IIntroduction to AI Systems Performance EngineeringTechnical textbook
Chapter 6

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

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
Lessons

Study this chapter

  1. 6.1
    Coalescing and useful bytes

    List every active lane address for one memory instruction and estimate requested bytes, transferred bytes, and useful-byte fraction

    Begin lesson →
  2. 6.2
    Shared-memory tiling and bank conflicts

    Design a cooperative shared-memory tile and predict its bank mapping, barrier locations, capacity cost, and global-transaction change

    Begin lesson →
  3. 6.3
    Registers, spilling, and instruction-level parallelism

    Explain a register-allocation change using live values, instruction-level parallelism, residency, spill instructions, and measured local-memory traffic

    Begin lesson →
  4. 6.4
    Data layout and memory access

    Write a complete coordinate-to-address contract and decide whether conversion or persistent packing improves the full producer-consumer path

    Begin lesson →
Chapter projects

Extended exercises

Complete these projects after the lesson-level practice tasks. Each project combines several mechanisms from the chapter.

01
Check

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.

02
Practice

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.

03
Challenge

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.

References

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.

  1. CUDA C++ Best Practices Guide
  2. CUDA C++ Programming Guide
  3. Nsight Compute Profiling Guide