Skip to content

feat(wgmma): add TF32 m64n64k8 value-threaded full-drain lowering - #1077

Merged
nihalpasham merged 2 commits into
NVIDIA:mainfrom
uurl:feat/wgmma-tf32-k8-value-threaded-full-drain
Aug 20, 2026
Merged

nihalpasham merged 2 commits into
NVIDIA:mainfrom
uurl:feat/wgmma-tf32-k8-value-threaded-full-drain

Conversation

@uurl

@uurl uurl commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Closes #1076

Summary

Adds value-threaded lowering for Hopper TF32 WGMMA

wgmma.mma_async.sync.aligned.m64n64k8.f32.tf32.tf32

in the canonical linear full-drain case.

TF32 now follows the existing register-resident strategy for:

wgmma.fence
mma+
commit_group
wait_group<0>

The 32 f32 accumulator values remain tied through one convergent inline-PTX region, preventing LLVM from introducing a spill boundary while the
asynchronous WGMMA group is in flight.

TF32 differs from the existing BF16/F16 forms in two relevant ways:

  • the hardware shape uses K=8;
  • the PTX instruction has no transpose immediates.

The lowering therefore models TF32 as a distinct instruction form instead of
only changing the input-type suffix.

What changed

Device API / importer

Adds:

wgmma_mma_m64n64k8_f32_tf32

for the canonical [[f32; 8]; 4] accumulator.

The importer now emits a dedicated TF32 m64n64k8 pointer-form NVVM operation.

The existing legacy compatibility entry

wgmma_mma_m64n64k16_f32_tf32

remains explicitly unsupported and is not repurposed.

NVVM dialect

Adds:

  • WgmmaMmaM64N64K8F32Tf32Op
  • WgmmaMmaGroupValuesM64N64K8F32Tf32Op

The TF32 value carrier uses the same 32 × f32 accumulator interface as the
existing BF16/F16 m64n64 carriers.

No TF32 counted-loop or pipeline carrier ops are added.

MIR lowering

Extends canonical linear full-drain recognition to TF32.

A region of the form

wgmma.fence
tf32 mma+
wgmma.commit_group
wgmma.wait_group<0>

is rewritten from the pointer-form intrinsic to the 32-value SSA carrier.

The generated PTX is:

wgmma.mma_async.sync.aligned.m64n64k8.f32.tf32.tf32

with:

accumulators, desc_a, desc_b, 1, 1, 1

and no F16/BF16 transpose operands.

Linear regions remain homogeneous. Mixing TF32 with BF16 or F16 is rejected.

TF32 has no deferred pointer fallback.

Existing counted-loop and partial-wait recognizers remain BF16-only.

Tests

Adds coverage for:

  • TF32 NVVM pointer-form verification
  • TF32 NVVM value-carrier verification
  • direct TF32 value-carrier lowering
  • TF32 pointer-form canonical full-drain fusion
  • non-canonical TF32 accumulator rejection
  • mixed BF16/TF32 rejection
  • mixed F16/TF32 rejection
  • TF32 partial-wait rejection
  • TF32 counted-loop rejection
  • importer support for the new m64n64k8 API
  • continued rejection of the legacy m64n64k16 TF32 entry
  • end-to-end TF32 PTX generation for one MMA
  • end-to-end TF32 PTX generation for two chained MMAs

Validation

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

NVVM dialect tests:

51 passed; 0 failed

Importer WGMMA path test:

1 passed; 0 failed

WGMMA lowering tests:

36 passed; 0 failed

End-to-end WGMMA value-carrier PTX tests:

running 6 tests

bf16_wgmma_uses_thirty_two_tied_f32_values_without_spills ... ok
bf16_wgmma_chains_two_mma_async_under_one_commit_without_spills ... ok
f16_wgmma_uses_thirty_two_tied_f32_values_without_spills ... ok
f16_wgmma_chains_two_mma_async_under_one_commit_without_spills ... ok
tf32_wgmma_uses_thirty_two_tied_f32_values_without_spills ... ok
tf32_wgmma_chains_two_mma_async_under_one_commit_without_spills ... ok

test result: ok. 6 passed; 0 failed

All six ptxas -arch=sm_90a probes report:

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

The TF32 m64n64k8.f32.tf32.tf32 mnemonic is accepted directly by ptxas.

Book validation:

python3 -m sphinx -W --keep-going -b html \
  cuda-oxide-book \
  cuda-oxide-book/_build/html
build succeeded.

Scope

This PR deliberately does not add:

  • TF32 counted K-loop lowering
  • TF32 partial-wait pipelines
  • TF32 counted pipelines
  • non-canonical TF32 pointer fallback
  • wider TF32 WGMMA shapes
  • compatibility lowering for the legacy m64n64k16_f32_tf32 API

Those remain fail-closed and can be addressed independently.

@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+124 and dialect-nvvm tests green, all six value-carrier ptxas probes pass including the two new TF32 lanes (32 tied f32 values, 0 spills, sm_90a). wgmma compile-only lane 2/2, clippy clean, book builds under -W.
  • The K=8 template split is correct per the PTX ISA: tf32 dense wgmma takes scale controls only (no transpose immediates), and keeping the legacy K=16 TF32 compatibility entry point rejected with a pointed diagnostic is right since Hopper's TF32 hardware shape is K=8.
  • Same Hopper-execution caveat as the F16 lane, consistent with how that landed.

@nihalpasham
nihalpasham merged commit 54f2e74 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-tf32-k8-value-threaded-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 TF32 m64n64k8 full-drain WGMMA lowering

2 participants