Log inStart free
LESSON 27.17 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

A fused softmax kernel

Watch softmax run as five GPU kernels, then as one fused kernel.


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

Go Pro · $8.25/mo
EXPLAINER · 27.17 · SOFTMAX BAYFUSED · 0 KERNELS · HBM 0 B
01
Stage 1 of 6 · Scores in HBM
The decode token has 2 heads. Each head stores 8 attention scores in HBM as FP16.
Explain it simply

At the bottom is HBM, the big main memory of the GPU. The new token has two heads, and each head has 8 scores, one per position. Softmax must turn each row into probabilities. Above sit the registers of one SM, where a kernel does its math.

HBM holds two rows of 8 scores. The largest score is 1.82 in head 1 and 3.48 in head 2. The register lanes are empty.

scores, partial resultsprobabilitiesextra HBM trips, overflowempty or not stored
SmzelP0 kernels runread 0 valueswrote 0 values0 B movedhead 1 · waitinghead 2 · waitingscores in HBMHBMFP16SMregisterss = q · k / √4 · 2 rows of 8 scores · 32 B in HBMSmzelP0 kernels runread 0 valueswrote 0 values0 B movedhead 1 · waitinghead 2 · waitingscores in HBMHBMFP16SMregisterss = q · k / √4 · 2 rows of 8 scores · 32 B in HBM
Toy: 2 heads × 8 positions; 8 lanes per block (a warp has 32)
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
sj=q⋅kj4\sy{s}{data}{s_j} = \frac{q \cdot k_j}{\sqrt{4}}
s1,5=1.82,  s2,7=3.48s_{1,5} = 1.82,\; s_{2,7} = 3.48

Each score is the query times one key, over the root of 4.

Common mix-ups

MYTHFusion makes softmax faster by doing less math.

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

Predict, then reveal
3 CHECKS · PRO
Q01With the max shift on, how many times more HBM bytes do the unfused kernels move?

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

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 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.