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
Read
In this order, only the parts listed
0 of 4 done
- 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.cuStop 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
.b32and accumulators as.f32, so convert explicitly and use float registers for the accumulators. - 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.
- 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 Instructionmmaand Data Movement and Conversion InstructionscvtUse the TF32 diagrams and Ampere-compatible
cvt.rna.tf32.f32, which rounds nearest with ties away from zero. The nearest-evencvt.rn.tf32.f32variant requiressm_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. - 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.
Focus on
- WMMA requires uniform warp participation and matching arguments. Fragment element ownership is unspecified; use
store_matrix_syncbefore 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-assemblyrconstraints for multiplicands andfconstraints 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.f32so 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.
Try it yourself
Closed-book, before checking anything
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.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.What does the final
f32in the PTX opcode specify?AnswerThe initial accumulator operand type. The first
f32specifies the result type; the twotf32fields specify multiplicand types.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.Does FP32 accumulation recover information lost in TF32 conversion?Answer
No. It reduces later accumulation error but cannot restore discarded input significand bits.
Practice
- MIT 6.S894 Lab 6 Part 0 -
exercise_mmaImplement
exercise_mma.cuforsm_80or newer; retain the supplied fragment and numerical tests.Clone the public
accelerated-computing-class/lab6repository and build in your own harness withnvcc -O3 -arch=native exercise_mma.cu -o exercise_mmainstead of the course runner; a correct kernel printsmma_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.m16n8k8fragments,mmaandcvt, archived with CUDA 13.0.0; also consultcp.asynccompletion 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/ch09andcode/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.