pub fn optimal_block_size<F>(
registers_per_thread: u32,
shared_mem_per_block: F,
limits: &SmResourceLimits,
) -> Result<(u32, OccupancyResult), GpuOptimError>Expand description
Search for the block size that maximises occupancy (à la
cudaOccupancyMaxPotentialBlockSize).
Candidate block sizes are every multiple of limits.warp_size from
warp_size up to and including limits.max_threads_per_block. The usage
model is intentionally simple and documented:
registers_per_threadis a constant independent of block size (the usual assumption — register usage is a property of the compiled kernel).shared_mem_per_blockis a closureblock_size -> bytes, which covers both a constant footprint (|_| BYTES) and block-size-dependent allocations such as a reduction kernel’s|threads| threads as usize * size_of::<f32>().
Returns the (block_size, occupancy_result) with the highest occupancy.
Ties are broken toward the larger block size (i.e. fewer resident blocks),
matching the CUDA runtime’s preference.