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

GPU synchronization

Watch 8 GPU threads add 8 numbers, with and without a barrier.


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 · 26.10 · SYNC BAY8 THREADS · WARP 3 2 CYCLES LATE
01
Stage 1 of 5 · Store to shared
Each thread writes its value x to shared memory. warp 3 starts 2 cycles late.
Explain it simply

You see 8 threads in 4 warps. A warp is a group of threads that run each step together. Each thread copies its number into shared memory, the fast memory that the block shares. Warp 3 waits for a slow load, so it starts 2 cycles late.

Eight threads store their values 4, 8, 9, 6, 5, 7, 2, 3 in shared memory. Warp 3 stores 2 cycles late.

stored valuessumsbarrierstalls, stale reads, lost addsno work, or never happens
cycle →012345678910late48965723one block · shared memory and timewarp 0warp 1warp 2warp 3t0t1t2t3t4t5t6t7storeround 1round 2round 3s[t] = x[t] · 8 threads, 4 warps of 2warp 3 starts 2 cycles latecycle →012345678910late48965723one block · shared memory and timewarp 0warp 1warp 2warp 3t0t1t2t3t4t5t6t7storeround 1round 2round 3s[t] = x[t] · 8 threads, 4 warps of 2warp 3 starts 2 cycles late
Toy: 1 block, 8 threads, warps of 2 (a real warp has 32)
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
st=xt\sy{s}{data}{s_t} = \sy{x}{data}{x_t}
s7=x7=3s_{7} = x_{7} = 3

Each thread t copies its value into slot t.

Common mix-ups

MYTHIf the sum comes out right, the code needs no barrier.

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

Predict, then reveal
3 CHECKS · PRO
Q01With no barriers, warp 1 is late instead of warp 3. Is the sum still 39?

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.