Skip to content

Add mma.sync.aligned.m8n8k4 f64 double-precision tensor core intrinsic - #323

Merged
nihalpasham merged 5 commits into
NVIDIA:mainfrom
honeyspoon:add-mma-f64
Jul 2, 2026
Merged

nihalpasham merged 5 commits into
NVIDIA:mainfrom
honeyspoon:add-mma-f64

Conversation

@honeyspoon

@honeyspoon honeyspoon commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds the Ampere FP64 mma.sync.aligned.m8n8k4 tensor-core operation as an
unsafe, register-valued cuda-device intrinsic.

The operation consumes the calling lane's two C registers plus one A and one B
register, and returns two D registers. It generates no hidden pointer traffic
or fixed PTX temporary-register declarations.

Partially addresses #274. Related to #289; this PR does not close either issue.

What changed

Device API and safety

  • Adds mma_m8n8k4_f64([f64; 2], f64, f64) -> [f64; 2].
  • Documents the exact lane-to-matrix mapping and full-warp participation rules.
  • Documents round-to-nearest-even behavior and the PTX 7.0 / sm_80+
    requirements.

Compiler pipeline

  • Represents the operation as four scalar f64 SSA operands and two scalar f64
    SSA results.
  • Verifies the exact operand/result count and types.
  • Extracts and reconstructs the Rust accumulator array in the MIR importer.
  • Lowers to one convergent inline PTX instruction with direct f64 register
    constraints and no memory clobber.

Target selection and regressions

  • Detects the exact FP64 MMA spelling as PTX 7.0 / sm_80.
  • Rejects explicit lower targets before invalid PTX can be emitted.
  • Adds verifier, importer, lowering, target-detection, one-call, and repeated-
    call coverage.
  • Preserves the strongest architecture and PTX floor when FP64 MMA is combined
    with BF16 MMA and the packed atomics already on main.

Testing

  • cargo fmt --all -- --check
  • cargo check --workspace --all-targets
  • Focused dialect, importer, and lowering test suites (203 passed)
  • Strict workspace clippy with warnings denied
  • One-call and two-call Rust-to-PTX builds select PTX 7.0 / sm_80
  • CUDA 13.3 ptxas -arch=sm_80 accepts both kernels
  • SASS contains one/two DMMA.884 instructions with STACK:0 LOCAL:0
  • Explicit sm_75 is rejected before PTX generation
  • A post-Add packed atomic add intrinsics (f16x2, bf16x2) #322 all-four kernel selects PTX 7.8 / sm_90, emits both MMA
    forms and both packed atomics, and assembles with zero stack or spills
  • Numerical execution on a physical sm_80+ GPU

Checklist

  • Contributor authorship preserved
  • Every PR commit has DCO sign-off
  • Public API and safety documentation updated
  • No crates/cuda-bindings/ files changed

@honeyspoon
honeyspoon force-pushed the add-mma-f64 branch 2 times, most recently from 2502499 to 0c5ad3b Compare July 1, 2026 15:55
@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 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) device-apis User-facing device-side and kernel-authoring APIs (cuda-device, cuda-macros) tests Adds or improves test coverage labels Jul 2, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Thanks for the PR.

I layered a couple of things on top:

  • changed the intrinsic to return [f64; 2] from register-valued inputs.
  • tightened verification to four f64 SSA operands and two f64 results.
  • emitted one convergent, register-only PTX instruction with exact constraints.
  • documented lane ownership, .rn rounding, full-warp safety, and the sm_80 / PTX 7.0 minimum.
  • added exact target detection plus adversarial token-boundary and near-miss tests.

This partially addresses #274 by completing its FP64 m8n8k4 item; that umbrella tracker remains open. It does not close #289, whose broader target/PTX mapping work remains outstanding.

Reviewer note: The only remaining technical check is a real-GPU numerical test across all 32 lane fragments against a CPU reference.

honeyspoon and others added 5 commits July 2, 2026 14:45
- Replace no-op `impl Verify` with real validation (3 MirPtrType
  operands, 0 results) matching ldmatrix/stmatrix verifier patterns.
- Fix missing imports: emit_goto, llvm_types, inline_asm_convergent.
- Merge dialect_nvvm::ops import into single use statement.
- Add #[allow(clippy::too_many_arguments)] on emit_mma_m8n8k4_f64.
- Align safety docs with movmatrix style (divergent-flow UB, ISA floor).
- Strengthen lowering test to assert constraints, AsmKind::Convergent,
  operand count, and result count.

Signed-off-by: nihalp <[email protected]>
@nihalpasham
nihalpasham merged commit 7f46356 into NVIDIA:main Jul 2, 2026
28 checks passed
@honeyspoon honeyspoon mentioned this pull request Jul 2, 2026
49 tasks done
nihalpasham added a commit that referenced this pull request Jul 3, 2026
* Add mma.sync.aligned.m16n8k16 f16 tensor core intrinsic

Adds the FP16 variant of the Ampere mma.sync instruction, following the
same register-only 4-layer pattern established by the BF16 (#321) and
F64 (#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.

* fix: harden f16 warp MMA contract

Signed-off-by: nihalp <[email protected]>

* style: format standalone MMA example

Signed-off-by: nihalp <[email protected]>

---------

Signed-off-by: nihalp <[email protected]>
Co-authored-by: nihalp <[email protected]>
@honeyspoon
honeyspoon deleted the add-mma-f64 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