Unit 5 of 10 · about 5 hours · implement

Tensor-core MMA: WMMA, `mma.sync` fragments and CuTe atoms

Tensor cores compute a collective matrix operation, not independent thread FMAs. Correct lane ownership, conversion and warp participation come before performance tuning.

You'll be able to

  • Implement one warp-wide TF32 MMA with explicitly converted inputs and FP32 accumulators.
  • Distinguish opaque WMMA fragments, documented PTX lane fragments and CuTe MMA atoms.
  • Verify fragment ownership with basis products and a nonzero initial accumulator.

Covers

Tensor-core matrix multiply-accumulate modelWMMA, MMA atoms and CuTe-level abstraction boundariesOperand fragments, layout ownership and accumulator layout
1

Read

In this order, only the parts listed

0 of 4 done

  1. Tensor-core model and one-instruction exerciseMIT 6.S894 Accelerated Computing (Fall 2025) - Lectures 6 and 8 and Labs 4 to 6

    Fall 2025 Lab 6 Part 0: Tensor Cores and exercise_mma.cu

    Stop before full-matrix optimization. The handout passes raw FP32 bits through integer registers for every operand and relies on implicit truncation. That passes the lab tests on Ampere, but the PTX ISA leaves the TF32 layout implementation-defined and types multiplicands as .b32 and accumulators as .f32, so convert explicitly and use float registers for the accumulators.

  2. WMMA's collective and memory contractCUDA 13.0 matrix programming and PTX references

    CUDA 13.0.0 Programming Guide 10.24.1 Description, 10.24.2 Alternate Floating Point and 10.24.7 Example

    Read the FP16-input, FP32-accumulator example and TF32 conversion requirement. Do not infer lane ownership from the fragment array.

  3. Explicit TF32 lane map and conversionCUDA 13.0 matrix programming and PTX references

    PTX ISA 9.0: Matrix Fragments for mma.m16n8k8, Multiply-and-Accumulate Instruction mma and Data Movement and Conversion Instructions cvt

    Use the TF32 diagrams and Ampere-compatible cvt.rna.tf32.f32, which rounds nearest with ties away from zero. The nearest-even cvt.rn.tf32.f32 variant requires sm_90 (Hopper, compute capability 9.0); on GPUs older than Hopper (compute capability below 9.0) use the Ampere-compatible conversion. Skip FP64 and sparse variants.

  4. Instruction traits become an MMA atomCuTe GEMM Tutorial

    CuTe MMA Atoms: Operation structs and Traits; TiledMMAs, documentation dated September 21, 2026

    Follow how instruction shape and thread/value layouts define the atom. Compare with your PTX map rather than implementing another complete GEMM.

2

Focus on

  • WMMA requires uniform warp participation and matching arguments. Fragment element ownership is unspecified; use store_matrix_sync before coordinate-dependent epilogues.
  • WMMA load/store pointers require 32-byte alignment; leading dimensions require multiples of 8 half elements or 4 float elements, both 16 bytes. A valid allocation base does not validate every subview.
  • For mma.sync.aligned.m16n8k8.row.col.f32.tf32.tf32.f32, each lane supplies four TF32 bit-pattern values for the first operand, two for the second, and four FP32 accumulator values. Use inline-assembly r constraints for multiplicands and f constraints for accumulators.
  • MMA shape, input representation, accumulator type and output storage are separate parts of the numerical contract. One collective instruction performs 2048 useful FLOPs for this shape.
Common mistakes · 3
  • Passing raw FP32 bit patterns as TF32 operands because the lab tests pass. The PTX ISA leaves the TF32 layout implementation-defined; convert with cvt.rna.tf32.f32 so the rounding is the one you state.
  • Executing a collective MMA or WMMA call in only some lanes, including at an output boundary.
  • Using a WMMA fragment's array index as a portable row or column index.
3

Try it yourself

Closed-book, before checking anything

Implement the one-warp 16 by 8 by 8 TF32 product in Lab 6 exercise_mma.cu. Explicitly convert each multiplicand with Ampere-compatible cvt.rna.tf32.f32, then issue mma.sync.aligned.m16n8k8.row.col.f32.tf32.tf32.f32. Run its permutations, basis products, decimal inputs and zero/nonzero accumulator cases against the bundled absolute-error threshold 0.005. Inspect the generated PTX and SASS: on an RTX 3050 with CUDA 13.4, each conversion appears as an FSETP finite check plus an integer add of 0x1000 rather than a named convert instruction, and the product as one HMMA.1688.F32.TF32 on that example GPU; your SASS may differ, so report what your own build emits and explain each lane's loaded and stored coordinates.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.What does the final f32 in the PTX opcode specify?Answer

    The initial accumulator operand type. The first f32 specifies the result type; the two tf32 fields specify multiplicand types.

  2. 2.Why test a nonzero initial accumulator?Answer

    A correct product-only result does not prove accumulator loading and mapping are correct. The instruction computes a product plus that initial matrix.

  3. 3.Does FP32 accumulation recover information lost in TF32 conversion?Answer

    No. It reduces later accumulation error but cannot restore discarded input significand bits.

5

Practice

  • MIT 6.S894 Lab 6 Part 0 - exercise_mma

    Implement exercise_mma.cu for sm_80 or newer; retain the supplied fragment and numerical tests.

    Clone the public accelerated-computing-class/lab6 repository and build in your own harness with nvcc -O3 -arch=native exercise_mma.cu -o exercise_mma instead of the course runner; a correct kernel prints mma_16x8x8 tests passed.

You're done when

The one-warp exercise passes every supplied case, and you can distinguish PTX ownership from opaque WMMA fragments and identify the emitted tensor instruction.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 9 more in the section
  • MIT 6.S894 Accelerated Computing (Fall 2025) - Lectures 6 and 8 and Labs 4 to 6MIT · required

    Use Lecture 6 for tensor cores and arithmetic intensity and Lecture 8 (Evolving Ampere to Hopper) for the production GEMM schedule. Do Lab 4 (tiling and reuse), Lab 5 (scheduling and problem sizes) and Lab 6 (tensor cores through inline PTX) built for your own GPU; each harness checks results against bundled test data. Lab 6 needs sm_80 or newer.

  • CuTe GEMM TutorialNVIDIA CUTLASS · required

    Work through tiling, layouts, copy atoms and MMA atoms. Draw the logical and physical ownership for one tile, then modify a shape or layout and verify both generated mapping and numerical output.

  • CUDA 13.0 matrix programming and PTX referencesNVIDIA · reference

    Coverage and correctness gap: the pool lacks a precise WMMA contract, and Lab 6 relies on TF32 conversion and register behavior the PTX ISA leaves unspecified. Use Programming Guide 10.24 and PTX ISA 9.0 mma.m16n8k8 fragments, mma and cvt, archived with CUDA 13.0.0; also consult cp.async completion semantics.

Also in this section

  • AI Systems Performance Engineering - Chapters 9 and 10Chris Fregly · primary

    Read Chapter 9 on arithmetic intensity, tiling and fusion, and Chapter 10 on intra-kernel pipelining, warp specialization and thread-block clusters. Separate what applies to every NVIDIA GPU from what needs Hopper or Blackwell.

  • AI Systems Performance Engineering companion code - Chapters 9 and 10Chris Fregly · required

    Inspect and run compatible baseline and optimized paths from code/ch09 and code/ch10. Verify whether each path is a custom kernel, compiler selection or library dispatch, then add an independent correctness and timing wrapper.

  • How to Optimize a CUDA Matmul Kernel for cuBLAS-like Performance: a WorklogSimon Boehm · support

    Read kernels 1 to 6, 9 and 10 with the companion repository. Its numbers come from an RTX A6000 (Ampere); remeasure on your GPU before comparing your kernels with them.

  • OCP 8-bit Floating Point SpecificationOpen Compute Project · required

    Study E4M3 and E5M2 encodings, exceptional values and conversion behavior. Build value-boundary tests and separate format correctness from the scaling policy chosen by a framework or kernel.

  • LeetGPU - GEMM and Quantized Matmul ChallengesAlphaGPU · required

    Solve 2 Matrix Multiplication and 22 GEMM, then choose 30 Batched Matrix Multiplication or 57 FP16 Batched Matmul. Attempt 32 INT8 Quantized Matmul or 81 INT4 Matmul only after scale and accumulator tests pass. Preserve local baselines and shape matrices.

  • GPU MODE - CUTLASS, Tensor Cores and CuTeGPU MODE · support

    Use Lectures 15, 23, 36, 57, 86, 103 and 114 selectively. Pair each chosen lecture with one implemented layout, instruction or pipeline change and compare it against a vendor-library baseline.

  • DeepGEMMDeepSeek · depth

    After the portable GEMM passes, reconstruct one Hopper FP8 path from source, identify its hardware, layout and scaling assumptions, and test a bounded modification only on supported hardware. Do not generalize repository benchmarks to other shapes or GPUs.

  • Modern GPU Programming for MLSysMLC · depth

    Read the performance, data-layout, tensor-core, TMA, tensor-memory, barrier and GEMM chapters for a Blackwell-depth route. Execute only with sm_100a and the pinned TIRx toolchain; otherwise use it for derivation and code reading.

  • TensorRT quantization schemes and workflowsNVIDIA · reference

    Coverage gap: the existing pool does not derive scale granularity and reconstruction conventions precisely. Read INT8/FP8 equations, per-tensor/per-channel/block quantization and dynamic quantization in documentation dated October 5, 2026. Skip engine building and replace the block pseudocode's floor-divided scale count with ceiling division.