TensorTonic
Study Plans
Study Plan
GPU Occupancy Calculator
GPU Programming
Medium

Calculate how many identical thread blocks fit on one streaming multiprocessor (SM) under the supplied resource limits. Let TTT be threads per block, WWW be warp size, and www be allocated warps per block:

w=⌈TW⌉.w=\left\lceil\frac{T}{W}\right\rceil.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 bbb is the maximum number of resident blocks and Wmax⁡W_{\max}Wmax​ is max_warps_per_sm, compute

resident_warps⁡=bw.\operatorname{resident\_warps}=bw.resident_warps=bw. occupancy⁡=bwWmax⁡.\operatorname{occupancy}=\frac{bw}{W_{\max}}.occupancy=Wmax​bw​.

Return a dictionary containing blocks_per_sm and resident_warps as Python integers, and occupancy as a Python float.

Loading visualization...

Examples

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}

Hint 1

divmod gives both the whole-warp count and the leftover threads.

Hint 2

Integer floor division counts how many whole blocks fit in a resource budget.

Requirements

  • Use Python integer arithmetic for resource counts; NumPy and GPU execution are not required.
  • A partially filled warp consumes a complete warp's thread and register capacity.
  • All resident blocks must fit within every supplied SM resource limit.

Constraints

  • All arguments are Python integers.
  • threads_per_block, warp_size, and every per-SM hardware limit are positive.
  • registers_per_thread and shared_mem_per_block are nonnegative.
  • A block may exceed an SM limit, in which case zero blocks, zero warps, and zero occupancy are valid.
  • Input values are at most 10,000,000.
Try Similar Problems
Shared-Memory Bank Conflict AnalyzerEasyGlobal-Memory Coalescing CounterEasyMeasure Kernel Timeline UtilizationMediumTrain a BPE Tokenizer From Scratch in PythonMediumCanonicalize Pairwise Preference DataMediumCompute Temperature-Based Data MixturesMediumApply Ranked BPE MergesMediumParallel and Recurrent Linear AttentionMediumImplement Per-Channel Weight QuantizationMediumAnalyze Prefill and Decode with the Roofline ModelMediumImplement Group-Wise INT4 QuantizationHardImplement Block-Wise FP8 QuantizationHard

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.

GPU Occupancy Calculator

GPU Programming
Medium

Calculate how many identical thread blocks fit on one streaming multiprocessor (SM) under the supplied resource limits. Let TTT be threads per block, WWW be warp size, and www be allocated warps per block:

w=⌈TW⌉.w=\left\lceil\frac{T}{W}\right\rceil.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 bbb is the maximum number of resident blocks and Wmax⁡W_{\max}Wmax​ is max_warps_per_sm, compute

resident_warps⁡=bw.\operatorname{resident\_warps}=bw.resident_warps=bw. occupancy⁡=bwWmax⁡.\operatorname{occupancy}=\frac{bw}{W_{\max}}.occupancy=Wmax​bw​.

Return a dictionary containing blocks_per_sm and resident_warps as Python integers, and occupancy as a Python float.

Loading visualization...

Examples

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}

Hint 1

divmod gives both the whole-warp count and the leftover threads.

Hint 2

Integer floor division counts how many whole blocks fit in a resource budget.

Requirements

  • Use Python integer arithmetic for resource counts; NumPy and GPU execution are not required.
  • A partially filled warp consumes a complete warp's thread and register capacity.
  • All resident blocks must fit within every supplied SM resource limit.

Constraints

  • All arguments are Python integers.
  • threads_per_block, warp_size, and every per-SM hardware limit are positive.
  • registers_per_thread and shared_mem_per_block are nonnegative.
  • A block may exceed an SM limit, in which case zero blocks, zero warps, and zero occupancy are valid.
  • Input values are at most 10,000,000.
Try Similar Problems
Shared-Memory Bank Conflict AnalyzerEasyGlobal-Memory Coalescing CounterEasyMeasure Kernel Timeline UtilizationMediumTrain a BPE Tokenizer From Scratch in PythonMediumCanonicalize Pairwise Preference DataMediumCompute Temperature-Based Data MixturesMediumApply Ranked BPE MergesMediumParallel and Recurrent Linear AttentionMediumImplement Per-Channel Weight QuantizationMediumAnalyze Prefill and Decode with the Roofline ModelMediumImplement Group-Wise INT4 QuantizationHardImplement Block-Wise FP8 QuantizationHard

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

Accepts: number

You must run your code first.