Unit 1 of 10 · about 3 hours · derive

GEMM operation counts and the naive kernel's traffic

A GEMM speed claim needs an operation count and a traffic model before it needs a timer. The naive kernel makes the cost of missing reuse visible.

You'll be able to

  • Derive useful GEMM operations and compulsory bytes for rectangular and batched shapes.
  • Trace a thread-per-output kernel and distinguish requested loads from DRAM traffic.
  • Predict how row-major thread mapping changes coalescing without changing the result.

Covers

M, N, K, batch shapes and useful GEMM operationsNaive thread-per-output GEMM and its traffic
1

Read

In this order, only the parts listed

0 of 3 done

  1. Arithmetic intensity before tilingAI Systems Performance Engineering - Chapters 9 and 10

    Chapter 9, opening discussion of arithmetic intensity and Figure 9-1

    Stop before Multilevel Microtiling and Software Prefetching. Treat the roofline as a ceiling, not proof that a kernel reaches either roof.

  2. Naive mapping and coalescingHow to Optimize a CUDA Matmul Kernel for cuBLAS-like Performance: a Worklog

    Kernel 1: Naive Implementation, including Lower Bounding the Fastest Possible Runtime; Kernel 2: Global Memory Coalescing

    Recalculate for your shape. The article's GEMM epilogue and RTX A6000 numbers are not the contract or measured speed of your kernel.

  3. A concrete naive CUDA kernelAI Systems Performance Engineering companion code - Chapters 9 and 10

    matmul_naive and main, at commit b57e4c6

    Read the square-only kernel and event interval. A checksum is not an independent elementwise correctness test.

2

Focus on

  • Use conventional shapes , . Report useful FLOPs for the multiply using the two-FLOP-per-FMA convention; count epilogue work separately.
  • For an overwrite-only product with element size , compulsory bytes are . A nonzero in adds an old-output read.
  • The naive overwrite kernel requests scalar input loads and stores. Broadcasts, caches and transaction overfetch make that different from measured DRAM bytes.
Common mistakes · 3
  • Reporting FLOPs as FLOP/s, or requested bytes as measured bandwidth traffic.
  • Assuming a low arithmetic intensity proves a bandwidth bottleneck. Launch overhead, uncoalesced accesses and dependency chains can prevent reaching the bandwidth roof.
  • Confusing dimension names across interfaces. LeetGPU Challenge 2 calls the reduction dimension N, unlike conventional GEMM notation.
3

Try it yourself

Closed-book, before checking anything

Closed-book, derive the counts for an overwrite-only FP32 product with , , . Get 393216 useful FLOPs, 45056 compulsory bytes, and 1597440 requested bytes for the uncached scalar-load model. For independent batches with no shared operands, multiply each count by the batch count.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Does an FMA count as one or two FLOPs?Answer

    Two in the usual GEMM throughput convention: a multiply and an add, despite being one instruction.

  2. 2.Why can the naive kernel read much less DRAM than its scalar-load count predicts?Answer

    Several threads request the same values, and caches or warp broadcasts can service those requests without separate DRAM reads.

  3. 3.For an overwrite-only square FP32 product with side , what is the compulsory-byte intensity?Answer

    FLOPs/byte. This assumes each input is read once and the output written once, not that a real kernel achieves it.

You're done when

You derive the rectangular counts without notes and explain one warp's input and output addresses without calling requested bytes DRAM traffic.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 9 more in the section

Also in this 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.

  • 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.

  • 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.

  • 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.