GEMM, Tensor Cores and Low Precision
Matrix multiplication is the central case study in co-designing data layout, reuse, instruction choice and asynchronous pipelines. Low precision adds scaling and numerical contracts that must remain visible behind impressive throughput numbers.
Section 5 of 10 · 10 units · about 46 hours
By the end you can Build a correctness-gated tiled GEMM, explain its hierarchy and low-precision contract, compare it across representative shapes with a strong library baseline, and show profiler evidence for both its best regime and a regime where it loses.
Units
- GEMM operation counts and the naive kernel's traffic3h
- Shared-memory tiling and boundary predication4h
- Register tiles, vectorized tile copies and resource limits5h
- Block, warp and instruction tiling with swizzled shared-memory layouts4h
- Tensor-core MMA: WMMA, `mma.sync` fragments and CuTe atoms5h
- Asynchronous copies, multistage pipelines and warp specialization6h
- Input, product and accumulation precision across FP16, BF16, TF32 and FP84h
- Scale granularity and quantization error against task tolerances4h
- Epilogue fusion and persistent or grouped GEMM5h
- Library baselines, shape-aware dispatch and residual analysis6h
Build it
Mini project · about 14 to 20 hours
Tiled GEMM to async pipelines with a low-precision error contract
Grow kernellab through the GEMM ladder from naive counts to tiled, tensor and pipelined kernels with quantization error and fused epilogues. Every level is gated against a vendor baseline with a held-out fallback. Paths your GPU cannot run, such as Hopper TMA or Blackwell tcgen05, are audited statically.
- 1Write a naive overwrite-only GEMM with a shape-to-FLOP calculator and compulsory and requested byte models. Check small products against CPU double precision.
- 2Write shared-memory and register-tiled GEMMs with edge and empty-dimension tests against CPU double products. Add aligned-copy dispatch with scalar tails, compare variants with interleaved trials, keep
cuobjdump -res-usagereports, and pass LeetGPU challenges 2 and 22. - 3Draw the tile-ownership diagram and verify one shared-layout permutation with a bank enumerator. Keep the verified permutation in the kernel.
- 4Implement the tensor-core path from MIT 6.S894 Lab 6
exercise_mma.cu, pass its numerical tests and inspect the generated MMA instructions. Read Hopperwgmmaand Blackwelltcgen05code, and run it only if your GPU has them. - 5Implement a two-stage
cp.asyncpipeline (compute capability 8.0 or newer) with a stage-lifetime diagram and short-loop and tail regressions. Compare it with the synchronous version using interleaved trials and sanitizer checks. - 6Decode the low-precision format boundaries and midpoint conversions, separating input-conversion from accumulation error. Compare per-tensor, per-channel and block quantization against an integer-accumulator reference with a predeclared acceptance table.
- 7Add bias and ReLU fusion with a complete-operation timing pair, then compare your ladder against a vendor baseline across a shape matrix. Hold one shape out from tuning for fallback, and report best with losing regimes and residuals.
What you hand in
- The GEMM ladder with FLOP and byte models, edge tests, sanitizer regressions and resource reports.
- The tensor path with instruction evidence, two-stage pipeline with lifetime diagram, and sync against async comparison.
- The format decoder with acceptance table, fused epilogue timing pair, and vendor sweep with held-out fallback.
How to check it
- Self-grade with the rubric below
- LeetGPU GEMM challenges against the reference implementation
Run 2 Matrix Multiplication and 22 GEMM in your own harness with matched tolerances; keep shape matrices and losing regimes.
- MIT 6.S894 Lab 6 tensor-core exercise
Build
exercise_mma.cuwith-arch=nativeand keep the supplied fragment and numerical tests.
How it's graded
Tiling correctness
Pass: Each GEMM level matches the CPU double reference on edge and odd shapes, and the held-out shape passes on fallback.
Great: Short-loop and tail cases are kept as regressions that fail on the unguarded kernel.
Resource and pipeline
Pass: Thread mapping, stage bytes and resource reports are kept, the lifetime diagram predicts synchronization, and sync against async uses interleaved trials.
Great: Paths your GPU cannot run are marked as static audit with no performance claim.
Numerical contract
Pass: Format boundaries and the input against arithmetic split are tested, quantization states scales and acceptance limits, and the vendor comparison keeps losing regimes.
Great: Unseen-value saturation is shown, and the fusion saving is derived before the timing pair.
Resources
- AI Systems Performance Engineering - Chapters 9 and 10Chris Fregly
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
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. - MIT 6.S894 Accelerated Computing (Fall 2025) - Lectures 6 and 8 and Labs 4 to 6MIT
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
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.
- OCP 8-bit Floating Point SpecificationOpen Compute Project
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
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.
- How to Optimize a CUDA Matmul Kernel for cuBLAS-like Performance: a WorklogSimon Boehm
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.
- GPU MODE - CUTLASS, Tensor Cores and CuTeGPU MODE
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
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
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.
- CUDA 13.0 matrix programming and PTX referencesNVIDIA
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. - TensorRT quantization schemes and workflowsNVIDIA
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.