Generalize JIT call fusion using SSA dependencies#2625
Draft
yanzin00 wants to merge 10 commits into
Draft
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2625 +/- ##
=======================================
Coverage 31.73% 31.73%
=======================================
Files 227 227
Lines 44908 44908
=======================================
Hits 14253 14253
Misses 30655 30655 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a generic
fuse-jit-callspass that combines directly SSA-connectedenzymexla.jit_calloperations into a single LLVM wrapper and replaces the original calls with one fused JIT call.For each JIT call, the pass examines its operands to find producer JIT calls and its results to find consumer JIT calls. This discovers the connected SSA dependency graph, including chains and DAGs containing more than two calls.
Operands defined outside the discovered group become arguments of the fused call. Results used only by another JIT call in the group become internal dependencies and are mapped directly between the cloned wrappers.Results that still have users outside the group remain outputs of the fused call.
Before modifying the IR, the pass validates that fusion is safe and supported. Currently, all calls must be in the same block, operands must dominate the fused call, and fusion must not move calls across unrelated side effects. The referenced LLVM wrappers must use the supported single-block, pointer-only, non-vararg, void-returning ABI. Calls with unsupported backend, layout, argument, or result metadata are not fused. Each JIT result must currently have a supported flat
output_operand_alias.Test
The pass is tested in:
test/lit_tests/mpi/fuse_jit_calls.mlirThe test first runs
lower-enzymexla-mpito lower the MPI operations intoenzymexla.jit_calloperations and LLVM wrapper functions. It then runsfuse-jit-callsand verifies that the dependentMPI_IrecvandMPI_WaitJIT calls are replaced by one fused JIT call.IR before
fuse-jit-callsBefore fusion,
MPI_IrecvandMPI_Waitare represented by separate JIT calls. The request result%1#1fromMPI_Irecvis passed directly toMPI_Wait, while the receive buffer%1#0remains externally used bystablehlo.transpose.IR
after fuse-jit-callsAfter fusion, both wrapper bodies are cloned into one fused LLVM wrapper, and the two original JIT calls are replaced by a single fused JIT call. The
MPI requestbecomes an internal pointer shared betweenMPI_IrecvandMPI_Wait, so it is removed from the JIT results. The receive buffer remains externally visible, and its alias to operand 0 is preserved.