liveBook · Manning

__launch_bounds__

As explained in Grokking GPU Programming

__launch_bounds__ is an NVIDIA-specific CUDA compiler attribute that specifies a kernel's maximum threads per block and optionally a minimum number of blocks per multiprocessor.

__launch_bounds__ is an NVIDIA-specific CUDA compiler attribute for setting a kernel’s maximum threads per block and optionally guiding the compiler toward a minimum number of resident blocks per multiprocessor. The second value guides register budgeting; it does not reserve space or guarantee those blocks will fit. section 14.7

A stronger occupancy target can squeeze registers per thread and cause spilling to slow local memory. Treat the attribute as one tuning option, then measure performance: maximum occupancy is not necessarily fastest. section 14.11 section 14.7

__global__ void __launch_bounds__(256, 2)    #A
myKernel(float* data, int n) {    #B
}

This declaration shows the attribute placed between the kernel qualifier and its name, with a 256-thread limit and a target of two blocks per multiprocessor. section 14.7

Compare register budgets

A target of two blocks with 256 threads each may lead the compiler to budget 32 registers per thread; if that causes spilling, a less aggressive target may run faster. Profile both configurations rather than assuming higher occupancy wins. section 14.11 section 14.8

How Grokking GPU Programming covers it

How deep it goes
Explains attribute placement, its register-budget effect, and performance trade-offs without detailing compiler internals.
Examples
Compares launch bounds of (256, 2) and (256, 8), including register limits and possible spilling.
What it assumes
Assumes familiarity with CUDA kernel launches and multiprocessors while explaining the attribute’s role in register budgeting.
What you can do after
Evaluate launch-bound configurations by measuring runtime instead of maximizing occupancy by assumption.
How it connects
Connects occupancy to registers, block size, shared memory, and kernel performance.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking GPU Programming. The section links point to the parts of the book it draws on.