Log inStart free
LESSON 27.08 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Kernel fusion

Watch neighbour GPU ops join into one kernel and skip trips to memory.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 27.08 · FUSION BAY12 OPS · 12 KERNELS
01
Stage 1 of 5 · Op per kernel
The decode step runs 12 ops. Each op is its own GPU kernel, with its own launch.
Explain it simply

You see the 12 ops of one decoder layer, from left to right. Each teal outline is one kernel. A kernel can pass its result on only through HBM, the big main memory of the GPU.

A row of 12 op boxes, each inside its own kernel outline. Faint curves under them go down to the HBM band.

kernel, tensor tripremoved, unfusedCPU launchstart coststep time
HBM (GPU main memory)1norm2QKV3RoPE4KV5attn6out7add8norm9gate-up10SiLU11down12addops of one decode step12 ops → 12 kernels · each kernel t = 1 µs + max(bytes ÷ BW, FLOPs ÷ peak)HBM (GPU main memory)1norm2QKV3RoPE4KV5attn6out7add8norm9gate-up10SiLU11down12addops of one decode step12 ops → 12 kernels · each kernel t = 1 µs + max(bytes ÷ BW, FLOPs ÷ peak)
Toy: one decode step, 12 ops, a 1 TB/s GPU
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
ti=1 μs+max⁡ ⁣(bytesiBW,FLOPsipeak)\sy{t}{data}{t_i} = 1\,\mu s + \max\!\left(\tfrac{\text{bytes}_i}{BW}, \tfrac{\text{FLOPs}_i}{\text{peak}}\right)
t2=1+max⁡(6.30,0.06)=7.30 μst_2 = 1 + \max(6.30, 0.06) = 7.30\ \mu s

Each kernel costs a 1 µs start plus its memory or math time.

Common mix-ups

MYTHFusion makes every kernel faster.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With 10 µs launches at batch 1, does fusing into matmuls save more or less than with 5 µs launches?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.