Skip to content

Add mma.sync.aligned.m16n8k16 f16 tensor core intrinsic - #327

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

nihalpasham merged 3 commits into
NVIDIA:mainfrom
honeyspoon:add-mma-f16-v2

Conversation

@honeyspoon

@honeyspoon honeyspoon commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

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

mma.sync.aligned.m16n8k16.row.col.f32.f16.f16.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_m16n8k16_f32_f16.
  • 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, packed F16 order, and warp participation contract.
  • Made the shared MMA fragment diagnostic operation-neutral.
  • Added positive and negative operation-verifier tests.
  • Added a checked-in device-stub -> MIR importer -> lowering -> PTX regression.

Safety and register contract

each lane: C[f32 x4] + A[b32 x4] * B[b32 x2]
                         |
                         v
                     D[f32 x4]

All 32 lanes must execute the same instruction with the same qualifiers, with no lane exited. A and B are raw .b32 carriers containing two F16 values each in low-to-high order. Passing another lane layout computes a different matrix operation. The instruction requires PTX ISA 7.0 and sm_80 or newer.

Testing

  • cargo test -p cuda-device --lib
  • cargo test -p dialect-nvvm --all-targets (17 passed)
  • cargo test -p mir-importer --lib (66 passed)
  • cargo test -p mir-lower --all-targets (85 unit + 40 integration passed)
  • Focused strict clippy, formatting, and diff checks
  • cargo oxide run standalone_device_fn --arch sm_80 (10/10)
  • Generated exact PTX 7.0 / sm_80; CUDA 13.3 ptxas accepted it
  • Explicit sm_75 compilation rejected the 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 commit is signed off
  • No crates/cuda-bindings/ changes
  • Public unsafe contract and compiler regression coverage included

Adds the FP16 variant of the Ampere mma.sync instruction, following the
same register-only 4-layer pattern established by the BF16 (NVIDIA#321) and
F64 (NVIDIA#323) MMA variants:

  cuda-device stub  → dialect-nvvm op → mir-importer emit → mir-lower convert

The F16 variant has identical register geometry to BF16 (4 f32 C/D, 4 i32
packed A, 2 i32 packed B = 10 operands, 4 results) and uses the same
inline-asm constraints (=f,=f,=f,=f,f,f,f,f,r,r,r,r,r,r).

Pipeline detection, lowering tests, and near-miss rejection tests are
included.
@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.

I pushed a few minor updates

  • with the exact unsafe lane contract, operation-neutral diagnostics, verifier negatives, and checked-in cuda-device-to-PTX coverage.

Reviewer note: This partially addresses #274.

@nihalpasham
nihalpasham merged commit a51b7eb into NVIDIA:main Jul 3, 2026
28 checks passed
@honeyspoon
honeyspoon deleted the add-mma-f16-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