Skip to content

feat(wgmma): add m64n128 BF16 full-drain lowering - #1079

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
uurl:feat/wgmma-m64n128-bf16-full-drain
Aug 20, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
uurl:feat/wgmma-m64n128-bf16-full-drain

Conversation

@uurl

@uurl uurl commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1078
Part of #338

Summary

Adds value-threaded lowering for:

wgmma.mma_async.sync.aligned.m64n128k16.f32.bf16.bf16

for canonical linear full-drain regions.

The new path carries a canonical [[f32; 8]; 8] accumulator as 64 tied SSA f32 values through one convergent inline-PTX scope.

What changed

  • Added the public wgmma_mma_m64n128k16_f32_bf16 API.
  • Added Acc64x128 = [[f32; 8]; 8].
  • Added pointer-form and 64-result value-form NVVM WGMMA ops.
  • Added MIR importer dispatch for the new intrinsic.
  • Generalized value-form WGMMA lowering from a fixed 32-value carrier to shape-specific 32/64-value carriers.
  • Added m64n128 BF16 recognition to deferred-accumulator fusion.
  • Added canonical [[f32; 8]; 8] full-drain lowering.
  • Recomputed accumulator element addresses after the fused m64n128 inline-PTX scope rather than keeping all addresses live across it.
  • Added verifier, lowering, codegen, integration, example, and documentation coverage.

Supported shape

wgmma.fence
one or more homogeneous m64n128k16.f32.bf16.bf16 MMAs
wgmma.commit_group
wgmma.wait_group<0>

The accumulator is:

[[f32; 8]; 8]

and is represented by 64 tied f32 values inside the fused asm region.

Intentionally unsupported

This PR does not add:

  • m64n128 F16;
  • m64n256;
  • TF32 support;
  • counted m64n128 loops;
  • m64n128 partial waits or pipelines;
  • pointer fallback for non-canonical m64n128 accumulators;
  • mixed m64n64/m64n128 full-drain regions.

Those cases remain fail-closed.

Backend validation

The dedicated sm_90a carrier tests compile real m64n128 WGMMA PTX through ptxas.

For both one MMA and two chained MMAs under one commit:

0 bytes stack frame
0 bytes spill stores
0 bytes spill loads
Used 90 registers

The existing m64n64 BF16/F16 carriers remain spill-free at 58 registers.

Validation

Passed locally:

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

cargo check \
  -p cuda-device \
  -p dialect-nvvm \
  -p mir-importer \
  -p mir-lower \
  -p cuda-oxide-codegen

cargo clippy \
  -p cuda-device \
  -p dialect-nvvm \
  -p mir-importer \
  -p mir-lower \
  -p cuda-oxide-codegen \
  --all-targets -- -D warnings

Test results include:

dialect-nvvm: 51 passed
mir-importer: 1101 passed
mir-lower unit tests: 253 passed
mir-lower integration tests: 120 passed
WGMMA PTX carrier tests: 6 passed

Also validated:

cargo oxide build wgmma_mma_bf16 --arch sm_90a
scripts/smoketest.sh -x -v '^wgmma_mma_bf16$'
sphinx-build -W --keep-going -b html \
  cuda-oxide-book cuda-oxide-book/_build/html

The compile-only WGMMA smoketest passes, and the Sphinx documentation build succeeds with warnings treated as errors.

@uurl
uurl force-pushed the feat/wgmma-m64n128-bf16-full-drain branch from 8d8b39d to 6928beb Compare August 20, 2026 10:41
@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

@nihalpasham
nihalpasham merged commit 6c5458f into NVIDIA:main Aug 20, 2026
50 checks passed
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-m64n128-bf16-full-drain 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.

Add value-threaded BF16 m64n128 full-drain WGMMA lowering

2 participants