Repository navigation
EnzymeHLOOpt: a gather of a broadcast along its batching dimensions reads the source - #3479
Merged
Merged
Conversation
…eads the source A gather of a broadcast along the dimensions it batches over reads, in every batch, the same tensor: it is a gather from that tensor without those batching dimensions (the start indices' batching dimensions become plain batch dimensions, so the result is the same). New pattern gather_of_broadcast_batching_dims, in the exec-time transform list. Batching a loop's gather from a buffer the loop does not change makes such a broadcast (greedy_while_loop_batch_fission broadcasts every operand defined outside the loop), and XLA materializes it: one copy of the buffer per iteration. MFEM's bench_assembly_levels BP5ELEMENT made tensor<39304x943296xf64> (296 GB) and tensor<39304x3x3x6367248xf64>, and ran out of memory compiling (68 GB of executable arguments). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3479 +/- ##
==========================================
- Coverage 29.92% 29.73% -0.19%
==========================================
Files 241 241
Lines 48628 48655 +27
==========================================
- Hits 14551 14468 -83
- Misses 34077 34187 +110 ☔ 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.
gather(broadcast_in_dim(x), idx)where every dimension the broadcast adds is an operand batching dimension of the gather reads the same tensor in every batch. It equals a gather fromxwith those batching dimensions dropped. The matching start-indices batching dimensions become plain batch dimensions, so the result type is unchanged. Batching dimensions that belong toxitself are kept.Conditions:
Otherwise, e.g. when an added dimension is indexed through
start_index_map, the gather stays.New pattern:
gather_of_broadcast_batching_dims, registered in the enzyme-hlo-opt set, the transform ops, and the exec-time pattern list inEnzymeXLA.cpp.Motivation: batching a loop's gather from a buffer the loop doesn't change creates such a broadcast.
greedy_while_loop_batch_fissionbroadcasts every operand defined outside the loop (DEFINED_OUTSIDE_WHILE), and XLA materializes it: one copy of the buffer per iteration. MFEM'sbench_assembly_levelsBP5ELEMENT madetensor<39304x943296xf64>(296 GB) andtensor<39304x3x3x6367248xf64>, and ran out of GPU memory compiling (68 GB of executable arguments). The minimal set of patterns that reproduces the broadcast isgreedy_while_loop_batch_fissionalone. With this pattern, the largest tensor in that module is 76 MB.Test: new
gather_of_broadcast_batching_dims.mlirwith full-line goldens:The first two match the original on JAX CPU exactly. Lit: 1503/1503 pass.
Merging with #3444 conflicts textually on the adjacent registration lines (TransformOps.td, the
EnzymeXLA.cpplist, the pattern set); keep both.🤖 Generated with Claude Code
https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD