GPU Memory Optimization
Reduce data movement and increase data reuse
Calculate memory transactions, use shared memory for reuse and rearrangement, control register pressure, and evaluate layouts across operator boundaries.
A source expression such as y[i] = a * x[i] + y[i] contains one multiply and one addition, but a graphics processing unit (GPU) must also obtain two input values and store one result. For many kernels, those transfers require more time than the arithmetic. The important question is therefore not only how many bytes the program requests. The question is how the hardware groups requests into transactions, where values are reused, and how often a value moves between named storage levels.
This chapter follows one value from off-chip device memory to an on-chip cache near a streaming multiprocessor (SM), into shared memory, through registers, and into a later operator. Data-center accelerators often use high-bandwidth memory (HBM), while many other GPUs use graphics double data rate memory. The same requested-versus-transferred byte analysis applies to both. Coalescing determines whether a warp uses most of each global-memory transaction. Shared-memory bank mapping determines whether on-chip requests proceed in parallel. Register allocation determines how much thread-local state can remain immediately available. Tensor layout determines whether these properties continue across operator boundaries.
The analysis method is consistent throughout the chapter. First identify the logical values required by the algorithm. Then map each lane to an address. Calculate requested bytes, transferred bytes, reuse, and storage capacity. Finally, measure the relevant traffic and elapsed time. This sequence prevents a favorable cache percentage or occupancy number from replacing the actual data-movement calculation.
Prerequisites
- Chapter 4 storage hierarchy and Chapter 5 warp-address mapping
- Ability to calculate byte offsets in row-major and column-major matrices
- Ability to read a profiler table containing requested and transferred bytes
Learning objectives
- Predict warp memory transactions from lane addresses
- Design and verify shared-memory reuse without bank conflicts
- Connect register live ranges and tensor layouts to measured traffic and elapsed time
Study this chapter
- 6.1Coalescing and useful bytesBegin lesson →
List every active lane address for one memory instruction and estimate requested bytes, transferred bytes, and useful-byte fraction
- 6.2Shared-memory tiling and bank conflictsBegin lesson →
Design a cooperative shared-memory tile and predict its bank mapping, barrier locations, capacity cost, and global-transaction change
- 6.3Registers, spilling, and instruction-level parallelismBegin lesson →
Explain a register-allocation change using live values, instruction-level parallelism, residency, spill instructions, and measured local-memory traffic
- 6.4Data layout and memory accessBegin lesson →
Write a complete coordinate-to-address contract and decide whether conversion or persistent packing improves the full producer-consumer path
Extended exercises
Complete these projects after the lesson-level practice tasks. Each project combines several mechanisms from the chapter.
Stride sweep
Run one warmed warp-scale FP32 load at byte strides 4, 8, 16, 32, 64, and 128 while keeping the requested value count fixed.
Evidence: Lane-address tables, predicted sectors, Nsight Compute transferred-byte metrics, and completed requested bytes per second.
Tiled transpose
Implement naive, 32×32 tiled, and 32×33 padded-shared-memory transpose kernels for aligned and tail dimensions.
Evidence: Exact output checks, global transaction counts, shared-bank-conflict metrics, resource use, and CUDA-event timing.
Layout amortization
Compare on-demand conversion with preserving packed weights for the recurring 7-billion-parameter inference workload over a declared replica lifetime.
Evidence: Cold-start time, steady invocation time, memory footprint, consumer compatibility, and a measured break-even invocation count.
Sources and further reading
The lesson explanations synthesize primary papers and official references. Follow the originals for proofs, exact APIs, architecture details, and version-sensitive behavior.