CUDA Cooperative Groups: Choosing Group Scope and Synchronization
CUDA Cooperative Groups is a CUDA C++ interface for naming sets of threads that cooperate. A group handle makes the intended participants explicit: cooperation can cover a whole thread block, a fixed tile within it, or the warp threads active at a particular point. Every member must follow the group’s collective-call rules, and synchronizing an entire grid requires a special launch configuration.
CUDA Cooperative Groups: Choosing Group Scope and Synchronization
CUDA Cooperative Groups is a CUDA C++ interface for naming sets of threads that cooperate. A group handle makes the intended participants explicit: cooperation can cover a whole thread block, a fixed tile within it, or the warp threads active at a particular point. Every member must follow the group’s collective-call rules, and synchronizing an entire grid requires a special launch configuration.
This article is based on NVIDIA’s CUDA Programming Guide and CUDA Runtime API documentation reviewed on 2026-11-22. It covers thread blocks, tiles, coalesced groups, and single-GPU grid synchronization; thread-block clusters and distributed shared memory are outside its scope.
Why name a thread group in code?
CUDA provides __syncthreads(), a barrier for all threads in one thread block. But an algorithm may need only a tile of threads to cooperate, or may need the currently active lanes of a warp to work together. Hand-written warp or cross-block synchronization can hide which threads must participate, making code brittle when a helper is called from a different control-flow path.
Cooperative Groups represents the participant set with a handle. The handle exposes each member’s rank and the group size, and can be passed to synchronization or collective operations such as reduction. This does not repair an invalid call automatically; it makes the required collaboration visible in the code.
The diagram simplifies the main scopes. Membership and activity are determined by the kernel launch and control flow.
Kernel launch
└─ grid
├─ block A: thread_block
│ ├─ tiled_partition: fixed-size subgroup
│ └─ coalesced_threads: currently active warp threads
└─ block B: thread_block
└─ each block has a separate group scopeWhich group matches the participants?
CUDA creates implicit groups from the kernel launch configuration. thread_rank() gives a thread’s position within its group, and num_threads() gives the group size. Choose the group that matches the algorithm’s actual collaboration scope; group size alone does not define synchronization scope.
| Group or construction | Participants | Suitable use and limit |
|---|---|---|
| this_thread_block() → thread_block | Every thread in the current block | Block-wide shared-memory stages and synchronization with the same scope as __syncthreads() |
| tiled_partition(parent group) | Fixed-size subgroups partitioned from a parent group | Express a tile-level algorithm; every parent-group member must participate in the partition call |
| coalesced_threads() → coalesced_group | Warp threads active at the call site | Cooperate after divergence; do not assume which lanes are returned or that membership remains fixed |
| this_grid() → grid_group | All threads in the kernel grid | Use only when an in-kernel grid-wide phase boundary is necessary; cooperative-launch conditions apply |
A fixed tile divides its parent group into subgroups of the chosen size. A coalesced group instead represents the threads active at one point; its membership is not promised to stay the same later. Do not substitute one for the other just because both may contain warp threads. A grid group is not simply a larger block group: an ordinary kernel launch does not create a grid-wide barrier.
How do sync and reduce work within a group?
cg::sync(group) makes all members of the specified group reach the barrier before any proceeds. Memory accesses made by those members before the barrier are visible to the group after it. The guarantee applies only to that group. With a thread_block it has the same scope as __syncthreads(); with a tile it synchronizes only the tile’s participants.
The C++ below is an illustrative skeleton where each block computes one partial sum. It assumes a one-dimensional grid and block, an input length count, and one output slot per block. Threads beyond the input length contribute zero but still participate in the reduction. Application-specific allocation, launch configuration, and error handling are omitted. The output is one partial sum per block, not the sum of the entire input.
#include <cooperative_groups.h>
#include <cooperative_groups/reduce.h>
#include <cstddef>
namespace cg = cooperative_groups;
__global__ void blockPartialSum(const int* input, int* partial, std::size_t count) {
cg::thread_block block = cg::this_thread_block();
const std::size_t i =
static_cast<std::size_t>(blockIdx.x) * block.num_threads()
+ block.thread_rank();
const int value = (i < count) ? input[i] : 0;
// Every thread in block participates in the same reduction.
const int sum = cg::reduce(block, value, cg::plus<int>());
if (block.thread_rank() == 0) {
partial[blockIdx.x] = sum;
}
}A reduction combines the values contributed by the group’s threads using an operation such as sum, minimum, or maximum. Each thread must call the same collective for that group, though their input values can differ. If the application needs one sum for the whole input, it must combine the block partials in another step. NVIDIA documents hardware acceleration for some 4-byte reductions on compute capability 8.0 or later, with a software path when the acceleration is unavailable; this is an implementation detail, not a performance guarantee for every workload.
What conditions and failure modes should you check?
Group creation and collective operations require all intended participants to take part. If only some block threads enter tiled_partition() in a branch, the rest do not join the same collective operation; this can cause deadlock or data corruption. Create the group before divergent branches where practical, then structure branches and collectives around the handle’s actual membership.
Grid-wide synchronization changes the host launch path as well as the device code. The CUDA 13 guide requires checking cudaDevAttrCooperativeLaunch and using cudaLaunchCooperativeKernel. The grid must not contain more blocks than can be simultaneously resident; the guide describes the limit as active blocks per SM multiplied by the number of SMs. The kernel also cannot use CUDA Dynamic Parallelism. The guide checked on 2026-11-22 lists compute capability 6.0 or later and platform conditions including Linux without MPS, Linux with MPS on compute capability 7.0 or later, or the latest Windows platform. Recheck current toolkit, driver, and operating-system requirements before depending on this behavior.
| Symptom or design | Likely cause | Check or recovery |
|---|---|---|
| A path hangs or results are corrupted | Not every group member reaches the same collective | Create the group before branching and ensure all members call the same synchronization or operation |
| A fixed lane is assumed after warp divergence | coalesced group membership can change during execution | Use the returned group’s rank and size; do not assume a permanent lane set |
| grid.sync() is used with an ordinary <<<grid, block>>> launch | An ordinary launch does not guarantee grid-wide cooperation | Check device, platform, occupancy and grid-size requirements; use cooperative launch |
| A grid-wide stage is needed but cooperative-launch conditions are unavailable | The device or launch configuration cannot support the global barrier | Consider separating stages at a kernel-completion boundary |
CUDA 13 documentation says Cooperative Groups multi-device synchronization APIs have been removed; this article covers a single GPU. If the platform or grid-size requirements cannot be met, splitting the phases at a kernel boundary is often the simpler design because it avoids the stricter cooperative-launch setup.
How do you validate the group and synchronization choice?
Write down the exact set of threads that must share data or agree on a stage: a whole block, a fixed tile, currently active warp threads, or the full grid.
Create the matching implicit group handle before divergent control flow where possible. Pass the handle explicitly to a helper that uses the group.
Check that every group-creation and collective call is reached by all members. Confirm tile size against its parent group, and reacquire the coalesced group and rank after control flow changes.
For cross-block synchronization, verify cudaDevAttrCooperativeLaunch, operating-system and runtime support, and the occupancy-based grid limit. If those conditions do not fit, consider a kernel boundary.
Compare expected output on known inputs, including boundary lengths, partial tiles and short or empty inputs. Confirm whether a reduction returns block partials or a whole-input result, then repeat the same checks and measurements after changes.
The purpose of Cooperative Groups is not to make the group as large as possible. It is to represent the smallest participant set that the operation actually requires, so its synchronization contract and execution limits are clear.
Sources
[NVIDIA CUDA Programming Guide — Cooperative Groups](https://docs.nvidia.com/cuda/cuda-programming-guide/04-special-topics/cooperative-groups.html)
[NVIDIA CUDA Runtime API 13.5 — Execution Control](https://docs.nvidia.com/cuda/cuda-runtime-api/cuda_runtime_api/group__CUDART__EXECUTION.html)
[NVIDIA CUDA Programming Guide — Device-Callable APIs and Intrinsics](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/device-callable-apis.html)
[NVIDIA CUDA Samples — simpleCooperativeGroups](https://github.com/NVIDIA/cuda-samples/blob/master/cpp/0_Introduction/README.md)