Repository navigation
EnzymeHLOOpt: ScatterIndicesAreUnique reads a constant without copying - #3439
Merged
Merged
Conversation
The check that a scatter's constant indices are all distinct built every index tuple through a recursive copy of a SmallVector per element and a set of vectors, and ran again on every visit of a scatter whose indices are not distinct: on a splat index of 21M elements it took 56 s per module, most of ex1's run. A splat is distinct only as one point; others are read once into flat tuples and sorted. Co-Authored-By: Claude Fable 5.1 <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 #3439 +/- ##
==========================================
+ Coverage 29.63% 29.96% +0.33%
==========================================
Files 240 240
Lines 48496 48546 +50
==========================================
+ Hits 14371 14548 +177
+ Misses 34125 33998 -127 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
Author
|
MFEM GPU unit suite (74 tests) with the runtime built from Enzyme-JAX main + #3437 #3439 #3440 #3441 #3442 and Reactant.jl #3423 + #3425, over objects from main + the open affine-cfg PRs (#3436 #3438 among them): 74/74 (sweep final55, 2026-10-08 17:38). ex1 (Poisson, order 3, PA, PCG to 1e-12), timed solves in one process (JIT excluded), native CUDA for reference:
|
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.
ScatterIndicesAreUnique's constant-indices path built every index tuple through a recursive lambda copying aSmallVectorper element, then astd::setof vectors — and since a scatter whose indices are not distinct makes the pattern fail, the whole enumeration ran again on every visit of that scatter by the greedy driver. It also readshape[indexVectorDim]for scalar indices (index_vector_dim == rank), one past the end.On MFEM's ex1 (star mesh, order 3, PA) one exec-time module (
PADiffusionSetup's, six scatters with a splat index constant of20480x32x32x1) spent 56 s in it — the bulk of the 44 s run was this one optimization (perf: 50% of all samples in the pattern'sSmallVectorchurn); the module now takes 0.1 s through the runtime pattern list.Now: a splat is distinct iff there is one scatter point; otherwise the values are read once into a flat array, the tuples laid out point by point (the index-vector dimension handled whether real or implicit), and distinctness is a sort plus an adjacent compare.
Test
scatter_indices_unique_constant.mlir: distinct, repeated, two-component tuples along the leading dimension, scalar indices (full-line goldens). On a 200k-element random permutation the verdicts match the old code.🤖 Generated with Claude Code
https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD