6.2.10 · D4GPU Architecture

Exercises — Occupancy and latency hiding

2,670 words12 min readBack to topic

Before we begin, one reminder of the one formula everything rests on. If you have never met it, read it slowly:

See the picture of the barrel-limit idea:

Figure — Occupancy and latency hiding

Level 1 — Recognition

Recall Solution

WHAT: Occupancy is a ratio of active to maximum warps. WHY: That is literally its definition — no resource limits to hunt for here, we are handed the active-warp count directly. Answer: .

Recall Solution

Step 1 — warps per block. A warp is threads, so warps per block. WHY divide by 32: the hardware always groups threads into fixed lanes of ; that is the atom of scheduling. Step 2 — total active warps. warps. Step 3 — occupancy. . Answer: warps/block, occupancy.


Level 2 — Application

Recall Solution

Step 1 — registers per warp. Each warp has threads, so it consumes registers. WHY multiply by 32: every one of the lanes needs its own private copy of each register; a warp's cost is the per-thread cost times . Step 2 — how many such warps fit. WHY the floor : you cannot host a fractional warp — leftover registers that can't cover a full warp are simply wasted. Step 3 — occupancy. With no other limit, . Answer: warps, .

Recall Solution

We must check each resource and take the minimum. Register limit: Shared-memory limit: how many KB blocks fit in KB? Block-count limit: blocks is well under the -block max, so not binding. Step — take the minimum: . Answer: shared memory is the bottleneck; .

Recall Solution

WHY this tool: Little's Law answers exactly "how much must be in flight to keep a pipe full given a latency and a rate". That is precisely our question — we are not shrinking latency, we are overlapping it. Answer: (single-scheduler idealisation). The parent note explains why real SMs need only warps: schedulers plus instruction-level parallelism supply the concurrency SM-wide.


Level 3 — Analysis

Recall Solution

(a) warps . (b) warps . (c) WHY 128 can still win: if the kernel is memory-bound, warps may already hide the load latency (recall warps usually suffice SM-wide). Meanwhile keeping data in registers avoids spills to local memory that cost hundreds of cycles each. So with no spills can beat with spills. Answer: (a) ; (b) ; (c) memory-bound kernels where the extra registers prevent spilling.

Recall Solution

WHY divide by loads-per-warp: each warp now contributes outstanding requests, so it does the work of toward filling the -cycle gap. WHY the real number is far lower: the A100 has schedulers issuing from different warps in consecutive cycles, and the memory system services many requests in parallel (memory-level parallelism). Divide the idealised figure by the effective SM-wide issue width and you land in the empirical warp range. Answer: idealised; in practice warps due to schedulers + MLP.

Recall Solution

WHAT limits each: A's ceiling is registers; B's ceiling is shared memory. The binding constraint is the only one worth relaxing (barrel plank logic). Kernel A: cutting register use raises , directly lifting the minimum → occupancy rises. Kernel B: more registers do nothing — shared memory is still the shortest plank; you'd raise a non-binding limit. Answer: Kernel A benefits. For B you must cut shared-memory usage instead (e.g. smaller tiles).


Level 4 — Synthesis

Recall Solution

(a) Check each limit.

  • Registers: warps.
  • Shared mem: blocks warps.
  • Blocks: blocks max, so blocks give warps (not extra-binding).
  • . Binding constraint: shared memory (20 warps). (b) Change: halve shared memory to KB/block. Then blocks warps for smem; registers still allow ; block max allows . New minimum . WHY it stops at 25, not 40: once shared memory stops binding, registers become the new shortest plank at warps. Synthesis lesson: fixing one bottleneck exposes the next. Answer: (a) , shared-memory bound. (b) KB smem → , now register bound.
Recall Solution

WHY roofline: it tells us the ceiling a kernel can reach from its intensity — compute-bound above the ridge, memory-bound below. Step — ridge-point intensity (where the two ceilings meet): Our , so we are far below the ridge → memory-bound. (b) Implication: performance is set by feeding data, and moderate occupancy (, i.e. warps) already hides load latency. Pushing to gives diminishing returns; better to improve coalescing so each transaction moves useful bytes. Answer: (a) memory-bound (); (b) ~50% occupancy suffices — chase coalescing, not occupancy.


Level 5 — Mastery

Recall Solution

(a) Occupancy.

  • P: warps .
  • S: warps . (b) Which wins. Version S doubles occupancy — tempting. But it adds cycles of serial spill latency on the critical path of every thread, whereas P saves cycles by keeping data resident. Because the kernel is memory-bound, P's warps () already supply enough concurrency to hide the genuine load latency SM-wide. Extra warps in S hide nothing new but pay the spill tax. Decision: Version P is faster. Occupancy rose in S, yet per-thread critical-path latency exploded — and once latency is already hidden, more warps don't help. Answer: (a) P , S ; (b) P wins — spills add serial cycles that no amount of occupancy recovers here.
Recall Solution

Warp scheduling view: a scheduler picks a ready warp each cycle. A stalled warp (waiting on its load) is not ready, so if it is the only warp, the scheduler has nothing to issue → the SM idles. SM architecture view: context (registers) for many warps lives on-chip simultaneously, making a switch free — but only if other warps exist to switch to. One warp = nothing to switch to. Little's Law view: in-flight requests needed . A lone warp issues one load then must wait; it cannot keep cycles' worth of independent requests outstanding by itself, because its later instructions depend on that load's result. Rule of thumb: you need multiple independent warps — empirically on modern SMs — to keep the schedulers fed and the memory system busy while any one warp waits. Answer: latency hiding is inherently a between-warps mechanism; ILP within one warp is bounded by dependencies, so warps is the practical minimum.


Recall Quick self-test (cloze)

Occupancy active warps divided by maximum warps per SM. The occupancy formula takes the minimum of all resource limits. Registers are billed per warp as per-thread count times 32. A single warp cannot hide its own load latency because latency hiding is a between-warps mechanism.

What is the ridge-point intensity on the A100 (19.5 TFLOP/s, 1555 GB/s)?
About FLOP/byte
Why floor the warp counts?
You cannot host a fractional warp; leftover resource is wasted
For a memory-bound kernel below the roofline ridge, is 100% occupancy worth chasing?
No — ~50% already hides latency; fix coalescing instead