Log inStart free
LESSON 27.C1 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Removing overhead from a decode step

Watch three fixes shorten a decode loop on one time axis.


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.C1 · OVERHEAD BAY89.0 µs PER TOKEN · GPU BUSY 39%
01
Stage 1 of 5 · Eager loop
Each token needs 13 CUDA calls and 20 µs of host work. Launch waits and turns leave the GPU idle 61%.
Explain it simply

The CPU launches 12 kernels one by one, then asks to copy the new tokens back. The GPU works while the CPU launches. But the host work waits for the GPU to finish, so those two never overlap. Each token takes 89.0 µs.

Eager loop of 3 tokens: 267.0 µs, 89.0 µs per token. The GPU is busy 39% of the time.

kernelCUDA call, host work1 µs startGPU idle (brick), CPU wait (grey box), run before the fix (grey line)copy, token, end
hosthosthost123kernels 105.5 µs (39%)GPU idle 161.5 µs (61%)CPUstream 1stream 2tokens050100150200250300time (µs)3 tokens: 267.0 µseager loop: 12 launches per step (27.03)CPU per step: 13 calls × 5 µs + 20 µs host = 85.0 µsGPU per step: 12 kernels, 35.2 µshosthosthost123kernels 105.5 µs (39%)GPU idle 161.5 µs (61%)CPUstream 1stream 2tokens050100150200250300time (µs)3 tokens: 267.0 µseager loop: 12 launches per step (27.03)CPU per step: 13 calls × 5 µs + 20 µs host = 85.0 µsGPU per step: 12 kernels, 35.2 µs
Toy: 3 tokens, 12 kernels per step, a 1 TB/s GPU
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
C=n L+h\sy{c}{param}{C} = n\,\sy{l}{param}{L} + h
C=13⋅5+20=85.0 μsC = 13 \cdot 5 + 20 = 85.0\,\mu s

CPU time per step is the calls times their cost, plus host work.

Common mix-ups

MYTHEach fix saves the same time in any order.

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

Predict, then reveal
3 CHECKS · PRO
Q01With 2 µs launches at batch 1, does a CUDA graph added first save more or less than 5 µs?

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.