Global-memory coalescing
Count the sectors touched by active lanes and distinguish request efficiency from measured device-memory traffic.
On this page
The question for today
What you’ll understand
- Derive byte addresses from a tensor layout and lane index.
- Count aligned 32-byte sectors under a stated CUDA architecture model.
- Separate coalescing efficiency, cache reuse, and end-to-end performance.
A tensor kernel can ask each thread for only one floating-point value and still move much more data than those values contain. The memory system services groups of lane addresses, so access layout determines which sectors are needed. This lesson uses the CUDA 12.8.1 best-practices model for devices of compute capability 6.0 or higher, with a 32-lane warp and scalar four-byte loads. Wider instructions and other architectures require their own analysis.
Start with active-lane addresses
Write the address used by each active lane for one issued memory instruction. For a row-major FP32 tensor, adjacent lanes accessing adjacent columns often request consecutive four-byte words. A column traversal can instead separate lanes by a whole row stride. The important pattern is the set of addresses serviced together, not whether the source code contains a simple loop or a familiar tensor operation. Predication and boundary tiles change which lanes participate, so analyze partial warps as well as the interior case.
Under the stated compute-capability model, count the distinct aligned 32-byte sectors needed to cover the requested words. Permuting lanes within the same sectors does not necessarily change that count. Fewer active lanes do not automatically reduce it if their words remain spread over the same sectors. An aligned base allocation also does not guarantee every tensor view is aligned: an offset slice or a row pitch can shift the starting address. Verify effective addresses after indexing and view transformations.
Alignment changes the covered sectors
Thirty-two adjacent four-byte loads request 128 useful bytes. If the first word begins on a 32-byte boundary, four sectors cover them. Starting one word later can require five sectors for the same useful payload. Strided accesses can use only part of each fetched sector. These counts describe one access request under the simplified sector model; they are not a promise that an identical number of bytes reaches external memory after caching, reuse, compression, or implementation-specific effects.
Coalescing is also independent of correctness. A highly coalesced access can still be out of bounds, race with another operation, or violate alignment requirements for the compiled instruction. Conversely, a scattered access may be correct and unavoidable for the algorithm. Improve layout only while preserving the logical mapping of tensor elements. Compare numeric outputs, including edge dimensions and noncontiguous inputs, before interpreting a bandwidth improvement as a successful optimization.
Connect layout to a measured bottleneck
Use compiler and profiler evidence to establish the actual instruction widths, active lanes, and memory behavior. Compare otherwise equivalent tensor kernels at representative sizes, separating warm cache reuse from cold streaming behavior. A coalescing change can affect register pressure, shared-memory use, and occupancy, so the fastest source layout is not determined by sector count alone. Record the target GPU architecture, toolkit, and kernel launch shape whenever reporting a result. CUDA version and compute capability describe different parts of that environment.
The Roofline lab illustrates only a possible traffic consequence. Reset, set operational intensity to 2 FLOP per byte and bandwidth to 80 GB/s, predict the synthetic ceiling, then Step. For a new run, Reset and set both intensity to 1 and bandwidth to 80, predict, then Step. Treat the lower intensity as an assumed doubling of bottleneck bytes at fixed useful arithmetic. The model’s compute ceiling is fixed at 1000 GFLOP/s; it does not count sectors or benchmark a GPU.
Work it through
An offset adds a sector
All 32 lanes load adjacent four-byte words. In case A the first byte address is 0, aligned to a 32-byte sector. In case B it is 4. Count covered sectors and request efficiency, ignoring cache reuse.
Case A touches bytes 0 through 127. Sectors starting at 0, 32, 64, and 96 cover the 128 useful bytes, giving four sectors.
Case B touches bytes 4 through 131. It needs sectors starting at 0, 32, 64, 96, and 128, giving five sectors or 160 covered bytes.
Efficiencies are 128/128 = 100% and 128/160 = 80%. Neighboring warps may reuse over-fetched sectors, so these ratios alone do not predict the measured throughput difference.
A one-word view offset changes the covered-sector count without changing the requested tensor values’ total byte size.
The living notebook
Explore the model
Interactive lab · roofline
Extra traffic reduces operational intensity
Reset, set intensity I = 2 and bandwidth B = 80, predict the synthetic ceiling, then Step. Compare a fresh Reset with both I = 1 and B = 80. The fixed 1000-GFLOP/s ceiling is hypothetical; this instrument does not simulate coalescing or actual GPU bandwidth.
- Attainable ceiling
- 640 GFLOP/s
- Ridge intensity
- 12.5 FLOP/byte
- Ceiling regime
- Memory-bound ceiling
Synthetic roofline ceiling min(1000, B·I), in GFLOP/s, with B in decimal GB/s and I in FLOP/byte. Playback traces the roof without changing the selected kernel. This upper-bound model is not a measured throughput prediction, hardware comparison or price model. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forSector efficiency can influence bottleneck traffic, but a Roofline ceiling remains a model rather than measured performance.
Pause & reason
Check your understanding
Your turn
Try it yourself
All 32 lanes load four-byte words at addresses 8ℓ from an aligned zero base. Count the 32-byte sectors touched, useful bytes, and efficiency under the same model.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
The last word begins at byte 248 and ends at 251; each sector holds four of these strided words.
Compare with the solution
The addresses cover eight aligned sectors, from base 0 through base 224. Useful payload is 32 × 4 = 128 bytes, while covered bytes are 8 × 32 = 256. Request efficiency is 50%. This does not measure DRAM traffic after reuse or prove a particular runtime slowdown.
Keep the idea
Take it with you
- Coalescing depends on the addresses of active lanes for each issued instruction.
- Alignment and stride change sector coverage under an architecture-specific model.
- Sector counts, cache traffic, safety, and kernel performance need separate evidence.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.