CPU, GPU AND RAM

Cooperative CUDA grids: a grid barrier needs a launch contract

In this article
THE QUICK TAKE

Grid synchronization requires a compatible cooperative launch and a resident grid; a homemade global spin barrier can deadlock ordinary kernels.

A block barrier cannot coordinate every block in a CUDA grid. Algorithms with a global phase boundary need a different execution structure. Cooperative launch and grid synchronization can express that boundary under specific residency constraints. Understanding those constraints prevents a common mistake: constructing a barrier that waits for blocks which have not yet been allowed to run.

Why a block barrier stops at the block

Threads in a block share a scheduling and synchronization contract. Independent blocks in an ordinary grid may execute in different waves. When an early wave occupies the device and spins waiting for every later block, those later blocks may have no resources to start. The algorithm has created a circular dependency between progress and residency. More aggressive polling cannot solve that structural problem.

Primary reference: CUDA Programming Guide: Cooperative Groups.

A cooperative launch makes a stronger promise

A supported cooperative launch allows the program to use a grid-wide cooperative group. The launch configuration must respect the device’s supported capability and the number of blocks that can participate with their resource requirements. Register and shared-memory consumption therefore influence more than performance. They affect whether the whole synchronization design can be launched legally. Query capabilities and calculate the supported configuration rather than guessing from thread count.

Primary reference: CUDA C++ Best Practices Guide.

A global iterative update as an example

Imagine an iterative solver where blocks produce partial updates and the next phase reads all completed updates. A grid barrier can separate those phases inside one cooperatively launched kernel. Every participating thread must reach compatible synchronization points. A branch that exits early because its tile is empty can violate that requirement. Empty tiles may still need inactive computational work but active participation in the barrier protocol.

Primary reference: Nsight Compute Profiling Guide.

Separate kernels are a useful baseline

The same solver can end one kernel and launch the next in a stream. This provides a clear global phase boundary without requiring the entire grid to remain resident together. It pays additional launch costs and may materialize intermediate state in device memory. Compare this simpler baseline with the cooperative design. A complex persistent kernel is justified by measured benefits, not by the disappearance of a launch statement.

Validate progress on the smallest case

Test synchronization with empty tiles, uneven work, and the largest intended cooperative grid before optimizing arithmetic. Instrument phase progress carefully, avoiding instrumentation that introduces another global wait. When changing block size or shared-memory allocation, revisit the residency calculation. A tuning change that improves a local kernel metric may invalidate the cooperative launch or reduce the amount of useful global work the kernel can express.

Related reading: A GPU inference benchmark you can trust; Reproducible inference stacks: preserving a GPU pilot’s result.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles