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: Add TSPLIB dump capabilities to block layout #111005

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

amanasifkhalid
Copy link
Member

@amanasifkhalid amanasifkhalid commented Dec 30, 2024

Adds functionality for dumping the flowgraph to files that can be consumed by TSPLIB-based optimizers. This enables us to compare the JIT's 3-opt implementation to state-of-the-art optimizers.

TSPLIB consumes a parameter file specifying various options for the solver to leverage, as well as a problem file describing the flowgraph. The JIT communicates the flowgraph to TSPLIB via a full matrix of "distances" between blocks, which is computed with Compiler::ThreeOptLayout::GetCost(). Unfortunately, TSPLIB only accepts integral values for distances, so the layout costs are truncated -- this imprecision sometimes leads the external optimizer to different optima that aren't truly better than the JIT's answer.

TSPLIB gives each block a 1-indexed ordinal based on the order in which their distances are reported in the problem file. From the JIT side, I decided to use the lexical order of the optimized layout for this. This way, if we tell the optimizer to report its best traversal (via the JitOutputTSPTourFile switch), comparing it to the JIT's layout is simple: linearly-increasing traversals (1 2 3 etc) show agreement between the two.

This functionality is best used with SPMI: Just set JitDumpFlowGraphToTSPFile=1 when compiling a method, and then pass the resultant parameter file <spmi index>.par to the external optimizer.

I've used this functionality to analyze 3-opt's efficacy on benchmarks.run_pgo; I'll report my findings in a separate issue. I'll wait for #110922 to go in first before opening this up for review.

@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 Dec 30, 2024
Copy link
Contributor

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

@amanasifkhalid amanasifkhalid marked this pull request as ready for review January 6, 2025 19:39
return;
}

if (numCandidateBlocks > 150)
Copy link
Member Author

Choose a reason for hiding this comment

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

This proved to be a reasonable upper bound when running benchmarks.run_pgo: Very few methods had more blocks than 150, and the jump up was dramatic. I suppose we can adjust this locally as needed for other analyses.

@amanasifkhalid
Copy link
Member Author

cc @dotnet/jit-contrib, @AndyAyersMS PTAL. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

1 participant