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

The CUDA thread hierarchy

Watch one blur kernel split into threads, blocks, a grid and warps.


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.05 · GPU BAY240 PIXELS · 240 THREADS
01
Stage 1 of 5 · One thread each
The blur kernel needs one GPU thread per pixel: 240 threads. The thread for pixel (9, 6) writes the mean of 9 pixels.
Explain it simply

Each small square is one pixel of a grey image. The GPU starts one thread for every pixel, and they all run the same short program. The traced thread adds the 9 pixels in its box and divides by 9. That mean is its output pixel, on the right.

A grey image of 20 by 12 pixels, one thread per pixel. The thread for pixel (9, 6) averages 9 pixels to 195.1.

pixelsblocks, SMsidle threadsempty lanestraced thread
04812160246810the image: one thread per pixelthe traced threado(9, 6) = 1756 / 9 ≈ 195.1195216174198223204178190178mean195.1output (9, 6)9 input pixels around (9, 6)sum 1756 · 1756 / 9 ≈ 195.104812160246810the image: one thread per pixelthe traced threado(9, 6) = 1756 / 9 ≈ 195.1195216174198223204178190178mean195.1output (9, 6)9 input pixels around (9, 6)sum 1756 · 1756 / 9 ≈ 195.1
Toy: 26.C2 · a 20 × 12 image · 3 × 3 blur · 2 SMs
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
ox,y=19∑i,j=−11px+i, y+j\sy{o}{out}{o_{x,y}} = \tfrac{1}{9}\sum_{i,j=-1}^{1} \sy{p}{data}{p_{x+i,\,y+j}}
o9,6=17569≈195.1o_{9,6} = \tfrac{1756}{9} \approx 195.1

Each output pixel is the mean of the 3 × 3 pixels around it.

Common mix-ups

MYTHA block of 16 threads takes half a warp.

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

Predict, then reveal
3 CHECKS · PRO
Q01If the image is 16 pixels wide, how many threads stay idle with 8 × 4 blocks?

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.