Skip to content

feat(wgmma): add register-resident F16 counted K-loop lowering - #1075

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

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

Conversation

@uurl

@uurl uurl commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1074

Summary

Extend the existing register-resident WGMMA counted K-loop lowering to m64n64k16.f32.f16.f16.

The new path reuses the same counted-loop control and accumulator model already used by BF16:

fence
counted K-loop:
    mma
    descriptor recurrence
commit_group
wait_group<0>

All 32 per-thread f32 accumulator values remain tied across one convergent
inline-PTX statement, so LLVM never observes an in-flight asynchronous WGMMA accumulator between loop iterations.

What changed

  • Add an F16 counted-loop value carrier:
    WgmmaMmaLoopValuesM64N64K16F32F16Op.
  • Extend the single-slot counted-loop recognizer to accept canonical F16 loops.
  • Generalize the counted-loop PTX template over the existing WGMMA input kind.
  • Add MIR-to-LLVM conversion for the F16 counted-loop carrier.
  • Add verifier and lowering coverage for the new carrier.
  • Extend the real llc / ptxas counted-loop probe to cover both BF16 and F16.
  • Update the public WGMMA documentation to describe F16 counted-loop support.

The existing counted-pipeline path remains BF16-only.

Scope

Supported F16 shape:

  • canonical [[f32; 8]; 4] accumulator;
  • one MMA per counted-loop iteration;
  • compile-time positive trip count;
  • affine u64 descriptor recurrences;
  • fence -> counted loop -> commit_group -> wait_group<0>.

Still unsupported:

  • F16 wait_group<N> for N > 0;
  • F16 multi-slot pipelines;
  • F16 counted pipelines;
  • non-canonical F16 accumulator fallback;
  • dynamic trip counts;
  • arbitrary loop CFGs;
  • TF32 WGMMA.

Validation

cargo fmt --all -- --check
cargo check -p dialect-nvvm -p mir-lower -p cuda-device -p cuda-oxide-codegen
cargo test -p dialect-nvvm --test ops_test
cargo test -p mir-lower --test lowering_test
cargo test -p cuda-oxide-codegen --test wgmma_counted_loop_ptx -- --nocapture
cargo clippy -p dialect-nvvm -p mir-lower -p cuda-device -p cuda-oxide-codegen --all-targets -- -D warnings

Results:

  • dialect-nvvm: 51 passed
  • mir-lower lowering_test: 117 passed
  • BF16 counted-loop ptxas: 58 registers, 0-byte stack, 0 spill stores, 0 spill loads
  • F16 counted-loop ptxas: 58 registers, 0-byte stack, 0 spill stores, 0 spill loads
  • clippy -D warnings: clean

The F16 lowering therefore matches the existing BF16 counted-loop register
footprint in the current probe while remaining spill-free on sm_90a.

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

Copy link
Copy Markdown
Collaborator
  • Verified end to end: mir-lower 253+117 and dialect-nvvm tests green, and both ptxas-backed probes reproduce the reported numbers: the BF16 and F16 counted-loop lanes compile spill-free for sm_90a (0 stack bytes, 0 spill loads/stores). wgmma compile-only lane 2/2, clippy clean.
  • The whitelist-widening hazard is handled: the guard in pipelined_counted_loop_operation_is_supported keeps F16 out of the pipeline matcher whose event identification is BF16-typed, so an F16 event cannot be silently dropped.
  • sm_90a execution with real descriptors remains the known category gap shared with the landed BF16 paths; ptxas acceptance plus the zero-spill assertions are the agreed bar here.

@nihalpasham
nihalpasham merged commit e1061bf into NVIDIA:main Aug 20, 2026
49 checks passed
nihalpasham added a commit to uurl/cuda-rust that referenced this pull request Aug 20, 2026
Unifies the counted-loop whitelist with the generalized MMA-kind arm
landed in NVIDIA#1075 while keeping the kind-only pointer-retype skip.
nihalpasham pushed a commit that referenced this pull request Aug 21, 2026
…1106)

Closes #1090.

`mlir-dialects.md` states its own freshness rule:

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

Nothing enforced that rule, so the rule that would expose stale counts was
itself unchecked. The page failed its own test for weeks before #1052 (560
printed against 570 in the tree), and **it is failing again right now**: the
catalog hashes to `00372dfe`, five hand-written ops and five catalog entries
after that refresh landed. Two hand audits in two batches is the pattern this
closes.

## The gate

One file hashed, one page grepped, no cargo and no network. The hash is the one
`cuda-intrinsics-gen` stamps into every generated file --
`sha256_bytes(catalog_json.as_bytes())` over the file as committed -- so a
plain `sha256sum` reproduces it, and the page prints its first eight digits.

Three checks rather than one, so each failure says which thing moved:

- The generated sources must stamp the hash `catalog.json` actually has.
  Failing here means the generated outputs are stale, and the message says to
  run `cuda-intrinsics-gen -- generate` -- not to edit the book.
- The page must print exactly one distinct stamp. It names it twice, once
  stating it and once in the rule that tells a reader what a mismatch means, so
  updating one and not the other leaves the rule contradicting the statement
  above it.
- The stamps must agree, and the failure prints both sides plus the two
  commands that re-derive the counts the stamp guards.

It refuses to report success from a check that found nothing: a page reworded
so no stamp is left fails with that stated, rather than passing vacuously. That
path needed the `|| true` on the capture rather than on a later pipeline --
under `pipefail` a grep matching nothing aborted the script before the
diagnostic, turning a reworded page into a silent non-zero exit.

## The refresh that makes it pass

Five numbers and the stamp, all re-derived from the tree:

| claim | was | now |
|---|--:|--:|
| catalog stamp (x2) | `26a9cc13` | `00372dfe` |
| total operations | 570 | 575 |
| hand-written operations | 21 | 26 |
| hand-written `wgmma` row | 9 | 14 |
| catalog entries | 1010 | 1015 |

Generated stays 549 across 35 modules and every area row is unchanged, because
#1085's five new catalog entries are aliases onto existing structural ops --
exactly what the page's "several intrinsics can share one structural op"
sentence predicts. The +5 hand-written are all `wgmma`, from #1075, #1077 and
#1079.

The `wgmma` row's description moves with its count, as in #1052: it said "the
m64n64k16 bf16/f16 shapes", and the module now holds four shape/type pairs --
`m64n64k16` bf16 and f16, `m64n128k16` bf16 (#1079), `m64n64k8` tf32 (#1077).

## Verification

- Four mutations, each failing with its own message: a stale stamp, only one of
  the two stamps updated, the page reworded so none is found, and an edited
  `catalog.json`. The healthy tree passes.
- Every count re-checked against the tree: 26 + 549 = 575, both tables sum to
  their stated totals (7 rows to 26, 11 rows to 549), and each still lists
  every module on disk.
- All eleven guard scripts pass, `check-spdx-headers.sh` accepts the new file,
  `cuda-intrinsics-gen -- check` reports outputs current, the workflow parses
  with all nine jobs on `ubuntu-latest`, and the book builds clean under
  `sphinx-build -W`.

`just check-guards` should list this script too, one line beside the other ten.
Its recipe is being restructured in #1102, so that line is left for a follow-up
rather than conflicting; no guard enforces that list, so CI is unaffected
either way.

Signed-off-by: Vyncint Ng <[email protected]>
@uurl
uurl deleted the feat/wgmma-f16-counted-k-loop branch August 22, 2026 06:09
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 register-resident F16 WGMMA counted K-loop lowering

2 participants