What Is a CUDA Warp? How Lanes Affect Memory and Branches
A CUDA warp is a group of 32 threads that NVIDIA CUDA groups to process instructions together. Each thread in a warp has its own lane number and data, but the group matters when memory requests are combined or some lanes are inactive on a branch. A warp does not correspond one-to-one with 32 physical cores or with an execution group on every other GPU. [NVIDIA CUDA Programming Guide — Programming Model](https://docs.nvidia.com/cuda/cuda-programming-guide/01-introduction/programming-model.html)
What Is a CUDA Warp? How Lanes Affect Memory and Branches
A CUDA warp is a group of 32 threads that NVIDIA CUDA groups to process instructions together. Each thread in a warp has its own lane number and data, but the group matters when memory requests are combined or some lanes are inactive on a branch. A warp does not correspond one-to-one with 32 physical cores or with an execution group on every other GPU. NVIDIA CUDA Programming Guide — Programming Model
How are warps organized inside a block?
CUDA divides the threads in a thread block into groups of 32 called warps. In a one-dimensional block, the lane number is threadIdx.x modulo warpSize, and the warp number is the quotient. A block with 64 threads therefore contains two warps, each with lane IDs from 0 through 31. The CUDA model's warpSize is 32. When code depends on the width, using the device-side warpSize makes that dependency explicit. NVIDIA CUDA Programming Guide — Programming Model NVIDIA CUDA Programming Guide — C/C++ Language Extensions
The diagram is a conceptual mapping for a one-dimensional block whose threadIdx.x values run from 0 through 63.
threadIdx.x: 0 1 2 ... 31 | 32 33 34 ... 63
warpIdx: 0 0 0 ... 0 | 1 1 1 ... 1
laneId: 0 1 2 ... 31 | 0 1 2 ... 31A warp is a subgroup inside a block; it is not the block itself. With 48 threads, the second warp has only 16 actual threads and its remaining lane positions are unused. Such a block size is legal, but the final warp may not use all its execution lanes. NVIDIA's guide says a block size that is a multiple of 32 is generally preferable; this is a starting point, not a guarantee of the best size for every kernel. NVIDIA CUDA Programming Guide — Programming Model
| Unit | Meaning in CUDA | Boundary to remember |
|---|---|---|
| Thread | One execution participant in the kernel | It is not pinned to one CUDA core |
| Lane | A thread's numbered position within a warp | In a 1D block, IDs repeat from 0 to warpSize-1 |
| Warp | A group of 32 threads inside one block | It does not span separate blocks |
| Block | A thread group that can contain several warps | Its synchronization scope differs from a warp's |
How does a warp combine global-memory access?
Coalescing combines the global-memory addresses requested by lanes in a warp into as few memory transactions as possible. That is why consecutive threads reading or writing consecutive array elements often produce well-grouped addresses. If 32 lanes each request one 4-byte float at consecutive addresses, the useful data totals 128 bytes. For an aligned access under the documented compute-capability 6.0-and-later model, four 32-byte transactions can serve those requests. NVIDIA CUDA Programming Guide — Writing SIMT Kernels NVIDIA CUDA C++ Best Practices Guide 13.5 — Coalesced Access
Both patterns below have 32 lanes requesting one 4-byte value each. In the second, each lane advances by 32 elements, placing addresses in separate 32-byte segments.
laneId: 0 1 2 ... 31
indexA: 0 1 2 ... 31
indexB: 0 32 64 ... 992| Address pattern per lane | Example 4-byte values | Illustrative transaction use |
|---|---|---|
| Consecutive addresses | float indices 0, 1, 2, …, 31 | Fills four aligned 32-byte segments with 128 bytes |
| Skip 32 elements | float indices 0, 32, 64, …, 992 | If each request falls in a separate segment, 128 bytes use 32 segments |
The 12.5% figure for the second row comes from a teaching model in which 128 useful bytes arrive in 32 transactions of 32 bytes each, or 1,024 transferred bytes. It is not a measured kernel speed or a claim that every GPU generation uses the same transaction count. Coalescing depends on element size, address distribution, and compute capability; caches and other work also affect performance. The practical use of the warp model is to inspect which addresses lanes request together, not to memorize “contiguous always means fast.” NVIDIA CUDA C++ Best Practices Guide 13.5 — Coalesced Access
How do lanes participate in branches?
In CUDA's SIMT model, threads in a warp follow the same instruction flow, but each thread can evaluate a condition differently. When the paths split, the lanes selected for one path execute it while the others are masked off. If both paths are needed within the same warp, work is required to process each path, so efficiency can be lower than when all lanes follow one path. This does not mean a branch is always twice as slow; the effect depends on path length, compilation, and data. NVIDIA CUDA Programming Guide — Programming Model
The diagram below is a hypothetical illustration: lane IDs split into two paths according to whether the ID is even. It is not a GPU performance result.
condition: laneId % 2 == 0
pathTrue: 0, 2, 4, ... 30
pathFalse: 1, 3, 5, ... 31A branch is a normal way to express control flow for the input. However, code with different lane conditions must not assume that an entire warp always executes one branch at once. Detailed causes and remedies for warp divergence are outside this article's scope. Keep results correct, then measure the actual pattern on the target GPU instead of removing branches by guesswork.
“Same instruction flow” describes the CUDA SIMT programming model. It does not mean software may rely on undocumented physical lockstep scheduling or use it as a memory-ordering guarantee. For communication between lanes, follow the documented warp operations and synchronization rules. NVIDIA CUDA Programming Guide — Programming Model NVIDIA CUDA Programming Guide — C/C++ Language Extensions
When and how should warp-scoped operations be used safely?
Most CUDA kernels can let each lane process its own data. Consider warp-scoped operations only when lanes need to exchange values or coordinate access to memory within the same warp. A function name containing “sync” does not make every warp operation a memory barrier. NVIDIA CUDA Programming Guide — C/C++ Language Extensions
| Operation | Scope and effect | What to check |
|---|---|---|
| __shfl_sync(mask, …) | Exchanges values between warp lanes named in mask | Each calling lane's bit must be set; every non-exited lane named in mask must call the same operation at the same point with the same mask. It does not order memory accesses |
| __syncwarp(mask) | Coordinates named lanes in the same warp and provides memory ordering among participants | The mask must match the actual participants. It does not wait for other warps in the block |
| __syncthreads() | Synchronizes threads in one block | A block-wide barrier may be needed when multiple warps share data |
Warp shuffle passes a value between lanes without shared memory, but reading from an inactive lane has undefined results. The shuffle call itself is not a memory barrier. By contrast, __syncwarp(mask) orders memory among the named warp participants. If a non-exited lane named in the mask does not reach the same call point with the same mask, behavior can be invalid or undefined. For complex masks, consider the higher-level libcu++ cuda::device::warp_shuffle operation that NVIDIA documents as a generalized, safer alternative. NVIDIA CUDA Programming Guide — C/C++ Language Extensions
Do not transfer CUDA's 32-lane width and mask rules unchanged to another GPU API. AMD ROCm HIP documentation says warpSize can vary by target device and cross-lane mask types can differ from CUDA. When porting to HIP, query the target width and recheck that API's participation rules. AMD HIP C++ Language Extensions 7.1 — warpSize and Cross-Lane Functions
Use this order to review warp assumptions in a new CUDA kernel.
**Identify the target API and execution model.** This explanation covers NVIDIA CUDA's 32-thread warp. For HIP or another API, check its group width and mask rules separately.
**Write down the block size and lane mapping.** In a 1D block, calculate the threadIdx.x range for each warp and check whether the last warp contains unused lanes.
**List the addresses requested by lanes for one instruction.** For an array, check whether adjacent lanes use adjacent indices; if there is a stride, estimate how many memory segments the access needs.
**Check the active lanes in each branch.** Trace which lanes take each path, but do not claim a fixed runtime multiplier before measuring the code and device.
**Verify masks and synchronization scope.** Separate shuffle value exchange from memory ordering, and check whether cooperation among multiple warps requires block-wide synchronization.
The lane diagrams and memory numbers in this article are explanatory; they were not run or measured on a GPU. Even a coalesced access pattern does not guarantee a particular speed. Profile with the target device and real input while preserving correctness.
Sources
[NVIDIA CUDA Programming Guide — Programming Model](https://docs.nvidia.com/cuda/cuda-programming-guide/01-introduction/programming-model.html)
[NVIDIA CUDA Programming Guide — Writing SIMT Kernels](https://docs.nvidia.com/cuda/cuda-programming-guide/02-basics/writing-cuda-kernels.html)
[NVIDIA CUDA Programming Guide — C/C++ Language Extensions](https://docs.nvidia.com/cuda/cuda-programming-guide/05-appendices/cpp-language-extensions.html)
[NVIDIA CUDA C++ Best Practices Guide 13.5 — Coalesced Access](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/)
[AMD HIP C++ Language Extensions 7.1 — warpSize and Cross-Lane Functions](https://rocm.docs.amd.com/projects/HIP/en/docs-7.1.0/how-to/hip_cpp_language_extensions.html)