Skip to content

feat(wgmma): support three-slot counted pipelines - #1021

Merged
nihalpasham merged 1 commit into
NVIDIA:mainfrom
uurl:feat/wgmma-three-slot-counted-k-loop
Aug 19, 2026
Merged

nihalpasham merged 1 commit into
NVIDIA:mainfrom
uurl:feat/wgmma-three-slot-counted-k-loop

Conversation

@uurl

@uurl uurl commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1020

Summary

Extend the production BF16 WGMMA counted-loop pipeline from the existing two-slot wait_group<1> form to also support a three-slot wait_group<2> form.

The counted carrier, recognizer, and lowering now derive the accumulator-slot count from the partial-wait depth while deliberately restricting the production contract to:

2 slots + wait_group<1>
3 slots + wait_group<2>

The straight-line WGMMA pipeline continues to support its broader wait_group<N> range independently.

Implementation

The counted-loop carrier now models a variable number of accumulator slots and carries the corresponding partial-wait depth.

The production layout is derived from:

slot_count        = max_pending_groups + 1
accumulator_count = slot_count * 32
descriptor_count  = slot_count * 2
control_count     = slot_count * 4 + 1

This gives:

wait_group<1>:
  2 slots
  64 accumulator values
  9 control values

wait_group<2>:
  3 slots
  96 accumulator values
  13 control values

The counted inline-PTX template now emits one MMA -> commit_group -> wait_group<N> stage per slot, advances all descriptor recurrences inside the same counted loop, and performs a final wait_group<0> before any accumulator result becomes visible to LLVM.

Recognition

The counted-loop recognizer remains fail-closed.

It now requires:

  • one canonical accumulator pointer per slot
  • pairwise-distinct accumulator pointers
  • homogeneous partial-wait depths
  • exactly one MMA -> commit_group -> wait_group<N> stage per slot
  • N equal to either 1 or 2
  • two affine descriptor recurrences per slot
  • one final wait_group<0>

Malformed counted pipelines are rejected rather than partially fused.

Negative coverage includes:

  • mixed wait_group<1> / wait_group<2> stages
  • wait_group<2> with only two slots
  • reused accumulator slots

Validation

cargo test -p dialect-nvvm
cargo test -p mir-lower

cargo test -p cuda-oxide-codegen \
  --test wgmma_pipelined_counted_loop_ptx -- --nocapture

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

Results:

dialect-nvvm:
  50 passed

mir-lower unit tests:
  246 passed

mir-lower lowering tests:
  111 passed

counted-pipeline codegen:
  2 passed

ptxas results on sm_90a:

two-slot production path:
  0 bytes stack frame
  0 bytes spill stores
  0 bytes spill loads
  Used 90 registers

three-slot production path:
  0 bytes stack frame
  0 bytes spill stores
  0 bytes spill loads
  Used 122 registers

The three-slot production path therefore keeps all 96 tied accumulator values register-resident without introducing stack or spill traffic.

Scope

This PR modifies the counted WGMMA production path only.

It does not extend counted pipelines beyond wait_group<2> and does not change the existing broader straight-line WGMMA pipeline support.

@uurl
uurl force-pushed the feat/wgmma-three-slot-counted-k-loop branch from 7ddbb80 to 6c1e5f3 Compare August 18, 2026 11:33
@nihalpasham nihalpasham added enhancement New feature or request 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 19, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

@nihalpasham
nihalpasham merged commit 28b0ae0 into NVIDIA:main Aug 19, 2026
107 of 114 checks passed
@uurl
uurl deleted the feat/wgmma-three-slot-counted-k-loop branch August 19, 2026 21:37
nihalpasham pushed a commit that referenced this pull request Aug 20, 2026
…s own test (#1052)

`mlir-dialects.md` anchors its op counts to a catalog stamp and says how to
tell when they have rotted:

    At catalog SHA-256 `20440c06` (the stamp in every `ops/generated/` file
    header), the dialect holds 560 operations across 42 modules ...
    If the header stamp no longer starts with `20440c06`, the counts on this
    page predate the catalog you are reading.

Every generated file now stamps `26a9cc13`, so that condition is true. Six
numbers and one description are stale, all of them from the last batch of
merges:

| claim | page | tree |
|---|--:|--:|
| dialect total | 560 | **570** |
| hand-written ops | 19 | **21** |
| hand-written `wgmma` row | 7 | **9** |
| generated ops | 541 | **549** |
| catalog entries | 1002 | **1010** |
| generated "Warp-level" row | 31 | **39** |

The two deltas are traceable: #1021 and #1025 added two hand-written `wgmma`
ops (19 -> 21), and #1032 added the eight `redux.sync` f32 variants
(541 -> 549, 1002 -> 1010, and the Warp-level row that owns `redux`).

The `wgmma` row's description moved with its count rather than just the
number. It read "the m64n64k16 bf16 shapes", but #1025 added
`WgmmaMmaM64N64K16F32F16Op` and `WgmmaMmaGroupValuesM64N64K16F32F16Op`, so the
module now holds f16 shapes too.

Module counts did not change: 7 hand-written plus 35 generated is still 42.

Verified against the tree rather than against the merge descriptions:
`^pub struct \w+Op;` counts 21 under `src/ops/` and 549 under
`src/ops/generated/`, 570 together; `intrinsics/catalog.json` holds 1010
entries; and all 35 generated files carry the one stamp `26a9cc13`. Both
tables sum to their new totals (7 rows to 21, 11 rows to 549) and each still
lists every module on disk with nothing that is not one. Book builds clean
under `sphinx-build -W`.

Signed-off-by: Vyncint Ng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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 three-slot WGMMA counted pipelines with wait_group<2>

2 participants