What is Memory coalescing?
Combining accesses into a few memory transactions when adjacent threads in a warp access adjacent addresses.
Japanese name: メモリコアレッシング
Combining accesses into a few memory transactions when adjacent threads in a warp access adjacent addresses.
Japanese name: メモリコアレッシング
GPU global memory is accessed in fixed-size chunks, typically 32-byte sectors within 128-byte cache lines, not in individual words. Threads execute in groups called warps, usually 32 threads issuing the same load instruction together. When thread i of a warp reads the 4-byte element at base + 4i, the 32 requests fall into 128 contiguous bytes, and the hardware combines them into one or a few memory transactions. This combining is memory coalescing, and it lets the GPU use nearly all the bytes it moves.
If threads access addresses with a stride, for example every fourth element, the warp touches four times as many sectors, and most of each fetched sector is discarded. Random or indirect accesses can require a separate transaction for every thread. Misaligned starting addresses can add one extra segment. In each case effective bandwidth drops to a fraction of the peak, and since many GPU kernels are limited by memory bandwidth rather than arithmetic, uncoalesced access often slows a kernel by a large factor.
Data layout largely decides whether accesses coalesce. With particle positions stored as an array of structures (AoS), the x, y and z of particle 0 are followed by those of particle 1, so when each thread reads x the addresses are 12 bytes apart. With a structure of arrays (SoA), all x values are contiguous, so adjacent threads read adjacent addresses and the warp's loads coalesce. SoA is also usually better for CPU SIMD vectorization, for the same reason: neighboring lanes want neighboring elements.
Common fixes include mapping the fastest-changing thread index, threadIdx.x in CUDA, to the contiguous dimension of an array, converting AoS data to SoA, and staging data through on-chip shared memory, for example loading a matrix tile with coalesced row reads and writing it out transposed. Coalescing concerns global memory transactions. It should not be confused with shared-memory bank conflicts, which occur when several threads of a warp hit different addresses in the same shared-memory bank and their accesses are serialized.
Answer: C. When adjacent threads in a warp read adjacent addresses, the reads are combined into a few memory accesses
GPU memory is read and written in chunks such as 32 or 128 bytes. If the 32 threads of a warp each read 4 consecutive bytes, the 128 bytes together are fetched in one or a few accesses. With scattered addresses, each thread needs a separate chunk and unused data is carried along, cutting effective bandwidth to a fraction.
Answer: C. Separate arrays for x, y and z (a structure of arrays rather than an array of structures)
In an array of structures (AoS), the layout is x, y, z of particle 0, then x, y, z of particle 1 and so on, so when each thread reads x the addresses are 12 bytes apart. In a structure of arrays (SoA), all x values are contiguous, so adjacent threads read adjacent x values and the accesses coalesce. SoA is often better for CPU SIMD for the same reason.
It is the hardware combining the global memory accesses of a warp's threads into as few transactions as possible, which happens when adjacent threads access adjacent, aligned addresses.
In a structure of arrays, each field is stored contiguously, so adjacent threads reading the same field access consecutive addresses and their loads coalesce; an array of structures puts a stride between them.
Coalescing concerns how a warp's global memory accesses map onto memory transactions, while bank conflicts concern multiple threads accessing the same bank of on-chip shared memory, which forces serialization.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.