Unit 5 of 10 · about 5 hours · explain, implement

Matched CUDA and Triton kernels and the lowering path

Two kernels that pass the same tests can still differ in precision, resources and shipped machine code. Parity work makes the difference visible.

You'll be able to

  • Implement matched CUDA and Triton kernels for one operation and test them against the same reference and tolerances.
  • Trace both kernels from source through PTX to SASS and state which device code actually ships.
  • Explain where the Triton lowering diverges from handwritten CUDA: tiling, precision defaults and launch setup.

Covers

Matched CUDA and Triton implementations of the same kernelFrontend, IR, lowering, LLVM, PTX and machine-code trajectory
1

Read

In this order, only the parts listed

0 of 3 done

  1. GPU MODE Lecture 29: compilation trajectoriesGPU MODE - Triton, CuTe and Machine Code

    presentation.md: Device Code Processing with cicc to PTX and ptxas to SASS, then Triton Compilation from the DSL through TTIR, TTGIR, LLIR, PTX and cubin with the cache layout

  2. CUDA Binary UtilitiesPTX ISA and CUDA Binary Utilities

    Sections 1.2 (cuobjdump against nvdisasm inputs), 2.1.1 (dumping SASS, ELF and PTX), 2.1.2 (listing embedded binaries) and 2.1.3 (resource usage with -res-usage)

  3. Triton lowering to PTXAI Systems Performance Engineering - Chapter 14

    Chapter 14, Triton Programming Model: Triton converts the program to PTX with each program using a single CUDA thread block, and vectorizes arithmetic and memory operations

2

Focus on

  • cuobjdump accepts cubins and host binaries while nvdisasm accepts only cubins with richer output. Pick the tool by input, not habit.
  • -res-usage reports registers and shared memory per function. Match those numbers against the Triton handle before comparing speed.
  • A fat binary can carry several architectures. List embedded binaries before claiming which SASS runs.
  • Triton tl.dot defaults to tf32 on fp32 inputs while a naive CUDA kernel stays in fp32. Parity tests must pin precision on both sides.
Common mistakes · 3
  • Comparing PTX .target strings and calling it a performance result. PTX is virtual; only the SASS for your architecture executes.
  • Forgetting cuobjdump -lelf on a shipped binary. The running code may come from a different embedded arch than the one you inspected.
  • Attributing a Triton-versus-CUDA gap to tiling when one side used tf32 and the other used fp32. Fix input_precision first.
3

Try it yourself

Closed-book, before checking anything

Compile a vector-add .cu with nvcc -arch=native -cubin and run cuobjdump -sass plus cuobjdump -res-usage. Show the guarded prologue (S2R, IMAD, ISETP, guarded EXIT, LDG.E loads) and the resource line, which read REG:12 with SHARED:0 under CUDA 13.4 for compute capability 8.6; 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.When do you reach for nvdisasm instead of cuobjdump?Answer

    When the input is already a cubin and you want control-flow graphs, register liveness or source correlation, which cuobjdump does not provide.

  2. 2.Your binary runs slower than the SASS you inspected suggests. What do you check?Answer

    Which embedded binary actually loads, with -lelf and the driver architecture. The inspected SASS may belong to another arch.

  3. 3.The Triton kernel is faster than your CUDA kernel on fp32 matmul. What is the first suspect?Answer

    Precision: Triton tl.dot defaults to tf32 inputs while the CUDA kernel accumulates true fp32. Re-run with input_precision='ieee' before crediting tiling.

  4. 4.What does REG:12 SHARED:0 tell you about the vector-add kernel?Answer

    It uses 12 registers per thread and no shared memory, so occupancy is set by registers and block limits, not by shared memory.

5

Practice

  • LeetGPU 1 Vector Addition in Triton with a CUDA twin

    Public challenge.py at challenges/easy/1_vector_add/challenge.py: torch.add reference with atol=1e-05, rtol=1e-05, free tier

    Write matched CUDA and Triton kernels in your own repository and pass the example plus the scalar-tail and non-power-of-two functional tests, on LeetGPU or locally against reference_impl from challenge.py as in the CUDA primitives section (a Triton solve takes the tensors directly). Then compare cuobjdump -res-usage reports for both.

  • LeetGPU 2 Matrix Multiplication in Triton with a CUDA twin

    Public challenge.py at challenges/easy/2_matrix_multiplication/challenge.py: torch.matmul reference with atol=0.0001, rtol=0.0001, free tier

    Pin input_precision on the Triton side and the accumulation on the CUDA side before any timing, and keep the losing shapes in your report.

You're done when

Both twins pass the same tests, and you can point at the PTX and SASS lines plus the resource reports that explain their gap.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 9 more in the section
  • 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.

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

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

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

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