Unit 4 of 10 · about 3 hours · measure
Generated code, resources and debugging Triton kernels
A slow or wrong Triton kernel is a compiler artifact until you read it. Resource reports and IR dumps turn guessing into evidence.
You'll be able to
- Inspect a compiled Triton kernel for registers, shared memory and the full IR-to-cubin trajectory.
- Debug a failing Triton kernel with the interpreter, device asserts and compute-sanitizer, and state what each tool cannot see.
- Build a minimal reproducer that isolates a Triton defect from the surrounding program.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Debugging TritonTriton Programming Guide and Tutorials
Using Triton's Debugging Operations:
static_print,static_assert,device_print,device_assert, withdevice_assertactive only whenTRITON_DEBUG=1; Using the Interpreter withTRITON_INTERPRET=1, including Limitations on bfloat16 and indirect access; Using Third-party Tools withcompute-sanitizer - GPU MODE Lecture 29: Triton internals and artifactsGPU MODE - Triton, CuTe and Machine Code
presentation.md: NVCC toolchain (nvccto PTX toptxasto SASS), Triton Compilation through TTIR, TTGIR, LLIR, PTX and cubin, the JIT handleasmkeys, andMLIR_ENABLE_DUMP=1for per-pass IR;vector_add.py:compiled_kernel.asmkeys withget_sass - Fused Softmax: occupancy from a warmup compileTriton Programming Guide and Tutorials
Compute Kernel helper
softmax: pre-compile withwarmup, then readn_regsandmetadata.sharedto derive occupancy from register and shared-memory limits - Debugging generated compiler codeAI Systems Performance Engineering - Chapter 14
Chapter 14, Performance Hints and Debugging Generated Code:
TORCH_LOGS,TORCH_COMPILE_DEBUG=1and the dumped FX graph, Inductor IR and Triton code
Focus on
- The
asmdict holdssource,ttir,ttgir,llir,ptxandcubin. Each stage answers a different question about the final machine code. n_regsandmetadata.sharedset resource ceilings before any profiler runs. Compare them against the launch before blaming the algorithm.- The interpreter runs programs sequentially on CPU with NumPy semantics. It exposes indexing bugs but not races or occupancy effects.
compute-sanitizerchecks races and out-of-bounds on hardware, where the interpreter cannot help.
Common mistakes · 3
- Adding
device_assertand seeing nothing. It executes only whenTRITON_DEBUG=1is set. - Trusting interpreter timing or race behavior. Sequential CPU simulation cannot show either; rerun on hardware with
compute-sanitizerfor those. - Reading
n_regsfrom awarmupcall with one grid and assuming it covers all configs. Anytl.constexprchange recompiles and can change resources.
Try it yourself
Closed-book, before checking anything
n_regs 26, shared 0, target sm_86, asm keys source, ttir, ttgir, llir, ptx and cubin, and a PTX header with .version 8.8, .target sm_86 and .reqntid 128. Measured on an RTX 3050 6 GB with CUDA 13.4; on your GPU, compare the structure, not the exact counts.Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.Which
asmkey holds the PTX, and which holds the final machine code?Answerptxholds the PTX andcubinholds the final machine code.ttir,ttgirandllirare the compiler stages above them.2.A kernel reports high
n_regsand zero shared memory. What limits occupancy first?AnswerRegisters. Divide the SM register file by registers per thread times threads per block, and compare against the block limit before touching shared memory.
3.Your kernel fails only on hardware but passes with
TRITON_INTERPRET=1. What class of bug is likely?AnswerA race, an out-of-bounds access masked by NumPy semantics, or a resource effect. Reproduce under
compute-sanitizerwith a minimal launch.4.Why does the interpreter refuse bfloat16 tensors?Answer
It has no bfloat16 operation support. Cast with
tl.castto float32 for the interpreter run, then re-verify on hardware.
Practice
- GPU MODE Lecture 29
vector_add.pycodegen inspectionRun
vector_add.pyfar enough to printcompiled_kernel.asm.keys(), dump thettgirandptx, and rerun withMLIR_ENABLE_DUMP=1; then run the same launch undercompute-sanitizerDo this on your own GPU with a short launch. Keep each sanitizer run small and never leave a process holding GPU memory.
You're done when
You can name the IR stage behind any PTX or SASS observation, and your minimal reproducer fails identically on hardware and under the sanitizer.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 9 more in the section
- Triton Programming Guide and TutorialsTriton Project · primary
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.
- AI Systems Performance Engineering - Chapter 14Chris Fregly · required
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.
- GPU MODE - Triton, CuTe and Machine CodeGPU MODE · support
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.
Also in this section
- UCSD CSE 291A/DSC 291 (Spring 2026) PA2 Part 1 - Triton matmul, add and ReLUUC San Diego · required
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. - TensorTonic Language Modeling from Scratch - Triton problemsTensorTonic · support
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 · support
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. - CUTLASS 3.x Design and CuTe Layout AlgebraNVIDIA · required
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 · required
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.
- PTX ISA and CUDA Binary UtilitiesNVIDIA · reference
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.
- CUDA Tile IR Programming ModelNVIDIA · depth
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 · depth
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.
- MIT 6.S894 Lecture 10 - Domain Languages and AcceleratorsMIT · support
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.