04.01

CUDA kernels, selection, and fusion

skillmaxingInference EngineeringCUDA kernels, selection, and fusion
Visual lesson

CUDA kernels, selection, and fusion

Included with Pro · 4:49
Lessons · 1,179 words

When Python code multiplies two tensors on a GPU, the GPU does not run Python. The CPU launches a kernel: a function compiled for the GPU that runs across thousands of threads at once, each handling one element or one block of the tensor. A forward pass through an LLM is a long sequence of these launches, one or more for every operation in the model.

What a kernel launch looks like
Figure 1What a kernel launch looks likeOne operation, one or more kernels. Each reads its input and writes its output.

Two decisions around each kernel set the speed. Selection is picking the best implementation of an operation for this GPU architecture, number format, and tensor shape. Fusion is replacing several small kernels, each of which reads its input from memory and writes its output back, with one kernel that does all the steps in a single pass. Since decode is memory-bound, and many small operations are too, fusion often matters more than raw arithmetic speed.

Pro

Continue reading

Pro unlocks every video lesson, the full notes, worked sizing and cost calculations, and runnable configs across the Inference Engineering course, from GPUs and kernels to quantization, speculative decoding, disaggregation and production autoscaling.

Unlock full access to
Python with AIInference EngineeringAI researchComplete system design
30% off with LAUNCH30first payment
Buy now
View all plans ·Already Pro? Sign in