Triton, CUTLASS, and PyTorch Operators
Select, implement, and integrate GPU kernels
Choose the right kernel authoring level, integrate custom operations correctly, and make them composable with autograd and compilation.
Suppose a PyTorch profile shows that layer normalization and a following residual addition take 180 microseconds for a particular tensor shape. A developer can express a fused replacement as ordinary PyTorch operations, ask torch.compile to generate code, write a Triton kernel, assemble a CUTLASS operation, or write CUDA C++. Every route can compute the same numbers. The routes differ in how directly they expose thread assignment, memory layout, synchronization, matrix instructions, automatic differentiation, and integration with the rest of PyTorch.
Chapter 11 follows one optimized operation from a Python call to GPU execution. The first lesson compares implementation options using evidence from the missing capability, not a blanket ranking of languages. The second lesson launches a small Triton vector-add program and connects program identifiers, blocked offsets, masks, and compile-time parameters to the output array. The third lesson registers an operation with PyTorch so fake tensors, autograd, autocast, and torch.compile can reason about the operation without executing unsafe guesses.
Correct output from one contiguous FP16 tensor does not make a production operator complete. Real framework calls can contain odd sizes, transposed strides, non-contiguous views, BF16 values, gradient recording, graph capture, and devices that lack a specialized instruction. An operator test suite must make those cases observable. The fast implementation also needs an eligibility predicate: a Boolean decision that sends only supported inputs to the optimized kernel and sends every other valid input to a correct fallback.
PyTorch code begins on a central processing unit (CPU) and launches the selected work on a graphics processing unit (GPU). CUTLASS commonly builds matrix multiplication (GEMM) kernels. Triton and compiler tools can print an intermediate representation (IR), which is the compiler-owned program form between source code and target instructions. The lesson connects each printed artifact to one measured launch.
The final lesson constructs the evidence expected for a maintained or upstream contribution. A benchmark table covers representative shapes, including shapes with no improvement. Correctness tests state tolerances and edge cases. Compiler logs show whether the operator composes with graph capture. The resulting lesson treats kernel code as one part of a software interface that must remain correct as models, devices, and framework versions change.
Prerequisites
- Chapters 8–10: kernel schedules and numerical requirements
- Python, PyTorch tensors, and autograd
- C++ templates and CUDA builds at a reading level
Learning objectives
- Select CUDA, Triton, CUTLASS, a library, or compiler generation from required control
- Implement the metadata and gradient contracts of a PyTorch custom operation
- Prepare correctness and performance evidence for a maintained kernel path
Study this chapter
- 11.1Kernel implementation optionsBegin lesson →
Select an implementation level from the required schedule control and complete software lifecycle
- 11.2Triton programming modelBegin lesson →
Map an output tile to Triton program instances, pointer blocks, masks, and configuration parameters
- 11.3PyTorch custom operator requirementsBegin lesson →
Define schema, fake-tensor, autograd, autocast, dispatch, and fallback behavior for a custom operation
- 11.4Production and upstream integrationBegin lesson →
Specify an optimized input region and provide reproducible correctness, performance, and maintenance evidence
Extended exercises
Complete these projects after the lesson-level practice tasks. Each project combines several mechanisms from the chapter.
Triton trio
Implement vector add, fused softmax, and one reduction in Triton.
Evidence: Correctness and configuration sweeps across shapes.
Framework contract
Integrate one custom operation with schema, fake behavior, and autograd or an explicit non-differentiable contract.
Evidence: Operator checks, compile test, and benchmark.
Upstream candidate
Find and prepare a narrow issue or contribution in PyTorch, Triton, vLLM, or SGLang.
Evidence: Reproducer, tests, benchmark matrix, and a review-ready design note.
Sources and further reading
The lesson explanations synthesize primary papers and official references. Follow the originals for proofs, exact APIs, architecture details, and version-sensitive behavior.