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

JIT: profile synthesis blend and repair modes #83567

Merged
merged 2 commits into from
Mar 17, 2023

Conversation

AndyAyersMS
Copy link
Member

Implement blend and repair modes for synthesis. Blend merges a bit of synthesized data into an existing PGO data set; repair tries to fix any local inconsistencies (via heuristics). Both run count construction afterwards.

Trust blended data like we trust dynamic data. Probably will want more nuance here (eg trust dynamic blend, but not static blend) but this is sufficent for now.

Also implement random and reverse modes; these will ultimately be used for stress testing (not called anywhere yet).

Parameterize some of the magic constants that have cropped up.

Add blend mode as a new weekend pgo stress mode; fix the other synthesis mode I added recently to pgo stress to set the config properly.

Contributes to #82964.

Implement blend and repair modes for synthesis. Blend merges a bit of
synthesized data into an existing PGO data set; repair tries to fix any
local inconsistencies (via heuristics). Both run count construction
afterwards.

Trust blended data like we trust dynamic data. Probably will want more
nuance here (eg trust dynamic blend, but not static blend) but this is
sufficent for now.

Also implement random and reverse modes; these will ultimately be used
for stress testing (not called anywhere yet).

Parameterize some of the magic constants that have cropped up.

Add blend mode as a new weekend pgo stress mode; fix the other synthesis
mode I added recently to pgo stress to set the config properly.

Contributes to dotnet#82964.
@ghost ghost assigned AndyAyersMS Mar 17, 2023
@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 Mar 17, 2023
@ghost
Copy link

ghost commented Mar 17, 2023

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

Issue Details

Implement blend and repair modes for synthesis. Blend merges a bit of synthesized data into an existing PGO data set; repair tries to fix any local inconsistencies (via heuristics). Both run count construction afterwards.

Trust blended data like we trust dynamic data. Probably will want more nuance here (eg trust dynamic blend, but not static blend) but this is sufficent for now.

Also implement random and reverse modes; these will ultimately be used for stress testing (not called anywhere yet).

Parameterize some of the magic constants that have cropped up.

Add blend mode as a new weekend pgo stress mode; fix the other synthesis mode I added recently to pgo stress to set the config properly.

Contributes to #82964.

Author: AndyAyersMS
Assignees: AndyAyersMS
Labels:

area-CodeGen-coreclr

Milestone: -

@AndyAyersMS
Copy link
Member Author

@jakobbotsch PTAL
cc @dotnet/jit-contrib

Example of blend mode in action:

;; original
-----------------------------------------------------------------------------------------------------------------------------------------
BBnum BBid ref try hnd preds           weight     IBC  lp [IL range]     [jump]      [EH region]         [flags]
-----------------------------------------------------------------------------------------------------------------------------------------
BB01 [0000]  1                           30532. 30532    [000..004)-> BB03 ( cond )                     IBC 
BB02 [0001]  1       BB01                  0        0    [004..006)        (return)                     rare IBC 
BB03 [0002]  1       BB01                30532. 30532    [006..009)-> BB05 ( cond )                     IBC 
BB04 [0003]  1       BB03                30532. 30532    [009..00C)-> BB06 ( cond )                     IBC 
BB05 [0004]  2       BB03,BB04             0        0    [00C..00E)        (return)                     rare IBC 
BB06 [0005]  1       BB04                30532. 30532    [00E..01C)-> BB08 ( cond )                     IBC 
BB07 [0006]  1       BB06                  0        0    [01C..01E)        (return)                     rare IBC 
BB08 [0007]  1       BB06                30532. 30532    [01E..036)        (return)                     IBC 
-----------------------------------------------------------------------------------------------------------------------------------------

;; blend
-----------------------------------------------------------------------------------------------------------------------------------------
BBnum BBid ref try hnd preds           weight     IBC  lp [IL range]     [jump]      [EH region]         [flags]
-----------------------------------------------------------------------------------------------------------------------------------------
BB01 [0000]  1                           30532. 30532    [000..004)-> BB03 ( cond )                     IBC 
BB02 [0001]  1       BB01                 61.06    61    [004..006)        (return)                     IBC 
BB03 [0002]  1       BB01                30471. 30471    [006..009)-> BB05 ( cond )                     IBC 
BB04 [0003]  1       BB03                30410. 30410    [009..00C)-> BB06 ( cond )                     IBC 
BB05 [0004]  2       BB03,BB04           121.76   122    [00C..00E)        (return)                     IBC 
BB06 [0005]  1       BB04                30349. 30349    [00E..01C)-> BB08 ( cond )                     IBC 
BB07 [0006]  1       BB06                157.82   158    [01C..01E)        (return)                     IBC 
BB08 [0007]  1       BB06                30191. 30191    [01E..036)        (return)                     IBC 
-----------------------------------------------------------------------------------------------------------------------------------------

@AndyAyersMS
Copy link
Member Author

Mono failure is known: #81123.
Wasm test timed out.

@AndyAyersMS
Copy link
Member Author

3 diffs in asp.net, because fgProfileWeightsEqual comparison changed from < to <=. Seems odd that such a tiny change could have a large impact. The relevant check is here:

// If the call site has profile data, report the relative frequency of the site.
//
if ((pInlineInfo != nullptr) && rootCompiler->fgHaveSufficientProfileWeights())
{
const weight_t callSiteWeight = pInlineInfo->iciBlock->bbWeight;
const weight_t entryWeight = rootCompiler->fgFirstBB->bbWeight;
profileFreq = fgProfileWeightsEqual(entryWeight, 0.0) ? 0.0 : callSiteWeight / entryWeight;
hasProfile = true;
assert(callSiteWeight >= 0);
assert(entryWeight >= 0);
}

We have

-----------------------------------------------------------------------------------------------------------------------------------------
BBnum BBid ref try hnd preds           weight   IBC  lp [IL range]     [jump]      [EH region]         [flags]
-----------------------------------------------------------------------------------------------------------------------------------------
BB01 [0041]  1                             0.01   0    [???..???)-> BB32 (always)                     i internal IBC 
BB02 [0004]  1       BB37                 15     15    [01E..067)-> BB36 ( cond )                     i idxlen bwd bwd-target IBC 

and so previously we'd determine that the entry weight was different than zero, and now we think it is not.

This is an OSR method and we currently don't have a good mechanism for determining the appropriate entry weight for such methods. We set the weight to 1% of the weight of the target block, guessing that the loop that inspired OSR must have executed at least 100 times.

Since there are just a handful of diffs I'll leave it as is.

@AndyAyersMS AndyAyersMS merged commit bbc5634 into dotnet:main Mar 17, 2023
@AndyAyersMS AndyAyersMS mentioned this pull request Mar 17, 2023
21 tasks
@ghost ghost locked as resolved and limited conversation to collaborators Apr 16, 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