Triton, CuTe and Compiler Paths
Modern kernel work spans CUDA, tile languages, template libraries and graph compilers. This stage implements the same mechanisms through multiple abstraction levels, inspects lowering and makes autotuning, dispatch and fallback correctness explicit.
Section 7 of 10 · 10 units · about 40 hours
By the end you can Implement the same nontrivial kernel in CUDA and Triton, reconstruct the lowering and resource behavior, correctness-gate autotuning and dispatch, and preserve compiler or library fallback across unseen shapes and one version change.
Units
- Triton programs, program IDs, pointers and masks4h
- Triton reductions and dot-product precision3h
- Specialization, autotuning and compile-cost accounting5h
- Generated code, resources and debugging Triton kernels3h
- Matched CUDA and Triton kernels and the lowering path5h
- `torch.compile` capture, fusion, graph breaks and recompilation4h
- Custom operators, stream semantics and autograd contracts3h
- The CUTLASS hierarchy and CuTe layout algebra5h
- CuTe copy and MMA atoms, tiled MMAs and pipelines4h
- Other programming models, dispatch with fallback and compiler regression tests4h
Build it
Mini project · about 12 to 16 hours
Matched CUDA and Triton paths with lowering and dispatch gates
Implement the same mechanisms in CUDA and Triton: blocked programs, reductions, autotuning, codegen inspection, a custom op, one CuTe GEMM reconstruction and versioned dispatch with fallback. Paths your toolchain or GPU lacks are read, not run.
- 1Write a Triton vector-add kernel with its grid function, checked against
x + yon shapes you choose, including non-multiples of the block size. Add a masked approximate GELU checked againsttorch.nn.functional.geluin two dtypes, each with a matched CUDA twin under identical tests. - 2Implement tiled row sums and stable row-wise softmax for strided inputs with padding and partial tiles, checked against fp32 references. Show where
tl.dotprecision flags change the error against float64, and name which rounding dominates. - 3Run the CSE 291A PA2 Part 1 fused kernel under
student_local_test.py, with an autotuning search gated on correctness. Separate cold compile cost from warm launch cost with interleaved timings against the PyTorch reference. - 4Inspect one compiled kernel from Triton IR down to PTX, quoting register and shared-memory usage from your own build. Compile one CUDA source file with
-arch=nativeand comparecuobjdump -sassandcuobjdump -res-usageoutput with the Triton report. - 5Use
torch._dynamo.explainto contrast a data-dependent branch with its branch-free rewrite, quoting graph and break counts from your own run. Register a Triton LayerNorm as a custom op with gradient checks against the framework, and record its higher-order limitation. - 6Reconstruct one GEMM configuration down to layouts, copy atoms and MMA atoms, and compare it stage by stage with the equivalent Triton blocked program. Wrap the Triton softmax from LeetGPU challenge 5 in versioned dispatch with a tested fallback and a register-change regression.
What you hand in
- Matched CUDA and Triton kernels with shared tests, pinned precision and kept losing shapes.
- Autotune and compile evidence: cold against warm costs, codegen dumps and dynamo break reports.
- The CuTe GEMM reconstruction, the custom LayerNorm op and versioned dispatch with fallback.
How to check it
- Self-grade with the rubric below
- LeetGPU CUDA and Triton parity set
Re-solve one primitive, one GEMM and one transformer challenge in Triton with matched CUDA twins against
reference_impl. - CSE 291A PA2 Part 1 student tests
Run
student_local_test.py; compare with interleaved timing against PyTorch, not the hosted score.
How it's graded
Parity with pins
Pass: CUDA and Triton twins pass identical tests from your own harness including tails and non-powers of two, with precision pinned before timing and losing shapes kept.
Great: Register and shared-memory lines are quoted from your own build, with the flags that produced them.
Autotune and lowering honesty
Pass: The second autotuned launch skips benchmarking, cold and warm costs are separated, and break counts come from your own run.
Great: Each recompile names the guard that triggered it.
Reconstruction and dispatch
Pass: The CuTe reconstruction reaches layouts, copy atoms and MMA atoms, and dispatch tests cover native, forced fallback and register-change branches.
Great: The LayerNorm gradient derivation states its row-mean terms and its higher-order limit is tested.
Resources
- Triton Programming Guide and TutorialsTriton Project
Complete the vector add, fused softmax, matrix multiplication, LayerNorm and fused-attention tutorials that run on your hardware. For each, add adversarial tails, independent references, cold and warm timing, resource inspection and a correct fallback.
- UCSD CSE 291A/DSC 291 (Spring 2026) PA2 Part 1 - Triton matmul, add and ReLUUC San Diego
Implement the fused kernel and its configuration search, and test with
student_local_test.pyon your own GPU. The remote grader needs a course token, so replace its speedup score with your own interleaved timing against the PyTorch reference. - AI Systems Performance Engineering - Chapter 14Chris Fregly
Read Chapter 14 on the PyTorch compiler, OpenAI Triton and XLA backends. Trace one framework operation from graph capture through generated GPU code, and identify graph breaks and specialization guards.
- CUTLASS 3.x Design and CuTe Layout AlgebraNVIDIA
Study the collective and kernel hierarchy, then the CuTe layout algebra guide. Reconstruct one GEMM configuration down to layouts, copy atoms and MMA atoms and compare it with the equivalent Triton blocked program.
- LeetGPU - CUDA and Triton Parity SetAlphaGPU
Re-solve one primitive, one GEMM and one transformer challenge from GPU-4 through GPU-6 in Triton. Compare CUDA, Triton, compiler and library paths on identical tests and hardware; leaderboard rank does not replace local raw evidence.
- TensorTonic Language Modeling from Scratch - Triton problemsTensorTonic
Solve Masked Triton GELU Kernel, Tiled Triton Row Sum, Triton Row-Wise Softmax and Fused Tiled Matmul and ReLU, and rerun each with your own adversarial shapes.
- AI Systems Performance Engineering companion code - Chapters 9, 10, 13 and 14Chris Fregly
Use
code/ch09,code/ch10,code/ch13andcode/ch14selectively for Triton, warp specialization, persistent kernels and compiler comparisons. Strip local compatibility shims when diagnosing upstream failures and record every guard in the measurement context. - GPU MODE - Triton, CuTe and Machine CodeGPU MODE
Use Lectures 14, 15, 29, 37, 57, 86, 103, 104 and 114 selectively. Assign one lecture to each actual implementation question rather than watching the collection linearly.
- MIT 6.S894 Lecture 10 - Domain Languages and AcceleratorsMIT
Use the Higher-level kernel languages slides comparing Triton, Pallas, cuTile (Tile IR) and the CuTe DSL on mapping, effort and performance for the programming-model comparison. Do not use the TPU lab.
- CUDA Tile IR Programming ModelNVIDIA
Read the programming model and inspect the official repository after CUDA, Triton and CuTe mappings are clear. Implement one tiny parity kernel only if the toolchain supports it and record compiler-version constraints.
- Modern GPU Programming for MLSys - TIRxMLC
Use Parts II and III plus the compiler reference as a Blackwell-specific comparison of layouts, dispatch, TMA pipelines and persistent scheduling. Do not make TIRx a required dependency for the portable track.
- PTX ISA and CUDA Binary UtilitiesNVIDIA
Inspect generated PTX and SASS for the matched CUDA and Triton kernels. Check instruction, memory-space and target assumptions in the versioned ISA and use binary tools to confirm which device code ships.