Repository navigation
feat(wgmma): add deferred BF16 accumulator lowering - #598
Conversation
Signed-off-by: Raul Estrada <[email protected]>
A fence-to-wait sequence that crosses a branch, join, or loop back-edge is rejected; a complete sequence inside a loop body fuses and pays the accumulator memory round-trip plus a full wait every iteration. The device-crate, pass, example, and book wording all said loops were rejected outright.
Root cargo fmt does not cover the standalone example crates, so the example's import order slipped through; and the operand-parity check in the wgmma group verifier trips clippy's manual_is_multiple_of under -D warnings.
|
LGTM, with one thing I want to be explicit about before merging. On the design: two ways to lower this exist. CUTLASS and Triton thread the accumulator through registers across separate The CUTLASS/Triton approach on the left is what makes WGMMA fast (multiple groups in flight, register-resident K-loops), but it has a real soundness hole for us at the LLVM layer: The fused block can't hit that by construction, and Rust MIR keeps an address-taken accumulator in memory anyway (no aggregate-SSA machinery yet). So: this sound bridge is okay for now but a pipelined, value-threaded path as a tracked follow-up would make sense. Two commits on top:
Verified:
Compile-verified only - I don't have Hopper hardware, so descriptor handling and end-to-end numerics on sm_90a remain unexecuted. Merging; closes #597. |
Closes #597
Summary
This PR adds initial lowering support for:
The implementation preserves the 32 per-thread
f32accumulator values across the asynchronous WGMMA fence/MMA/commit/wait sequence.Instead of lowering each pointer-form MMA independently,
mir-lowerrecognizes a complete supported sequence and replaces it with a deferred WGMMA group. The group is then lowered into one convergent inline-PTX scope, keeping the accumulator in registers untilwait_group<0>completes.Motivation
WGMMA accumulator values are asynchronous outputs.
A direct pointer-based lowering would need to load and store the accumulator around an individual MMA call, but the updated values are not valid until the committed group has completed. Storing them before
wgmma.wait_group.sync.aligned 0would therefore produce incorrect semantics.This PR models the complete asynchronous region explicitly and keeps unsupported sequences fail-closed.
What changed
Public API and importer
wgmma_mma_m64n64k16_f32_bf16.NVVM dialect
u64.Deferred-accumulator fusion
Adds a preprocessing pass that recognizes:
The pass supports a straight-line sequence across unconditional basic-block transitions and rejects ambiguous or incomplete regions.
It fails closed for:
u64wait-group constants;wait_group<0>.LLVM lowering
The deferred group lowers to one convergent inline-PTX scope that:
f32accumulator registers;wgmma.fence.sync.aligned;wgmma.commit_group.sync.aligned;wgmma.wait_group.sync.aligned 0;The original pointer-form operation remains illegal at final lowering unless it has been consumed by the fusion pass.
Tests and examples
Adds positive coverage for fusing and lowering a valid WGMMA sequence.
Adds negative coverage for:
Adds verifier coverage for immutable, non-generic and non-pointer accumulators.
Replaces the previous negative WGMMA MMA example with a compile-only BF16 example.
Adds the BF16 example to the standard WGMMA smoketest set.
Updates the WGMMA documentation and support status.
Current limitations
This PR intentionally supports only:
The following remain unsupported:
These cases continue to produce structured compiler errors.
Validation
The following commands pass:
Observed results:
dialect-nvvm: 50 tests passed.mir-lower: 146 unit tests and 88 integration tests passed.cuda-oxide-codegen: unit, compilation, concurrency, PTX and target-provenance suites passed.Hardware validation
The compile and smoketest validation was performed on a Blackwell GPU, where Hopper WGMMA instructions cannot execute.
The BF16 example therefore validates compilation and compiler lowering only. Functional execution still requires:
sm_90aGPU;