Skip to content

feat(wgmma): add value-threaded F16 full-drain lowering - #1025

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

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

Conversation

@uurl

@uurl uurl commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1024

Summary

Adds value-threaded lowering for Hopper

wgmma.mma_async.sync.aligned.m64n64k16.f32.f16.f16

in the canonical linear full-drain case.

F16 now follows the existing BF16 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.

What changed

Device API / importer

  • Enables importer handling for wgmma_mma_m64n64k16_f32_f16.
  • Keeps TF32 unsupported.
  • Documents the supported F16 lowering shape.

NVVM dialect

Adds:

  • WgmmaMmaM64N64K16F32F16Op
  • WgmmaMmaGroupValuesM64N64K16F32F16Op

The F16 value carrier has the same 32 × f32 accumulator interface as the existing BF16 carrier.

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

MIR lowering

  • Generalizes the linear value-group PTX template over BF16/F16 input kind.

  • Emits:

    wgmma.mma_async.sync.aligned.m64n64k16.f32.f16.f16
    

    for F16.

  • Recognizes canonical pointer-form F16 linear full-drain regions.

  • Converts them to the value-threaded carrier.

  • Requires homogeneous BF16 or F16 MMAs within a single linear full-drain region.

  • Rejects non-canonical F16 accumulators instead of using the BF16 deferred
    pointer fallback.

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

Tests

Adds coverage for:

  • direct F16 value-carrier lowering
  • F16 pointer-form full-drain fusion
  • non-canonical F16 rejection
  • mixed BF16/F16 rejection
  • F16 partial-wait rejection
  • F16 NVVM op verification
  • F16 importer support

The existing wgmma_value_carrier_ptx end-to-end test is also extended to F16.

Validation

Validated locally with CUDA 13.2 / ptxas targeting sm_90a.

cargo fmt --all -- --check
git diff --check
cargo check -p dialect-nvvm -p mir-importer -p mir-lower -p cuda-device
cargo clippy -p dialect-nvvm -p mir-importer -p mir-lower -p cuda-device \
  --all-targets -- -D warnings

WGMMA lowering tests:

25 passed; 0 failed

Book build with warnings treated as errors:

build succeeded

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

running 4 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

test result: ok. 4 passed; 0 failed

For all four PTXAS probes:

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

The F16 mnemonic is accepted directly by CUDA 13.2 ptxas for sm_90a.

Scope

This PR deliberately does not add:

  • F16 counted K-loop lowering
  • F16 partial-wait pipelines
  • F16 counted pipelines
  • non-canonical F16 pointer fallback
  • TF32 support

Those remain fail-closed and can be addressed independently.

@uurl
uurl force-pushed the feat/wgmma-f16-value-threaded-full-drain branch from 4a93e5f to d2140ce Compare August 18, 2026 12:18
@nihalpasham nihalpasham added enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) codegen Device code-generation pipeline (Rust MIR to IR to PTX) cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) labels Aug 19, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator
  • Reproduced all four ptxas probes locally: 58 registers, 0 stack bytes, 0 spill bytes for the f16 and bf16 chains, and the wgmma smoketest category compiles. Same fused-window approach the bf16 path already uses, now covering the f16 flavor.

# Conflicts:
#	crates/mir-lower/src/convert/intrinsics/wgmma.rs
@nihalpasham
nihalpasham merged commit f1e62fe into NVIDIA:main Aug 19, 2026
49 checks passed
@uurl
uurl deleted the feat/wgmma-f16-value-threaded-full-drain 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

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.

Add value-threaded F16 full-drain WGMMA lowering

2 participants