Skip to content

Add mma.sync.aligned.m16n8k8 tf32 tensor core intrinsic - #328

Merged
nihalpasham merged 4 commits into
NVIDIA:mainfrom
honeyspoon:add-mma-tf32-v2
Jul 3, 2026
Merged

nihalpasham merged 4 commits into
NVIDIA:mainfrom
honeyspoon:add-mma-tf32-v2

Conversation

@honeyspoon

@honeyspoon honeyspoon commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the raw Ampere TF32 warp-level matrix multiply-accumulate operation:

mma.sync.aligned.m16n8k8.row.col.f32.tf32.tf32.f32
    {%d0, %d1, %d2, %d3},
    {%a0, %a1, %a2, %a3},
    {%b0, %b1},
    {%c0, %c1, %c2, %c3};

This is the low-level, unsafe register atom used to build typed matrix and tile APIs. It partially addresses tracking issue #274; it does not close the issue.

What changed

  • Added the cuda-device stub mma_m16n8k8_f32_tf32.
  • Added the dialect-nvvm operation, MIR importer handling, register-only convergent lowering, and PTX 7.0 / sm_80 target detection.
  • Documented the exact per-lane A/B/C/D coordinates, Rust-array-to-PTX register order, and warp participation contract.
  • Documented that A and B must already contain valid TF32 register values. Ordinary f32::to_bits() is not a TF32 conversion; use cvt.rna.tf32.f32 or an equivalent TF32-producing operation.
  • Made the shared MMA fragment diagnostic operation-neutral and added verifier boundary tests.
  • Added checked-in raw and f32-to-TF32 device paths through the complete compiler pipeline.
  • Integrated current main after Add mma.sync.aligned.m16n8k16 f16 tensor core intrinsic #327 while retaining the complete F16 and TF32 APIs, detectors, dispatch arms, lowerings, tests, and PTX checks.

Safety and TF32 contract

six lane-local f32 values
          |
          | cvt.rna.tf32.f32 x6
          v
 A[tf32 x4], B[tf32 x2] -> mma.sync -> D[f32 x4]

All 32 lanes must execute the same instruction with the same qualifiers, with no lane exited. A and B use raw .b32 TF32 register carriers in the documented lane layout. The instruction requires PTX ISA 7.0 and sm_80 or newer.

Testing

  • cargo test -p cuda-device --lib
  • cargo test -p dialect-nvvm -p mir-importer -p mir-lower (18 dialect verifier, 67 importer, 85 lowering unit, and 41 lowering integration tests passed)
  • Strict workspace and standalone-example clippy with warnings denied
  • Root, rustc-codegen-cuda, and complete per-example formatting checks
  • cargo oxide run standalone_device_fn --arch sm_80 (14/14)
  • Generated one exact F16 MMA, two exact TF32 MMAs, and six cvt.rna.tf32.f32 instructions
  • Generated PTX 7.0 / sm_80; CUDA 13.3 ptxas accepted it
  • Explicit sm_75 compilation rejected the TF32 operation with the required sm_80 floor
  • Full-warp numerical comparison on a GPU, including Compute Sanitizer

Checklist

  • Original contributor commit has the required DCO Signed-off-by trailer
  • Maintainer follow-up and merge commits are signed off
  • No crates/cuda-bindings/ changes in the PR delta
  • Public unsafe contract and compiler regression coverage included

Four-layer implementation (cuda-device stub, dialect-nvvm op, mir-importer
emit, mir-lower convert) of the Ampere TF32 warp MMA:

  mma.sync.aligned.m16n8k8.row.col.f32.tf32.tf32.f32

Register layout: 4 f32 C accumulators + 4 i32 packed A + 2 i32 packed B
→ 4 f32 D results. Uses convergent inline asm with register-only
constraints (=f/f/r).

Includes pipeline detection with near-miss rejection tests and a
lowering integration test.
@honeyspoon honeyspoon mentioned this pull request Jul 2, 2026
49 tasks done
@nihalpasham nihalpasham added enhancement New feature or request perf Performance of generated code or of the compiler itself intrinsics Device intrinsics and libdevice math mappings device-apis User-facing device-side and kernel-authoring APIs (cuda-device, cuda-macros) codegen Device code-generation pipeline (Rust MIR to IR to PTX) IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) cuda-feature A CUDA hardware/toolkit feature (TMA, tcgen05, WGMMA) tests Adds or improves test coverage labels Jul 3, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks for the PR

The raw TF32 MMA atom and register order are correct, and I added a follow-up that makes the TF32 producer rule and exact lane map explicit. The checked-in path emits six

  • cvt.rna.tf32.f32 conversions feeding the MMA, passes 12/12, and assembles for sm_80.

Reviewer note: A typed TF32 wrapper can be layered above this raw primitive. This partially addresses #274.

@nihalpasham
nihalpasham merged commit c51e31b into NVIDIA:main Jul 3, 2026
27 checks passed
@honeyspoon
honeyspoon deleted the add-mma-tf32-v2 branch July 23, 2026 13:53
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) device-apis User-facing device-side and kernel-authoring APIs (cuda-device, cuda-macros) enhancement New feature or request intrinsics Device intrinsics and libdevice math mappings IR-lowering Lowering between dialects (dialect-mir to LLVM dialect) perf Performance of generated code or of the compiler itself tests Adds or improves test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants