Log inStart free
LESSON 26.C2 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

One kernel on the GPU, end to end

Follow one blur kernel on a toy GPU, from launch to last pixel.


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 · 26.C2 · GPU BAY9 BLOCKS · 288 THREADS · 48 IDLE
01
Stage 1 of 6 · The launch
The grid rounds up to 3 × 3 blocks of 8 × 4 (26.05). 48 threads stay idle.
Explain it simply

Each GPU thread blurs one pixel. All blocks have the same shape, so the grid of blocks can reach past the image. The 48 extra threads check the bounds and stop. Every 32 threads of a block form a warp, a team that runs each step together.

The 20 by 12 image is covered by 3 by 3 blocks of 8 by 4 threads. 48 idle threads are dashed. The traced warp has 32 threads.

pixels, busy lanesblocks, SMs, sectors, cachesidle threads, masked lanes, unused bytes, waitsempty lanestraced warp, its reads, results
0,01,02,00,11,12,10,21,22,2x = 20gridDim = (⌈20 / 8⌉, ⌈12 / 4⌉) = (3, 3)9 blocks × 32 threads = 288 threadsthe traced pixel (2, 1): block (0, 0) warp 0, lane 10the traced warp: 32 lanes04812162024289 blocks of 8 × 4 = 32 threads, 1 warp each9 warps × 32 lanes = 288 lanes240 threads with a pixel · 48 idle · 0 empty lanesevery lane of the launch240 threads with a pixel48 idle threads (past the image)0 empty lanes (no thread)the launch: 20 × 12 image, blocks of 8 × 4from 26.05 The CUDA thread hierarchy0,01,02,00,11,12,10,21,22,2x = 20gridDim = (⌈20 / 8⌉, ⌈12 / 4⌉) = (3, 3)9 blocks × 32 threads = 288 threadsthe traced pixel (2, 1): block (0, 0) warp 0, lane 10the traced warp: 32 lanes04812162024289 blocks of 8 × 4 = 32 threads, 1 warp each9 warps × 32 lanes = 288 lanes240 threads with a pixel · 48 idle · 0 empty lanesevery lane of the launch240 threads with a pixel48 idle threads (past the image)0 empty lanes (no thread)the launch: 20 × 12 image, blocks of 8 × 4from 26.05 The CUDA thread hierarchy
Toy: 26.C2 · a 20 × 12 image · 3 × 3 blur · 2 SMs · toy step counts and latencies
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
gridDim=(⌈Wbx⌉,⌈Hby⌉)\sy{g}{param}{\text{gridDim}} = \left(\left\lceil \tfrac{W}{\sy{b}{param}{b_x}} \right\rceil, \left\lceil \tfrac{H}{\sy{b}{param}{b_y}} \right\rceil\right)
gridDim=(⌈20/8⌉,⌈12/4⌉)=(3,3)\text{gridDim} = (\lceil 20/8 \rceil, \lceil 12/4 \rceil) = (3, 3)

The grid holds enough whole blocks to cover the image.

Common mix-ups

MYTHPadding the image makes the whole blur faster.

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

Predict, then reveal
3 CHECKS · PRO
Q01If every thread clamps, does the launch take more cycles than with the branch, or fewer?

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.