core24 min studyLesson 453 in Engineering

SM residency: account for every binding resource

Calculate an explicit hypothetical residency bound using effective allocated registers, shared memory, threads, and block limits.

On this page

What you’ll understand

  • Identify the minimum of independent SM residency limits.
  • Explain allocation granularity and why raw per-thread counts can mislead.
  • Use documented device queries and occupancy APIs rather than universal constants.

A kernel can launch many blocks while only a few reside on each streaming multiprocessor at once. Registers, shared memory, threads, warps, and architectural block limits constrain that residency. The binding resource can change abruptly when a small source change crosses an allocation boundary. This lesson uses explicitly hypothetical budgets after allocation rounding; it does not assign one configuration to every NVIDIA GPU or equate a resource bound with measured throughput.

Blocks reserve several finite resources together

A block consumes some effective register allocation, some shared memory, and a number of thread and warp slots. Several blocks fit only when all required capacities remain within limits. If registers allow four blocks and shared memory allows two, the useful residency bound is two, not their average or sum. A zero-sized allocation does not create a meaningful divide-by-zero bound; treat that resource as nonbinding instead. Other architecture-specific constraints can make a simplified bound optimistic.

Registers are allocated at architecture-dependent granularities, often involving warp or block allocation units. Multiplying a compiler-reported register count by active threads is therefore not always the final reserved amount. Shared-memory alignment, carveout configuration, dynamic shared memory, kernel attributes, and maximum block dimensions also matter. Query the actual device and kernel, inspect compiler resource reports, and use the occupancy API for the selected configuration. A number copied from an old tuning example is not an implementation-independent limit.

Bresident≤min⁡(Bmax⁡,⌊RSMRblock⌋,⌊SSMSblock⌋,⌊TSMTblock⌋)B_{\rm resident}\leq\min\left(B_{\max},\left\lfloor\frac{R_{\rm SM}}{R_{\rm block}}\right\rfloor,\left\lfloor\frac{S_{\rm SM}}{S_{\rm block}}\right\rfloor,\left\lfloor\frac{T_{\rm SM}}{T_{\rm block}}\right\rfloor\right)
B values count blocks, R values count effectively allocated register slots, S values are shared-memory bytes, and T values count thread slots. Nonzero block allocations and matching scope are assumed; warp and other device-specific limits may impose additional bounds.↔ Scroll wide equations horizontally.

A residency cliff does not identify the best kernel

Reducing registers can allow another block to reside, but forcing a low register cap can spill values into local memory and increase memory traffic. Increasing shared-memory reuse can reduce global loads while limiting resident blocks. Larger blocks can share work efficiently yet waste lanes on a tail or constrain scheduling. These are tradeoffs rather than rules that every kernel should maximize one resource ratio. Compile and measure the complete kernel after a proposed resource change.

A kernel may also fail to launch if the requested per-block resources exceed supported limits. A valid launch with lower residency is different from an invalid resource request. Static resource estimates do not establish which resident warps are ready or whether another workload competes for the device. Keep launch validity, theoretical occupancy, achieved occupancy, and useful throughput in separate reports. When tuning, identify whether a change affected resource allocation, executed work, or the measured application’s critical path.

Wresident=Bresident⌈Tblock32⌉W_{\rm resident}=B_{\rm resident}\left\lceil\frac{T_{\rm block}}{32}\right\rceil
This counts NVIDIA resident warp groups in the simplified equal-block model. It assumes the selected residency is feasible after all limits and allocation rounding; the result is a count, not cycles or operations per second.↔ Scroll wide equations horizontally.

Read limits with the architecture and build attached

Record GPU model and compute capability, CUDA/compiler version, block dimensions, registers, static and dynamic shared memory, and relevant kernel attributes. Repeat resource inspection after changing compiler flags, templates, or inlining because generated code can change. A single occupancy API result is useful configuration evidence, but it does not validate out-of-bounds accesses or barriers. Test correctness before interpreting performance, and distinguish total application allocations in device memory from per-SM shared-memory or register limits.

The reliability lab offers a small arithmetic analogy for finite capacity. Reset, set n=8 and k=3, predict five available items, then Step. The model actually counts available replicas and a majority threshold; it does not allocate registers, model SM blocks, or calculate occupancy. Use only its explicit available-count readout to separate total capacity from unavailable capacity. The real residency calculation below uses its own resource units and minimum rule rather than the lab’s unrelated majority condition.

Find the binding hypothetical budget

A fictional SM provides 65,536 effective register slots, 65,536 shared-memory bytes, 2,048 thread slots, and at most 16 blocks. Each 256-thread block reserves 16,384 register slots and 16,384 shared-memory bytes after all rounding. Assume no tighter warp or other limit.

  1. The register budget allows 65,536/16,384=4 blocks. Shared memory also allows four. Thread capacity allows 2,048/256=8 blocks, and the explicit block-count limit allows 16.

  2. Take the minimum: at most four blocks reside under the declared assumptions. Each block has eight warp groups, so four blocks contain 32 resident warps and 1,024 resident threads.

  3. If shared-memory allocation rises to 32,768 bytes per block while other allocations stay fixed, it permits only two blocks. That reduces this bound to 16 resident warps, but whether runtime improves or worsens depends on what the additional shared memory accomplishes.

The result

The simultaneous resource constraints bind at four blocks initially and two after the shared-memory change. These synthetic capacities are not a device specification.

Explore the model

Interactive lab

Interactive lab · reliability

Distinguish total and available capacity

Reset, set n=8 and k=3, predict five available replicas, then Step. This lab counts replica availability and a majority only; it does not allocate SM resources or compute GPU occupancy. Use the available-count analogy, not the majority rule, for this lesson.

Distinguish total and available capacityA replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Current readings: Available replicas: 4 of 5; Majority needed: 3; Majority available?: Yes. All parameters are adjustable with the labeled controls below.Majority available · need 3 of 5Playback highlights fixed statesR1 · upR2 · upR3 · upR4 · upR5 · downCyan mark: majority threshold
AvailableUnavailableMajority threshold
Available replicas
4 of 5
Majority needed
3
Majority available?
Yes
t = 0 s

A replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forCapacity arithmetic requires matching units and the actual resource-allocation rule.

Check your understanding

A kernel uses fewer source-level variables after an edit. What can be concluded about resident blocks?

Try it yourself

A hypothetical SM has 48 KiB shared memory and 1,536 thread slots. Blocks use 12 KiB effective shared memory and 256 threads. Assume other limits allow at least six blocks. What bound do these two resources impose?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Use binary KiB consistently and take the minimum of per-resource block counts.

Compare with the solution

Shared memory permits 48/12=4 blocks; threads permit 1,536/256=6. These two resources therefore bound residency at four blocks, or 32 NVIDIA warp groups. The conclusion assumes effective post-rounding allocations and no tighter omitted resource limit.

Take it with you

  • Residency is constrained by the smallest applicable resource bound.
  • Effective allocation includes architecture-dependent rounding and configuration.
  • A higher residency bound is not automatically a faster or correct kernel.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.