Stanford CS336 explains GPU kernels: data movement, not math, is what costs you

stanfordnlp · x · 2026-10-21

In Stanford's CS336 course, Percy Liang breaks down GPU kernels: every PyTorch primitive launches its own kernel, so gelu(x) 2 reads and writes memory twice. Fusing ops into one kernel halves memory traffic — the principle is to minimize data movement, since math is cheap. Key tricks: operator fusion and tiling (how FlashAttention avoids materializing the full attention matrix). Kernels can be written in CUDA, Triton, CUTLASS or ThunderKittens, or via torch.compile.

Related event: Stanford CS336 Lecture: GPU Kernel Optimization Centers on Memory(2 posts)→

Original post →

More from Infra

Infra channel →