What Is GPU Memory Coalescing? Map Warp Accesses for Better Efficiency
Memory coalescing is the way CUDA hardware serves addresses requested by the lanes of a warp with as few global-memory transactions as possible. The key is not simply how many threads are running, but which addresses one memory instruction requests and how many bytes each lane accesses. Neighboring lanes that read neighboring elements can share transfer segments; widely separated addresses may make the hardware fetch bytes the kernel never uses. Exact rules depend on GPU generation, access width, and alignment. Unless stated otherwise, the numeric examples below assume NVIDIA CUDA compute capability 6.0 or later and one aligned 4-byte read per lane in a 32-lane warp.
What Is GPU Memory Coalescing? Map Warp Accesses for Better Efficiency
Memory coalescing is the way CUDA hardware serves addresses requested by the lanes of a warp with as few global-memory transactions as possible. The key is not simply how many threads are running, but which addresses one memory instruction requests and how many bytes each lane accesses. Neighboring lanes that read neighboring elements can share transfer segments; widely separated addresses may make the hardware fetch bytes the kernel never uses. Exact rules depend on GPU generation, access width, and alignment. Unless stated otherwise, the numeric examples below assume NVIDIA CUDA compute capability 6.0 or later and one aligned 4-byte read per lane in a 32-lane warp.
How do warp addresses become memory transactions?
Each lane in a CUDA warp requests an address for a memory instruction. Hardware groups the requested addresses into memory segments and issues the transactions needed to cover those segments. A useful intuition for coalescing efficiency is the share of transferred bytes that the requesting lanes actually use. The NVIDIA CUDA C++ Programming Guide describes global-memory access in 32-byte transactions and explains that a warp's requests are grouped according to their address distribution.
The diagram shows 32 aligned, consecutive float values. Each value is 4 bytes, so the warp's 128 requested bytes fit in four 32-byte segments.
lane: 0 1 2 3 4 5 6 7 | 8 ... 15 | 16 ... 23 | 24 ... 31
float addr: 0 4 8 12 16 20 24 28 | 32 ... 60 | 64 ... 92 | 96 ... 124
segment: [ 0–31 ] [32–63] [64–95] [96–127]
result: 4 transactions of 32 bytes; 128 requested bytesLane order does not have to match ascending address order. A permutation can still use four transactions if the requested bytes remain within the same four segments. By contrast, if each lane reads a 4-byte value at least 32 bytes away from the next lane's address, the 32 addresses can fall in 32 different segments. The warp then transfers 1,024 bytes to use 128 bytes, for 12.5% useful-byte utilization. This illustrates a worst-case pattern; it does not mean cache reuse or actual device traffic will always make execution eight times slower.
| 4-byte access pattern within one warp | Example number of 32-byte segments | Interpretation |
|---|---|---|
32 lanes request adjacent A[i] values from a 32-byte-aligned start | 4 | The 128 requested bytes fill four segments. |
| 32 lanes request values at least 32 bytes apart | Up to 32 | Only 4 bytes in each segment may be used. |
| Only some lanes are active, or the start crosses an alignment boundary | Depends on the requested address range | A partial warp or misaligned address does not always produce one fixed transaction count. |
NVIDIA's Best Practices Guide uses the same simple model for compute capability 6.0 and later: count the 32-byte segments needed to serve concurrent warp accesses. Do not apply that arithmetic unchanged to earlier devices or different access widths; check the programming guide for the target compute capability. An alignment shift can make a consecutive access touch one additional segment. It is therefore more accurate to count the segments touched by a single instruction than to memorize “consecutive indexes are always best.”
How should threads map to the data layout?
For a one-dimensional array, a simple kernel assigns adjacent elements to adjacent threads by calculating a global index. This shortened example follows the vector-add pattern in the CUDA guide. The bounds check prevents threads in the last block from accessing elements beyond the array.
__global__ void add(const float* a, const float* b, float* c, int n) {
int i = blockIdx.x * blockDim.x + threadIdx.x;
if (i < n) {
c[i] = a[i] + b[i];
}
}Consecutive threadIdx.x values in a warp handle consecutive elements of a, b, and c. Check the addresses separately for every memory instruction: coalesced input reads do not automatically guarantee a coalesced output store. Also account for the array's starting address, element size, and active lanes in the final partial warp.
For two-dimensional data, match the lane-varying coordinate to the storage order. In a row-major matrix A[row][col], the linear address is row * leadingDimension + col. Columns are adjacent in memory, so mapping col across lanes often gives consecutive addresses when reading a row. If lanes instead vary row while holding the column fixed, their addresses may be separated by the row stride.
The best record layout also depends on which fields a kernel reads. The table below uses an illustrative assumption: each Particle has 4-byte x, y, and z values in a 12-byte structure, and the array begins aligned. When 32 lanes read only the x field of different records, addresses may span 12 segments. A separate x[] array (structure of arrays, or SoA) can serve the same read in four segments. An array of structures (AoS) may still be the better choice when operations use every field together, conversion would be costly, or padding and alignment differ.
| Layout or operation | Mapping to consider | Trade-off to check |
|---|---|---|
| One-dimensional contiguous array | Let lanes handle consecutive element indexes | Check width, alignment, and bounds for each read and write. |
| Row-major 2D array | Vary the column across lanes | Row-wise work may be efficient; collecting one column across rows introduces a stride. |
| Read one field from AoS records | Let each lane read the same field from a different record | The field stride may touch more memory segments. |
| SoA with several fields | Use consecutive indexes within each field array | Per-field access is straightforward, but more arrays or conversion may be needed. |
| Transpose with different input and output directions | Make global reads and writes consecutive separately |
For a matrix transpose, the lane layout that reads input consecutively may differ from the one that writes output consecutively. One option is to load a tile with coalesced global reads, reorder it in shared memory, and then write it with coalesced stores. The extra shared-memory use and synchronization have costs. NVIDIA's Best Practices Guide demonstrates this tiling approach in matrix examples. Shared-memory bank conflicts are a separate issue, not another name for global-memory coalescing.
How can Nsight Compute reveal inefficient coalescing?
First establish that global-memory access is a plausible cause of the measured slowdown. Use a CUDA GPU supported by Nsight Compute and the same input size, device, and execution path used by the application. For example, this command requests the Memory Workload Analysis tables. Check the available section names with --list-sections in the installed version.
ncu --section MemoryWorkloadAnalysis_Tables ./my_appIn the L1/TEX table, inspect Sectors/Req for global loads and stores. The current Nsight Compute guide describes an ideal ratio of 4 for a 32-bit value per lane when all 32 lanes are active, 8 for 64-bit access, and 16 for 128-bit access. Do not compare to those baselines unchanged when the active-lane mask or access width differs. If the sector count is higher than expected, recalculate lane addresses and strides. Sectors that miss in L1 may continue to L2 or device memory, so one L1 ratio by itself does not prove DRAM traffic or identify the application bottleneck.
**Choose the real kernel and input.** Select the kernel that takes meaningful time and record representative input size, distribution, and boundaries.
**Write down each lane address for one memory instruction.** Use the index expression and byte width to calculate active-lane addresses and mark the 32-byte sectors they touch. Use assumptions that match the target compute capability and access width.
**Read requests, sectors, and cache data together.** In Memory Workload Analysis, separate global loads from stores and inspect `Sectors/Req`, cache hits/misses, and memory utilization. Available fields and metrics vary by GPU and tool version.
**Change one mapping at a time.** Remap indexes or data so neighboring lanes access neighboring elements, then verify correctness including boundary cases. For a transpose, include the cost of reordering through shared memory.
**Verify gains under the same conditions.** Compare kernel time and application time including copies across repeated runs. Profiling and metric collection can add overhead, so do not use a profiler run alone as the performance result. Revert a change if the improvement is not repeatable or another stage becomes slower.
| Observation | Possible cause | What to check or how to recover |
|---|---|---|
Sectors/Req is higher than expected for a warp | Large stride, alignment boundary, lane mapping, or access width | Expand the address expression by lane, count the actual sectors, and compare row/column mapping or AoS/SoA. |
| Sector use improves but runtime barely changes | Cache reuse, compute bottleneck, spare memory bandwidth, or a short kernel | Check the full bottleneck and launch/copy costs. Keep the simpler layout if measurements show little benefit. |
| Reads look efficient but stores do not | Output indexes are mapped differently from input indexes | Analyze global reads and writes separately; consider tiled reordering if justified. |
| Repacking data makes the overall workload slower | Conversion/copy cost, temporary storage, or worse access in another kernel | Check whether multiple operations reuse the new layout; compare end-to-end time and revert if needed. |
Coalescing is a way to use the bytes moved by global-memory requests efficiently. More transactions do not always translate into the same proportional loss in application runtime. Cache behavior, reuse, arithmetic, memory-pipeline utilization, and conversion costs all matter. Start with the addresses, use measurements to identify a bottleneck, and keep a new layout only when it repeatedly helps the real workload.
Sources
[NVIDIA CUDA Programming Guide — Writing SIMT Kernels](https://docs.nvidia.com/cuda/cuda-programming-guide/02-basics/writing-cuda-kernels.html)
[NVIDIA CUDA C++ Best Practices Guide — Coalesced Access to Global Memory](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/)
[NVIDIA Nsight Compute — Profiling Guide](https://docs.nvidia.com/nsight-compute/ProfilingGuide/)