Master the fundamental concepts of gpu architecture through this focused micro-challenge.
Occupancy is the ratio of active warps on an SM to the maximum warps the SM can hold. Higher occupancy means more warps are available to hide memory latency, but it is not the only performance metric. A kernel with 100% occupancy can still be slow if every thread does redundant work.
The formula is straightforward:
cLoading…
For example, if an SM supports 48 warps and your kernel places 24 warps on it, occupancy is 50%.
Three resources compete to determine how many thread blocks fit on one SM:
registers_per_thread * threads_per_blockthreads_per_block / 32, capped by max warps per SMIf a kernel uses 128 registers per thread with 512 threads per block, register demand alone may allow only one block on a 64K-register SM. Shared memory can be the bottleneck too: four blocks at 24KB each fill a 96KB pool even when registers are plentiful.
You will read registers_per_thread, shared_memory_per_block, and threads_per_block from stdin and compute occupancy, identifying whether registers, shared memory, or warps is the limiting factor. This task asks you to test three configurations and explain whether higher occupancy would help. The calculator you build mirrors what nvcc --ptxas-options=-v reports when CUDA authors debug register pressure.
Write a C program that calculates GPU occupancy given kernel resource constraints.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github