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

Async copies and double buffering

Watch tile copies slide under the math until the math stops waiting.


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.12 · GPU BAYCOPY 96 NS · MATH 64 NS
01
Stage 1 of 5 · One tile step
Each tile step copies 1,024 bytes into shared memory, then does 8,192 FLOPs. An asynchronous copy lets the threads go on.
Explain it simply

Each SM builds its part of C one tile at a time. An A tile and a B tile travel from HBM into shared memory, a small fast memory on the chip. The copy takes 96 nanoseconds: 32 of waiting, then 64 of bytes arriving. The math on the CUDA cores then takes 64 nanoseconds.

An A tile and a B tile move from HBM into a shared-memory buffer. The copy takes 96 ns, the math 64 ns.

weights Ainputs B, bytes arrivingcopy in flightoutputs C, mathmath waits
HBMshared memorymath unitsABCbuffer 0plain loop · 1 bufferbuffer 0math0 ns5001,0001,5002,0002,500one tile stepasync copyCUDA cores64 ns a stepstep 1: A tile (0, 0) · B tile (0, 0) → C tile (0, 0)1 KB of 16 KBcopy = 32 + 1,024 B ÷ 16 B/ns = 96 ns · math = 8,192 ÷ 128 = 64 nsHBMshared memorymath unitsABCbuffer 0plain loop · 1 bufferbuffer 0math0 ns5001,0001,5002,0002,500one tile stepasync copyCUDA cores64 ns a stepstep 1: A tile (0, 0) · B tile (0, 0) → C tile (0, 0)1 KB of 16 KBcopy = 32 + 1,024 B ÷ 16 B/ns = 96 ns · math = 8,192 ÷ 128 = 64 ns
Toy: the 64 × 64 matmul of 27.C2 in 16 × 16 tiles; one SM's 16 tile steps
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
tcopy=L+bytesbwtmath=FLOPspeak\sy{copy}{data}{t_{copy}} = \sy{lat}{param}{L} + \frac{\sy{bytes}{data}{bytes}}{\sy{bw}{param}{bw}} \qquad \sy{math}{out}{t_{math}} = \frac{\sy{flops}{out}{FLOPs}}{\sy{peak}{param}{peak}}
tcopy=32+102416=96 nstmath=8192128=64 nst_{copy} = 32 + \frac{1024}{16} = 96\text{ ns} \qquad t_{math} = \frac{8192}{128} = 64\text{ ns}

A copy waits the latency, then the bytes stream in.

Common mix-ups

MYTHAn asynchronous copy alone makes the loop faster.

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

Predict, then reveal
3 CHECKS · PRO
Q01With 1 buffer, a 32 ns latency and CUDA cores, what share of the time does the math wait?

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.