Log inStart free
LESSON 27.19 · 5 STAGES · 2 CONTROLS · 2 CHECKSPRO · PREVIEW

Fused elementwise kernels: SiLU, SwiGLU and RoPE

Watch RoPE and SwiGLU run as many small kernels, then as two fused kernels.


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

Go Pro · $8.25/mo
EXPLAINER · 27.19 · FUSION BAYFUSED · 0 KERNELS · HBM 0 B
01
Stage 1 of 5 · Inputs in HBM
The GEMMs left q, k, g and u in HBM as FP16. An elementwise kernel does only a few FLOPs per value.
Explain it simply

At the bottom is HBM, the big main memory of the GPU. The token's query q and key k hold 8 values each. The gate g and the up value u hold 16 each. Each value needs only a few math steps, so moving it costs more time than its math.

HBM holds q and k, 8 values each, the cos and sin tables, and g and u, 16 values each. The register blocks above are empty.

inputs, values in registerscos and sin, anglesresultstemporaries, extra HBM tripsempty or not stored
qkcossintempsq′k′guah0 kernels runread 0 valueswrote 0 values0 B moved0 FLOPsrope: 1 fused kernelhead 1head 2qksilu_and_mul: 1 fused kernelgsiluuhHBMFP16SMregistersinputs in HBMqkcossintempsq′k′guah0 kernels runread 0 valueswrote 0 values0 B moved0 FLOPsrope: 1 fused kernelhead 1head 2qksilu_and_mul: 1 fused kernelgsiluuhHBMFP16SMregistersinputs in HBM
Toy: the 27.C3 decode token; q and k have 8 values, g and u have 16
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
I=FLOPsbytes\sy{i}{ink}{I} = \frac{\text{FLOPs}}{\text{bytes}}
I=128176≈0.73 FLOP/B≪295I = \frac{128}{176} \approx 0.73\ \text{FLOP/B} \ll 295

Intensity is the math done for each byte moved.

Common mix-ups

MYTHFusion is faster because it does less math.

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

Predict, then reveal
2 CHECKS · PRO
Q01With unfused kernels, how many kernels does RoPE run for q and k?

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

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 2 live controls
  • 2 mix-up cards and 2 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.