On this page
If you want to write GPU kernels for LLM inference, you'll hear two names: CUDA and Triton. They're not competitors in the way two frameworks are. They work at different levels, and most people who write inference kernels use both. The question is which to start with and what each is for.
#The one-sentence difference
- CUDA is NVIDIA's C++ programming model: you write code for one thread and reason about how 32 threads in a warp, and blocks of warps, share work and memory.
- Triton is a Python-embedded language: you write code for one block of data with vector operations, and the compiler decides how threads, shared memory and tensor cores carry it out.
If kernels are new to you, read what is a GPU kernel first.
#The same kernel in both
A row-wise softmax, the kind of reduction that appears all over inference.
In Triton, one program handles one row:
@triton.jit
def softmax(x_ptr, y_ptr, stride, n, BLOCK: tl.constexpr):
row = tl.program_id(0)
cols = tl.arange(0, BLOCK)
x = tl.load(x_ptr + row * stride + cols, mask=cols < n, other=-float("inf"))
x = x - tl.max(x, axis=0)
e = tl.exp(x)
tl.store(y_ptr + row * stride + cols, e / tl.sum(e, axis=0), mask=cols < n)
# one program per row; BLOCK is the row length rounded up to a power of two
softmax[(n_rows,)](x, y, x.stride(0), n_cols, BLOCK=triton.next_power_of_2(n_cols))tl.max and tl.sum are whole-block reductions. How the values are spread across threads, and how those threads combine their results, is the compiler's job.
In CUDA, the same thing needs you to do the reduction yourself: each thread handles a strided slice of the row, the 32 threads of each warp combine their partial max and sum with shuffle instructions, warps exchange results through shared memory with a barrier, and then every thread writes its outputs. Just the warp-level piece looks like this:
__inline__ __device__ float warp_max(float v) {
// each step halves the distance; after 5 steps every lane holds the max
for (int offset = 16; offset > 0; offset /= 2)
v = fmaxf(v, __shfl_xor_sync(0xffffffff, v, offset));
return v;
}Add the same for the sum, a shared-memory step to combine warps, the loads and stores with bounds checks, and the launch configuration, and the full kernel is 40 or so lines. Every one of them is a decision Triton made for you: how values are spread across threads, how the reduction tree works, where the barrier goes.
Neither is "better". Triton is shorter and harder to get wrong. CUDA shows you exactly what happens, and lets you change any of it.
#Autotuning: Triton's other big advantage
The best block sizes, number of warps and pipeline depth depend on the GPU and the input shape. In CUDA, you pick them by hand or write your own search. In Triton, you list candidates and let it measure:
@triton.autotune(
configs=[
triton.Config({"BLOCK_M": 128, "BLOCK_N": 128, "BLOCK_K": 64}, num_warps=8, num_stages=3),
triton.Config({"BLOCK_M": 64, "BLOCK_N": 128, "BLOCK_K": 32}, num_warps=4, num_stages=4),
],
key=["M", "N", "K"],
)
@triton.jit
def matmul_kernel(...):
...The first call for each new combination of M, N and K benchmarks every config and caches the winner. That's how one Triton kernel stays fast across GPUs and shapes without hand-tuning (Triton matmul and autotuning).
#Where each wins
| CUDA | Triton | |
|---|---|---|
| Control | Total: threads, warps, shared memory layout, every instruction | Block-level; the compiler handles the rest |
| Productivity | Slow to write and debug | Fast; kernels are often 5 to 10 times shorter |
| Peak performance | Highest, especially on the newest GPUs with tools like CUTLASS and CuTe | Very good for most kernels; the very best Hopper and Blackwell GEMMs and attention kernels are still usually CUDA |
| Portability | NVIDIA only | NVIDIA and AMD, from the same source |
| Tensor cores | Through WMMA, MMA, wgmma or libraries | tl.dot, chosen for your GPU automatically |
| Tuning | By hand | Built-in autotuning |
| Debugging | compute-sanitizer, Nsight, printf |
An interpreter mode on the CPU (TRITON_INTERPRET=1), plus the same profilers |
| Where you'll meet it | cuBLAS, FlashAttention, CUTLASS, engine kernels | torch.compile output, many engine kernels (fused MoE, attention variants) |
#How they show up in real engines
- vLLM has both: custom CUDA kernels for attention, quantised matmuls and norms, and Triton kernels for things like fused MoE and some attention paths.
- SGLang similarly mixes CUDA kernels (often via FlashInfer) with Triton kernels.
torch.compilegenerates Triton for fused elementwise and reduction code. SetTORCH_LOGS="output_code"to read what it produced.- FlashAttention 3 and the fastest Hopper and Blackwell GEMMs are CUDA built on CUTLASS and CuTe, because they depend on architecture-specific features like asynchronous warpgroup matmuls and the TMA copy engine.
So if you want to read and modify engine code, you'll need to read both.
#The newer options
The kernel-language space is busy. Alongside CUDA and Triton you'll hear about:
- CUTLASS and CuTe: NVIDIA's C++ template libraries for building high-performance matmuls and attention, now with a Python front end as well.
- Lower-level Triton dialects that expose more hardware control for the newest GPUs.
- Research and startup languages (such as ThunderKittens and TileLang) that aim for CUDA-level performance with Triton-like brevity.
They're worth watching, but CUDA and Triton are what you'll meet in engine code today, and the concepts transfer to everything else.
#A learning order that works
- A little CUDA first. Threads, blocks, warps, coalescing, shared memory, a tiled matmul and a warp-shuffle reduction. Two or three weeks. You're not learning CUDA to write everything in it; you're learning what a GPU actually does, so that Triton's choices (block size,
num_warps,num_stages) make sense. - Then Triton for real work. Vector ops, reductions, an autotuned matmul, fused norms and activations, an attention kernel. This is where most custom inference kernels are written.
- Profiling throughout. Nsight Systems for where time goes, Nsight Compute for why a kernel is slow. Without profiling, both languages are guesswork.
- Back to CUDA (CUTLASS, CuTe) only if you need the last 10 to 20% on a specific new GPU, or architecture features Triton doesn't expose yet.
If you only have time for one: learn enough CUDA to understand warps, memory and tensor cores, then spend your effort on Triton.
#An eight-week plan
| Week | Focus | Build |
|---|---|---|
| 1 | Threads, blocks, warps, memory hierarchy | Vector add; measure achieved bandwidth |
| 2 | Coalescing and shared memory | A transpose that's fast, and one that isn't |
| 3 | Tiling and occupancy | A tiled matmul; compare with cuBLAS |
| 4 | Warp shuffles and reductions | Softmax and RMSNorm in CUDA |
| 5 | Triton basics | The same softmax and RMSNorm in Triton |
| 6 | Triton matmul and autotuning | An autotuned matmul with grouped ordering |
| 7 | Fusion and PyTorch integration | A fused SwiGLU registered as a PyTorch custom op |
| 8 | Profiling and a real speed-up | Profile a model layer, find the slow kernel, fix it |
All of it runs on a free cloud GPU; you don't need to buy hardware to learn.
#What you don't need to do
- Beat cuBLAS at plain matrix multiplication. Use it.
- Write kernels before profiling. Most inference speed-ups come from configuration, batching, quantisation and fusion that compilers already do.
- Learn PTX (NVIDIA's assembly) unless you're working on compilers or the most specialised kernels.
#Mistakes that waste the most time
- Benchmarking without synchronising. GPU calls return before the work finishes; time with CUDA events or
torch.cuda.synchronize(), after a warm-up. - Testing only one input shape. A kernel that wins at 4,096 can lose at 4,000 because of padding and masking.
- Skipping correctness checks. Compare against a PyTorch reference with sensible tolerances on every change.
- Optimising a kernel that takes 2% of the step. Profile first.
#FAQ
Do inference engineering jobs require CUDA? Many ask for it, and most value the understanding even when daily work is in Python. Being able to read CUDA and write Triton covers most needs (how to become an inference engineer).
Is Triton only for NVIDIA? No. It also targets AMD GPUs, which is one of its main attractions.
Can I write Triton without knowing CUDA? Yes, and many people do. You'll tune it better if you understand what the compiler is doing underneath.
#Go deeper
The GPU Kernels for Inference course follows exactly this order: six CUDA lessons (coalescing, tiling, occupancy, reductions, tensor cores, CUDA graphs), four Triton lessons (the programming model, an autotuned matmul, fused RMSNorm and SwiGLU registered with PyTorch, and a paged decode-attention kernel), then Nsight profiling and a capstone. Every lab runs on a free Colab T4, and the first two lessons are free.
cudatritonkernelsgpucareersinference-engineering
Found this useful?
Send it to someone who is learning the same thing.
Next: learn it step by step, free
The CUDA programming model
Threads, blocks, warps and memory: the model every inference kernel is written against. A free lesson with step-through diagrams and a quiz.