Repository navigation
feat(wgmma): keep counted K-loop accumulators in SSA - #687
Merged
Merged
Conversation
Signed-off-by: Raul Estrada <[email protected]>
Signed-off-by: Raul Estrada <[email protected]>
Signed-off-by: Raul Estrada <[email protected]>
Signed-off-by: Raul Estrada <[email protected]>
This was referenced Aug 7, 2026
…d ptxas
The counted-loop fusion emits the first inline-PTX region in this
codebase with local labels, ${:uid} operand escapes, and bra.uni
branches, but nothing had pushed that template past the LLVM dialect.
Add a ptxas feasibility probe that builds the canonical pointer-form
K-loop (trip count 4, one MMA in the latch, affine descriptor
recurrences), lets the deferred accumulator fusion rewrite it, and
requires llc plus ptxas -arch=sm_90a to accept the result with zero
spill bytes while all 32 accumulator values stay live. The probe
asserts the uid-expanded loop labels and both branches so the deferred
pointer fallback cannot pass it vacuously.
Also clear the four clippy -D warnings failures in the new fusion pass
(two question-mark rewrites, one redundant into_iter, one house-style
too_many_arguments allow).
Collaborator
|
Gist: Step 4: for one narrow, provable loop shape, the whole K-loop now lives inside a single asm region, which is what keeps the 32 accumulators in registers across iterations. The recognizer being strict is a feature, not a limitation: anything it cannot prove falls back to the old path. I pushed one commit on top:
Merging after #686 (the rebase collapses the stack to this PR's own commit). |
…flict resolution The prior merge commit resolved interface_impls.rs and the wgmma files by taking the branch side of the whole file, which also discarded main's auto-merged additions in non-conflicted regions (notably the convert_construct_disjoint_slice registration). Re-resolved keeping the auto-merge and taking the branch side only inside the marker regions.
nihalpasham
approved these changes
Aug 8, 2026
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.
This PR is the fourth of six planned PRs for #605 and builds on the
linear SSA accumulator adapter introduced by #686.
Summary
Extend the value-threaded BF16 WGMMA path across a canonical counted K-loop.
For supported loops, the lowering now keeps all 32 per-thread
f32accumulator values in one convergent inline-PTX lifetime across every K
iteration, rather than materializing the accumulator through memory on each
iteration.
The resulting shape is conceptually:
Unsupported or non-canonical control-flow shapes continue through the existing
linear/deferred paths.
Motivation
#686 moved straight-line pointer-form WGMMA regions onto the 32-value SSA
carrier, eliminating accumulator memory materialization from inside the
convergent WGMMA asm scope.
A counted K-loop still presents a stronger lifetime requirement: if each loop
iteration becomes a separate LLVM inline-asm statement, LLVM regains visibility
between asynchronous WGMMA operations and may spill accumulator values while a
group is still in flight.
This PR closes that boundary for the canonical counted-loop case by placing the
entire asynchronous accumulator lifetime, including loop control and descriptor
recurrence, inside one convergent inline-PTX statement.
Implementation
Counted-loop recognition
The WGMMA accumulator preparation pass now uses the reusable
mir-transformsloop and induction analyses to recognize a restricted,provable counted-loop shape.
The optimization requires a canonical loop with:
wait_group<0>lifetime;[[f32; 8]; 4]accumulator layout.If those conditions cannot be proved, the pass leaves the loop untouched and
preserves the existing lowering behavior.
Loop analysis is also skipped for regions containing unreachable blocks. This
keeps malformed/negative-test MIR on the established diagnostic path instead of
querying dominance information that does not exist for unreachable CFG nodes.
Internal loop carrier
A new internal NVVM operation represents a counted BF16 WGMMA loop with:
The verifier closes the operation over the expected accumulator, descriptor,
delta, and trip-count types.
Lowering
The counted-loop operation lowers to one convergent, side-effecting LLVM
inline-asm statement.
The 32 accumulator inputs are tied to 32
=foutputs, as in the existingvalue-form carrier.
The PTX region:
remains entirely inside that single LLVM-visible asm boundary.
The 32 aggregate results are then recovered with
extractvalueand stored backto the canonical accumulator only after the final
wait_group<0>.Register-lifetime property
For a K-loop with
Niterations, accumulator memory traffic is now:rather than:
There is no accumulator
ld.f32,st.f32, or local.reg .f32materializationinside the counted-loop inline-PTX template.
Descriptor recurrence and loop control are also kept inside the same convergent
asm scope, so LLVM does not observe an intermediate accumulator lifetime between
iterations.
Fallback behavior
This remains a conservative optimization.
Loops that do not satisfy the canonical counted-loop contract are not partially
rewritten. Existing straight-line SSA adaptation and deferred pointer-form
fallback behavior remain available.
Existing malformed WGMMA control-flow cases also continue to produce their
previous diagnostics rather than being consumed by the new loop analysis.
Tests
Coverage includes:
wait_group<0>;ld.f32,st.f32, or.reg .f32materialization inside thecounted-loop template;
Validation
The existing backend carrier feasibility probe also remains green:
That probe validates the 32-value tied-register carrier independently; it is
not a direct
ptxasspill measurement of the new counted-loop production path.WGMMA smoketests also remain green:
git diff --checkis clean.Scope
This PR does not yet:
wait_group<N>values;Those remain for subsequent PRs in #605.