TECHNOLOGY

Pass the actual dynamic shared-memory size to the occupancy API

In this article
THE QUICK TAKE

Pass the launched function, block size and dynamic shared-memory bytes to occupancy calculations, then compare the estimate with actual work.

An occupancy calculation predicts more resident blocks than the kernel profile permits. The calculation used no dynamic shared memory, while the actual launch reserves a scratch tile. The API cannot recover that omitted launch argument from source code. Supply the same function, block size and dynamic allocation that the application actually launches before interpreting its estimate.

Identify the compiled function

Preserve the exact template specialization and loaded device target. Different variants can use different registers and static shared memory even when they implement the same operation. Query function attributes for that variant. A calculation performed on a convenient neighboring specialization does not describe the compiled resource requirements of the measured launch.

Pass dynamic bytes explicitly

cudaOccupancyMaxActiveBlocksPerMultiprocessor accepts the intended dynamic shared-memory usage per block in bytes. Use the application’s launch value, including any layout padding or multiple scratch regions. Static shared memory belongs to the compiled function and is a separate attribute; do not silently substitute static bytes for dynamic bytes or add them twice in the API argument.

Read the returned quantity

The result is a maximum active-block count per multiprocessor for the supplied configuration. It is not the number of blocks in the grid, achieved occupancy or a kernel-duration prediction. Preserve the API result and its return status together. A failed call does not produce a meaningful estimate merely because the output variable happens to retain an earlier value.

Reverse the question carefully

The available-dynamic-memory occupancy query answers how much dynamic storage can fit a requested resident-block count and block size. That is useful for a deliberate tile budget. It does not allocate memory, change the kernel’s function attributes or guarantee that an arbitrary layout uses that budget correctly. Keep the requested residency target with the returned allowance.

Compare the actual launch

Check the profiler’s launch resources against the calculation, then measure valid candidate layouts on identical data. If the corrected estimate now explains residency, investigate whether the extra storage earns its cost through reuse. A smaller allocation can fit more blocks while doing more global-memory work. Acceptance establishes a consistent resource model; useful throughput remains an experimental result.

Primary references

CUDA Runtime Occupancy API.

CUDA Runtime Execution Control.

CUDA Function Resource Attributes.

Related reading: GPU occupancy and register pressure: a coupled resource decision; Shared-memory bank conflicts: why padding can change access.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles