Calculate how many identical thread blocks fit on one streaming multiprocessor (SM) under the supplied resource limits. Let T be threads per block, W be warp size, and w be allocated warps per block:
w=⌈WT⌉.Each block consumes w times W effective threads. Its register use is registers_per_thread times this effective thread count, and its shared-memory use is shared_mem_per_block bytes. All five per-SM limits must hold: threads, warps, blocks, registers, and shared memory. Zero register or shared-memory use does not constrain the block count. Use only this resource model, with no additional hardware allocation rounding; warp_size defaults to 32.
If b is the maximum number of resident blocks and Wmax is max_warps_per_sm, compute
resident_warps=bw. occupancy=Wmaxbw.Return a dictionary containing blocks_per_sm and resident_warps as Python integers, and occupancy as a Python float.
Input: threads_per_block = 100, registers_per_thread = 64, shared_mem_per_block = 2048, max_threads_per_sm = 1024, max_warps_per_sm = 32, max_blocks_per_sm = 16, max_registers_per_sm = 32768, max_shared_mem_per_sm = 49152, warp_size = 32
Output: {"blocks_per_sm":4,"resident_warps":16,"occupancy":0.5}
Explanation: One block occupies four warps and 128 effective threads. Registers limit the SM to four blocks, which gives 16 resident warps and 0.5 occupancy.
Input: threads_per_block = 256, registers_per_thread = 0, shared_mem_per_block = 16384, max_threads_per_sm = 2048, max_warps_per_sm = 64, max_blocks_per_sm = 32, max_registers_per_sm = 65536, max_shared_mem_per_sm = 49152, warp_size = 32
Output: {"blocks_per_sm":3,"resident_warps":24,"occupancy":0.375}
Input: threads_per_block = 2048, registers_per_thread = 32, shared_mem_per_block = 1024, max_threads_per_sm = 1536, max_warps_per_sm = 48, max_blocks_per_sm = 16, max_registers_per_sm = 65536, max_shared_mem_per_sm = 49152, warp_size = 32
Output: {"blocks_per_sm":0,"resident_warps":0,"occupancy":0}
divmod gives both the whole-warp count and the leftover threads.
Integer floor division counts how many whole blocks fit in a resource budget.
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Calculate how many identical thread blocks fit on one streaming multiprocessor (SM) under the supplied resource limits. Let T be threads per block, W be warp size, and w be allocated warps per block:
w=⌈WT⌉.Each block consumes w times W effective threads. Its register use is registers_per_thread times this effective thread count, and its shared-memory use is shared_mem_per_block bytes. All five per-SM limits must hold: threads, warps, blocks, registers, and shared memory. Zero register or shared-memory use does not constrain the block count. Use only this resource model, with no additional hardware allocation rounding; warp_size defaults to 32.
If b is the maximum number of resident blocks and Wmax is max_warps_per_sm, compute
resident_warps=bw. occupancy=Wmaxbw.Return a dictionary containing blocks_per_sm and resident_warps as Python integers, and occupancy as a Python float.
Input: threads_per_block = 100, registers_per_thread = 64, shared_mem_per_block = 2048, max_threads_per_sm = 1024, max_warps_per_sm = 32, max_blocks_per_sm = 16, max_registers_per_sm = 32768, max_shared_mem_per_sm = 49152, warp_size = 32
Output: {"blocks_per_sm":4,"resident_warps":16,"occupancy":0.5}
Explanation: One block occupies four warps and 128 effective threads. Registers limit the SM to four blocks, which gives 16 resident warps and 0.5 occupancy.
Input: threads_per_block = 256, registers_per_thread = 0, shared_mem_per_block = 16384, max_threads_per_sm = 2048, max_warps_per_sm = 64, max_blocks_per_sm = 32, max_registers_per_sm = 65536, max_shared_mem_per_sm = 49152, warp_size = 32
Output: {"blocks_per_sm":3,"resident_warps":24,"occupancy":0.375}
Input: threads_per_block = 2048, registers_per_thread = 32, shared_mem_per_block = 1024, max_threads_per_sm = 1536, max_warps_per_sm = 48, max_blocks_per_sm = 16, max_registers_per_sm = 65536, max_shared_mem_per_sm = 49152, warp_size = 32
Output: {"blocks_per_sm":0,"resident_warps":0,"occupancy":0}
divmod gives both the whole-warp count and the leftover threads.
Integer floor division counts how many whole blocks fit in a resource budget.
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number
Accepts: number