6.2.5 · D3GPU Architecture

Worked examples — Warps and warp scheduling

4,009 words18 min readBack to topic

This is the "roll up your sleeves" page for the parent topic. We will not re-teach the theory — instead we hunt down every kind of situation the parent note can throw at you and work each one to a number. If a term feels unfamiliar, the parent note built it; here we use it.

Before anything else, one plain-language recap of the three numbers we keep reusing, because every example below is built from them:

Recall The three quantities every example uses
  • Warp size ::: 32 threads (fixed on NVIDIA hardware). A warp is one bundle of 32 threads that share one instruction fetch.
  • Linear thread index ::: flatten a 3D (x,y,z) thread coordinate into a single counting number, x fastest.
  • Warp ID ::: that linear index divided by 32, rounded down. So threads 0–31 → warp 0, 32–63 → warp 1, and so on.

The scenario matrix

Think of this table as a checklist. Every cell is a class of problem. Below it, each worked example is stamped with the cell(s) it clears. By the end, no cell is left uncovered — you will never meet a warp scenario on an exam that we skipped.

# Case class What makes it tricky Covered by
A Clean 1D block, multiple of 32 The "no waste" baseline Ex 1
B Block not a multiple of 32 Partial (wasted) warp at the tail Ex 2
C 2D block, row-major flatten Warps cut across rows Ex 3
C2 True 3D block, non-unit depth The term actually fires Ex 3b
D Degenerate: block smaller than 32 One warp, mostly idle lanes Ex 4
E Latency hiding — enough warps? Need warps Ex 5
F Limiting case: zero compute between loads No hiding possible — memory bound Ex 6
G Warp divergence, both branches taken Serialized paths, slowdown factor Ex 7
H Divergence edge: all threads same branch Zero penalty (no real divergence) Ex 8
I Real-world word problem Choose block dims to avoid waste Ex 9
J Exam twist: occupancy vs. warps-needed Hardware cap beats the ideal number Ex 10

Group 1 — Where do threads land? (cells A, B, C, C2, D)

The single formula behind all four:

Recall Total threads vs. total warps — the rounding rule made precise

Let be the total thread count. Two facts must never be confused:

  • The largest warp ID is (floor of the last linear index, which is since indices count from 0). Warp IDs run .
  • The number of warps is therefore , and this equals (ceiling of the total).

Why do these two agree? Write , where is the whole number of complete groups of 32 and is the remainder (). Two cases:

  • If : the block is an exact multiple of 32. The last index is , so , giving warps. And . Same.
  • If : the last index is with , so , giving warps. And (round the fraction up). Same.

So in both cases they land on the identical value — that is why "floor the last index, then add one" (which tells you the top warp's ID) equals "ceil the total" (which tells you how many warps exist).

One-line takeaway ::: for every positive integer , because splitting makes both sides equal (if ) or (if ).

Example 1 — Cell A: clean 1D block

Example 2 — Cell B: not a multiple of 32

Example 3 — Cell C: 2D block, warps cut across rows

Example 3b — Cell C2: a true 3D block (depth actually matters)

Example 4 — Cell D (degenerate): block smaller than a warp


Group 2 — Will the scheduler stay busy? (cells E, F, J)

Recall the parent's latency-hiding count. In plain words: while one warp waits cycles for memory, the scheduler runs other warps. If a warp does useful instructions between memory requests, you need enough warps so that "everyone else's work" fills the wait.

Example 5 — Cell E: enough warps to hide latency

Example 6 — Cell F (limiting case): zero compute between loads

Example 10 — Cell J (exam twist): ideal warps vs. hardware cap

First, the scheduler-level formula this example leans on. The parent note runs the count per scheduler, so we must name its symbols before using them:


Group 3 — Divergence cost (cells G, H)

When threads in one warp disagree about which branch to take, the warp runs both branches one after the other, masking off the lanes that shouldn't participate each time. See Branch-Divergence-Patterns for pattern-level tricks.

Example 7 — Cell G: both branches populated

Example 8 — Cell H (edge case): all threads agree


Group 4 — The word problem (cell I)

Example 9 — Cell I: choosing block dims for an image kernel


Recall Quick self-test

A (72,1,1) block: how many warps and how many wasted lanes? ::: warps; tail warp holds active → 24 wasted lanes. A (8,4,3) block: how many warps? ::: warps (one per z-slice, since each slice is exactly 32 threads). , : warps needed to hide? ::: warps. 16 lanes take if (cost 40), 16 take else (cost 40): slowdown? ::: .