Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add repeatCount in superpmi.exe to repeat the compilation of 1 or more methods #93417

Closed
wants to merge 1 commit into from

Conversation

kunalspathak
Copy link
Member

@kunalspathak kunalspathak commented Oct 12, 2023

I wanted to investigate the TP of 1 particular method and why it takes longer to JIT. Using superpmi if I can compile it multiple times I can see the area that is slow. One option would be to specify the method context id in mcl file repeatedly, but we have a check that they should be incremental. So I added a -repeatCount flag that will compile a single context id or entire mch file specified number of times, which will help in gathering accurate profile information.

Edit: For now, I did not propagated to superpmi.py and can be done if people find this option useful.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 12, 2023
@ghost ghost assigned kunalspathak Oct 12, 2023
@ghost
Copy link

ghost commented Oct 12, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

I wanted to investigate the TP of 1 particular method and why it takes longer to JIT. Using superpmi if I can compile it multiple times I can see the area that is slow. One option would be to specify the method context id in mcl file repeatedly, but we have a check that they should be incremental. So I added a -repeatCount flag that will compile a single context id or entire mch file specified number of times, which will help in gathering accurate profile information.

Author: kunalspathak
Assignees: kunalspathak
Labels:

area-CodeGen-coreclr

Milestone: -

@kunalspathak
Copy link
Member Author

@dotnet/jit-contrib

Comment on lines +330 to +331
for (int iter = 0; iter < o.repeatCount; iter++)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we shouldn't need to change the MethodContextReader at all. Instead of the "repeatCount" loop here, couldn't it be just before the CompileResult* crl = mc->cr; line? (There might need to be some kind of saving/restoring of the originalCR).

Copy link
Member Author

@kunalspathak kunalspathak Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly, the problem with that though is that the display of percent completion report will be slower. E.g. if someone pass -repeatcount 10000 for entire mch, the time after which you would see the console output would be after 10000 * 500 compilations.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems wrong that the MethodContextReader should have any knowledge of the repeatCount.

How about have the repeatCount loop include the %complete logging, and displayed % complete would be repeatIteration * reader->PercentComplete() / repeatCount. For a repeatCount of 1, this would be no change.

Then, change it to output every 500 iterations whether that is due to loadedCount or repeatCount, e.g.,

if ((totalIterations++ % 500 == 0) && (loadedCount > 0))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about have the repeatCount loop include the %complete logging, and displayed % complete would be repeatIteration * reader->PercentComplete() / repeatCount. For a repeatCount of 1, this would be no change.

My math here is wrong. It would need to be:

100.0 * (((reader->CurrentCount() - 1) * repeatCount + repeatIteration) / (repeatCount * reader->TotalCount())

for newly exposed MethodContextReader curIndexPos (as CurrentCount()) and IndexCount (as TotalCount())

(this depends on curIndexPos returning 1 when you're processing the first method context. curIndexPos and IndexCount also depend on there being a .MCT file, which there isn't always, in which case we would have to return the pos/fileSize like PercentComplete does, which wouldn't be as accurate.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, just seeing your comment. One of the other problem of moving loop to iterate over jit->CompileMethod() is that it will be a tight loop without showing the % progress unless we add another LogVerbose inside it. So for eg, if I pass -c 59 -repeatCount 10000, i am expected to see % completion after every 500 iterations or so. Unless I am misunderstanding your suggestion of where to add the logging.

BruceForstall added a commit to BruceForstall/runtime that referenced this pull request Nov 8, 2023
Passing `-repeatCount N` for some integer `N > 0` will compile
each function `N` times. This is true for each function in the
MCH file, by default, or each one specified by a `-c` argument
or .mcl file.

This can be used to help investigate the JIT throughput for compilation
of a particular function or set of functions.

This is based on dotnet#93417.
@kunalspathak
Copy link
Member Author

Replaced by #94503

@kunalspathak kunalspathak deleted the repeatcount branch November 8, 2023 05:11
BruceForstall added a commit that referenced this pull request Nov 8, 2023
Passing `-repeatCount N` for some integer `N > 0` will compile
each function `N` times. This is true for each function in the
MCH file, by default, or each one specified by a `-c` argument
or .mcl file.

This can be used to help investigate the JIT throughput for compilation
of a particular function or set of functions.

This is based on #93417.
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants