Skip to content

M2 · 16 h · skeleton

Writing a real kernel

Triton is the first language. CUTLASS or CuTe comes after you can explain the Triton result, not before.

Prerequisite
Modules 0 and 1. Comfort reading a small GPU kernel.
VRAM
8 GB.
Runtime
A day of iteration, not a single run.

What you must be able to show

  1. 01

    Pass assert_close against eager PyTorch on a fixed seed, including a negative input and a length that is not a multiple of the tile.

  2. 02

    Time the kernel with search excluded, name the winning tile, and name one tile you rejected and why.

  3. 03

    Place the kernel on a roofline whose peak is measured or labelled ESTIMATE. Do not borrow a vendor peak and call it yours.

Insights

Write one fused kernel in Triton. RMSNorm with an affine scale, or a bias plus residual in the epilogue of a GEMM. The reference is eager PyTorch. The point of the kernel is a round trip you can point at in the byte count, not a new algorithm.

Order of work. Get allclose green on a multiple of the tile and on a tail (N = BLOCK + 17). Then autotune. Then time, with the search outside the timer. Then place FLOPs and bytes on the Module 0 roofline. If you reverse that order you will tune a kernel that drops the last rows.

  • Mask the tail on both the load and the store. For scores, the masked fill is a large negative, not zero. Zero is a real logit.
  • Acceptance: torch.testing.assert_close, tolerance written next to the dtype. FP16 is not FP32.
  • Acceptance: the benchmark process does not include autotune search time, and the winning config is in the JSON.
  • Acceptance: one rejected tile, with a reason (spill, tail waste, or a short sequence where eager wins).
  • CUTLASS or CuTe is optional, and only after the Triton test is green. A second language is not a result.

Wrong conclusion. ‘Occupancy is 100%, so the kernel is fast.’ Occupancy is a means. Achieved bandwidth or a passing roofline is the result. A tile that uses too many registers can be slower at higher occupancy than a smaller tile that hits the memory ceiling.

UNTESTED. No Triton in this preview. Do not invent a microbenchmark to fill the table.