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

Registers, shared memory, occupancy and generated-code inspectionInterpreter, assertions, sanitizer limits and minimal reproducers
1

Read

In this order, only the parts listed

0 of 4 done

  1. Debugging TritonTriton Programming Guide and Tutorials

    Using Triton's Debugging Operations: static_print, static_assert, device_print, device_assert, with device_assert active only when TRITON_DEBUG=1; Using the Interpreter with TRITON_INTERPRET=1, including Limitations on bfloat16 and indirect access; Using Third-party Tools with compute-sanitizer

  2. GPU MODE Lecture 29: Triton internals and artifactsGPU MODE - Triton, CuTe and Machine Code

    presentation.md: NVCC toolchain (nvcc to PTX to ptxas to SASS), Triton Compilation through TTIR, TTGIR, LLIR, PTX and cubin, the JIT handle asm keys, and MLIR_ENABLE_DUMP=1 for per-pass IR; vector_add.py: compiled_kernel.asm keys with get_sass

  3. Fused Softmax: occupancy from a warmup compileTriton Programming Guide and Tutorials

    Compute Kernel helper softmax: pre-compile with warmup, then read n_regs and metadata.shared to derive occupancy from register and shared-memory limits

  4. Debugging generated compiler codeAI Systems Performance Engineering - Chapter 14

    Chapter 14, Performance Hints and Debugging Generated Code: TORCH_LOGS, TORCH_COMPILE_DEBUG=1 and the dumped FX graph, Inductor IR and Triton code

2

Focus on

  • The asm dict holds source, ttir, ttgir, llir, ptx and cubin. Each stage answers a different question about the final machine code.
  • n_regs and metadata.shared set 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-sanitizer checks races and out-of-bounds on hardware, where the interpreter cannot help.
Common mistakes · 3
  • Adding device_assert and seeing nothing. It executes only when TRITON_DEBUG=1 is set.
  • Trusting interpreter timing or race behavior. Sequential CPU simulation cannot show either; rerun on hardware with compute-sanitizer for those.
  • Reading n_regs from a warmup call with one grid and assuming it covers all configs. Any tl.constexpr change recompiles and can change resources.
3

Try it yourself

Closed-book, before checking anything

Launch the vector-add kernel with on Triton 3.8.0 and read the handle: 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.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Which asm key holds the PTX, and which holds the final machine code?Answer

    ptx holds the PTX and cubin holds the final machine code. ttir, ttgir and llir are the compiler stages above them.

  2. 2.A kernel reports high n_regs and zero shared memory. What limits occupancy first?Answer

    Registers. Divide the SM register file by registers per thread times threads per block, and compare against the block limit before touching shared memory.

  3. 3.Your kernel fails only on hardware but passes with TRITON_INTERPRET=1. What class of bug is likely?Answer

    A race, an out-of-bounds access masked by NumPy semantics, or a resource effect. Reproduce under compute-sanitizer with a minimal launch.

  4. 4.Why does the interpreter refuse bfloat16 tensors?Answer

    It has no bfloat16 operation support. Cast with tl.cast to float32 for the interpreter run, then re-verify on hardware.

5

Practice

  • GPU MODE Lecture 29 vector_add.py codegen inspection

    Run vector_add.py far enough to print compiled_kernel.asm.keys(), dump the ttgir and ptx, and rerun with MLIR_ENABLE_DUMP=1; then run the same launch under compute-sanitizer

    Do 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.py on 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/ch13 and code/ch14 selectively 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.