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

GPU reductions and warp shuffles

Watch a block of values become one sum, through shared memory and warp shuffles.


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.16 · WARP BAY64 THREADS · 2 WARPS · SUM 272
01
Stage 1 of 6 · One value each
A thread block of 64 threads holds one value per thread. A reduction combines all 64 values into one sum.
Explain it simply

Each small box is one thread's value, a digit from 0 to 9. The block has 64 threads in 2 warps of 32. You want one number from all of them: the sum. A reduction is any job like that, where many values become one.

Warp 0 shows 32 boxes, one per thread. 1 more warp shows below it.

thread valuesstride or offsetbarrier (all threads wait)partial and final resultslane not used
081624312704948244876999331130194297131210390880146935331507970780354740warp 1one blockwarp 0S = 2 + 7 + 0 + 4 + … = 272081624312704948244876999331130194297131210390880146935331507970780354740warp 1one blockwarp 0S = 2 + 7 + 0 + 4 + … = 272
Toy: one block of 32 to 128 threads, one seeded digit each
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
S=x0⊕x1⊕⋯⊕xB−1\sy{S}{out}{S} = \sy{x}{data}{x_0} \oplus \sy{x}{data}{x_1} \oplus \cdots \oplus \sy{x}{data}{x_{B-1}}
B=64,  ⊕=+,  S=272B = 64,\; \oplus = +,\; S = 272

The result combines every thread's value with one operation.

Common mix-ups

MYTHAfter a shuffle-down loop, every lane holds the sum.

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

Predict, then reveal
3 CHECKS · PRO
Q01With the xor shuffle, how many lanes of warp 0 end with the result?

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.