Skip to content

feat(wgmma): pipeline two accumulator groups across counted K-loops - #935

Merged
nihalpasham merged 3 commits into
NVIDIA:mainfrom
uurl:feat/wgmma-pipelined-counted-k-loop
Aug 17, 2026
Merged

nihalpasham merged 3 commits into
NVIDIA:mainfrom
uurl:feat/wgmma-pipelined-counted-k-loop

Conversation

@uurl

@uurl uurl commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #934

Summary

Add production lowering for a conservative two-slot BF16 WGMMA pipeline inside canonical counted K-loops.

The new path combines the existing register-resident counted-loop model with the existing partial-wait pipeline model while keeping the complete asynchronous WGMMA lifetime inside one convergent inline-PTX scope.

What changed

Add an internal value-form counted-pipeline carrier with:

64 x f32 accumulator inputs
9 x u64 loop/control inputs
64 x f32 accumulator results

The nine control operands are:

desc_a0_base
desc_b0_base
desc_a1_base
desc_b1_base

desc_a0_step
desc_b0_step
desc_a1_step
desc_b1_step

trip_count

The lowering emits the following static pipeline inside the counted PTX loop:

mma slot0
commit_group
wait_group<1>

mma slot1
commit_group
wait_group<1>

advance four descriptors
decrement trip counter
branch

A final wait_group<0> drains the remaining asynchronous work before either accumulator becomes visible to LLVM.

Recognition

The deferred-accumulator fusion pass recognizes this shape before falling back to the existing single-accumulator counted-loop matcher.

The accepted form is intentionally narrow:

  • one canonical counted loop;
  • one latch;
  • one exit;
  • compile-time positive trip count;
  • two distinct canonical [[f32; 8]; 4] accumulators;
  • exactly two pointer-form BF16 WGMMA operations in the latch;
  • one commit and wait_group<1> after each MMA;
  • four distinct u64 descriptor block arguments;
  • affine descriptor recurrences;
  • final wait_group<0> in the exit;
  • no loop values escaping the fused region.

Validation

Validated with CUDA 13.3 ptxas targeting sm_90a.

The new end-to-end test starts from pointer-form MIR and exercises the complete production path:

pointer-form MIR
    -> counted-pipeline recognition
    -> 64-value internal carrier
    -> convergent inline PTX
    -> LLVM NVPTX
    -> ptxas sm_90a

ptxas reports:

Function properties for wgmma_pipelined_counted_loop_kernel
    0 bytes stack frame
    0 bytes spill stores
    0 bytes spill loads
Used 90 registers, used 0 barriers

For comparison:

single-slot counted K-loop       58 registers, 0 spills
two-slot straight-line pipeline  90 registers, 0 spills
two-slot counted pipeline        90 registers, 0 spills

The combined counted pipeline therefore retains the same reported register count as the existing two-slot straight-line pipeline.

The affected test suites also pass:

dialect-nvvm        50 passed
mir-lower unit     220 passed
mir-lower tests    106 passed
cuda-oxide-codegen all tests passed

Formatting and whitespace validation also pass:

cargo fmt --all
cargo fmt --all -- --check
git diff --check

Scope

This PR intentionally supports only:

2 accumulator slots
wait_group<1>
canonical counted K-loop
BF16 m64n64k16 -> f32 accumulator

It does not generalize counted-loop scheduling to arbitrary wait depths, accumulator counts, CFG shapes, dynamic waits, or additional WGMMA data types.

Fixes #932

@nihalpasham nihalpasham added enhancement New feature or request codegen Device code-generation pipeline (Rust MIR to IR to PTX) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) intrinsics Device intrinsics and libdevice math mappings cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) labels Aug 17, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Gist: the two-slot counted-K-loop lowering from #934: the recognizer picks up the canonical pointer-form MIR loop and fuses the whole pipeline (both accumulator groups, descriptor recurrences, partial waits) into one convergent inline-PTX scope.

What I verified and did:

  • dialect-nvvm, mir-lower, and cuda-oxide-codegen suites green, including the new pointer-form probe: 0 spills at sm_90a via ptxas
  • pushed 417598e: clippy fix (iterate the mma ops by reference)
  • rebased onto main and pushed a59d5b9: main's pliron bump changed StructType::get_unnamed to take an explicit StructLayout and inline_asm_convergent grew a current_op parameter, so the counted-pipeline lowering now uses both new signatures. The earlier unit-test failures were the CI merge build hitting exactly this
  • wgmma smoketest passes (PTX compiled; no sm_90a hardware on my box)
  • CI fully green

The body says "Fixes #934" only, but together with #933 this satisfies every acceptance bullet of #932 too, so I'll close #932 at merge as well.

@nihalpasham
nihalpasham merged commit a136782 into NVIDIA:main Aug 17, 2026
44 checks passed
nihalpasham pushed a commit that referenced this pull request Aug 18, 2026
…alidates (#969)

The obligation #964's merge comment attached to #946 landing. #946 has landed
(d485edb), and it was not the only batch member to move these numbers.

The page carries a self-invalidating stamp: "If the header stamp no longer
starts with `df42ef97`, the counts on this page predate the catalog you are
reading." Every `ops/generated/` header now prints `20440c06...`, so it does.

Recomputed from the tree at d485edb, with each delta attributed by
`git ls-tree` + `git show` per module rather than from a PR diff:

  generated/integer_minmax.rs   0 -> 8    new module (#967, DPX min/max)
  generated/packed_alu.rs      22 -> 30   f32x2 arithmetic (#946)
  ops/wgmma.rs                  6 -> 7    counted-K pipeline op (#935)

which moves five figures and adds a row:

  stamp                    df42ef97 -> 20440c06
  total                    543 across 41 modules -> 560 across 42
  hand-written             18 ops -> 19 (`wgmma` 6 -> 7)
  generated                34 modules / 525 ops / 986 catalog entries
                        -> 35 modules / 541 ops / 1002 catalog entries
  Packed (SIMD-in-reg)     43 -> 51
  Integer min/max (DPX)    new row, 8 -- `integer_minmax`

`integer_minmax` gets its own row rather than joining Scalar math beside
`extended_minmax`: six of its eight ops are `16x2` packed forms
(`max_s16x2`, `min_relu_s16x2`, ...) and two are scalar `s32`, so it is a
feature area rather than a scalar-math addition.

Checked and unchanged in the same pass: dialect-mir is still 62 ops across 12
modules with 9 types, and the `pliron` pin is still 8447aa42, so the LLVM
dialect's 69 stands.

**A correction to my own #964 while I am here.** That PR asserted #946 added
no ops, on the strength of `gh pr diff 946 | grep -c pliron_op` returning 0.
As the merge comment noted, `gh pr diff` returns empty on a diff that large,
so the grep was counting nothing rather than finding nothing -- an
unfalsifiable check that reads as a clean result. Every count in this commit
is derived from git objects in the tree instead.

Separately, the chapter's opening said cuda-oxide "works across three pliron
dialects ... two defined locally". Two more local pliron dialects exist and
the book never mentions either: `dialect-iket` (7 ops, 2 types) and
`dialect-ptx` (#917). The claim is now scoped to the lowering path, which is
what this chapter actually covers, with a pointer to the two crates' READMEs.
The same count appears in `pliron.md` and `architecture-overview.md`; those
are a separate change, and this one does not touch either file.

Verified: every figure on the page recomputed by script against the tree;
`just book` (`sphinx-build -W --keep-going`) succeeds; check-book-api-names
passes.

Signed-off-by: Vyncint Ng <[email protected]>
@uurl
uurl deleted the feat/wgmma-pipelined-counted-k-loop branch August 19, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen Device code-generation pipeline (Rust MIR to IR to PTX) cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings IR-lowering Lowering between dialects (dialect-mir to LLVM dialect)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support two-slot partial-wait WGMMA pipelines in counted K-loops Validate spill-free two-slot WGMMA counted pipeline lowering

2 participants