What Is GPU Memory Hierarchy? Choose Storage by Scope and Reuse
GPU memory hierarchy is a map of where data resides during computation and which threads can share it. Storage ranges from small per-thread registers to device memory used across the GPU and memory attached to the CPU. Choose a place by the data’s lifetime, reuse and sharing scope. Physical placement and performance still depend on the GPU generation and programming model.
What Is GPU Memory Hierarchy? Choose Storage by Scope and Reuse
GPU memory hierarchy is a map of where data resides during computation and which threads can share it. Storage ranges from small per-thread registers to device memory used across the GPU and memory attached to the CPU. Choose a place by the data’s lifetime, reuse and sharing scope. Physical placement and performance still depend on the GPU generation and programming model.
Read two maps: physical location and sharing scope
The first map shows storage and cache locations. This simplified view of NVIDIA CUDA does not promise a fixed latency ranking or describe every GPU’s circuit. Cache hits, access patterns and hardware generations change the path.
Host memory (attached to CPU)
↕ copy or system-specific shared/access path
Device memory (DRAM; CUDA global-memory address space)
↕ requests reach device memory on cache misses
GPU-wide L2 cache
↕
Each SM: L1 cache | block-shared memory | per-thread registersThe second map is about who may see the data. A register belongs to one thread. Shared memory lets threads in a CUDA thread block (or a supported cluster) cooperate. Multiple blocks can access a global-memory allocation, but concurrent reads and writes still require correct synchronization and memory-ordering rules. L1 and L2 are hardware-managed cache levels, not arrays that a programmer fills directly.
| Level or space | Typical scope or role | What to keep in mind |
|---|---|---|
| Registers | Temporary values for one thread | SM resources are finite. High per-thread use can reduce concurrent work or cause values to spill elsewhere. |
| Shared memory | Cooperative data for a block or supported cluster | Useful when threads reuse or exchange values. High use and synchronization can reduce execution efficiency. |
| L1 cache | Automatic cache close to an SM | Cache policy and resource sharing with shared memory depend on architecture and configuration; hits are not guaranteed. |
| L2 cache | GPU-internal cache shared by multiple SMs | Reuse can be served closer to the SMs, but do not assume data will remain resident. |
| Device DRAM and global memory | Large storage and the CUDA kernel’s global address space | Holds data used by many threads and kernels. Access patterns matter, and some requests may be served by caches. |
| Host memory | System memory attached to the CPU | On a discrete GPU, the CPU–GPU link can matter. Integrated GPUs and Unified Memory can have different physical placement and access behavior. |
The NVIDIA CUDA Programming Guide describes a register file and shared-memory/L1 resources on each SM, with L2 shared across the GPU’s SMs. Capacities and allocation behavior vary by product and compute capability, so this vocabulary is not a universal latency chart. CUDA Programming Model
How are address spaces different from caches?
A CUDA memory space describes how code addresses data and which scope owns it. A cache is hardware that may serve a memory request from a closer location. Global memory and L2 are therefore not competing choices: a load from global memory may be served by L1 or L2. CUDA local memory is another common source of confusion. “Local” means logically private to a thread; it does not guarantee an on-chip physical location. Local arrays and register spills can create traffic in the device-memory hierarchy.
| CUDA space or feature | Meaning and useful role | Common misconception or caution |
|---|---|---|
| Register | A thread’s frequently used intermediate values | Registers are limited. Compiler register demand changes resource use and can cause spilling. |
| Local memory | Values logically private to one thread, such as some arrays | “Local” does not mean physically on-chip. Inspect actual traffic and profiling results. |
| Shared memory | Explicitly shared or exchanged values within a block | Synchronize before reading values written by other threads; consider block size and resource use. |
| Global memory | Device-resident data for kernels | It is not equally fast for every access. Coalescing adjacent threads’ accesses can reduce unnecessary transactions. |
| Constant and texture paths | Features for particular read patterns, such as uniform values or spatial locality | They are not universally faster general-purpose memory. Use them when the pattern fits the target architecture. |
| Host and Unified Memory | CPU-side memory and a model that can make allocations accessible to CPU and GPU | Unified Memory is a programming model, not a promise of one physical memory or equal performance on every system. |
NVIDIA’s CUDA Best Practices Guide explains CUDA scopes and coalesced global accesses. AMD HIP describes similar programming concerns with its own terms, including private registers, workgroup-scoped LDS and device-wide global memory. Similar purposes do not make CUDA shared and HIP LDS identical on every device; check the target platform’s documentation. CUDA memory spaces and coalescing · AMD HIP programming model
Host and device memory also need to be distinguished. A discrete GPU generally has memory attached to the CPU and separate memory attached to the GPU; data is copied or accessed through system-specific sharing features. An integrated SoC can physically share memory while retaining distinct CPU and GPU roles. CUDA Unified Memory makes allocations accessible to CPU and GPU, but placement and movement depend on system support. Check where data resides and how often it moves. CUDA Unified Memory guide
How does one matrix-multiplication block move through the hierarchy?
The following is an illustrative example of computing an output tile by reusing part of the input matrices. It is not a benchmark or a claim about measured speedup on a particular GPU.
A block reads the input tile it needs from global memory. If the tile will be reused, its threads can cooperatively place it in shared memory.
Threads synchronize to confirm that tile loading is complete. Without the needed synchronization, a thread might read a value that another thread has not written yet.
Each thread reads required values from the shared tile and keeps small multiply-and-accumulate intermediates in registers.
The block reuses the same tile to compute several outputs. This may reduce memory requests compared with fetching the input again for every result.
Threads write output values to global memory so later kernels or host-side work can use them.
| Calculation stage | Main space used | Why it fits and when it helps |
|---|---|---|
| Read input tile | Global memory and caches | Large source data begins here. Adjacent-thread accesses are easier to coalesce when adjacent threads read adjacent elements. |
| Reuse data inside a block | Shared memory | Helps when several threads use the same values repeatedly. Loading and synchronization can cost more than they save if reuse is low. |
| Multiply and accumulate | Registers | Fits small values a thread is using immediately. High register use can affect block concurrency or cause spills. |
| Store output | Global memory | Keeps results available to later blocks, kernels or host-side work. |
The possible benefit does not come from shared memory being “always faster”; it comes from reusing data in a block and avoiding some repeated trips to device memory. If an input is read once or a tile has little reuse, staging and synchronization add work. A large tile or many registers can also consume SM resources and reduce the number of concurrent blocks. Use tiling when reuse is present and measure the result.
How should you validate a storage choice in a real kernel?
Changing one factor at a time makes performance changes easier to explain.
**Set a baseline.** Record input size, GPU model and programming model, kernel time and output correctness. Compare the same workload under the same conditions.
**Write down ownership and lifetime.** Identify whether one thread, a block, multiple blocks or the CPU needs each value, and when it is read or written. This exposes the required scope and synchronization.
**Check access shape and reuse.** A value used once may not justify an explicit cache. Consider shared memory for data reused within a block, and check whether adjacent threads’ global accesses coalesce.
**Inspect compiler and execution resources.** Check whether register use, local-memory traffic, shared-memory use or resource limits for concurrent blocks changed. If local traffic rises, investigate large per-thread arrays or register spills.
**Profile the bottleneck again.** NVIDIA Nsight Compute’s Memory Workload Analysis can help inspect memory requests, transfers and cache hit rates on supported NVIDIA GPUs. Compare these with kernel time rather than optimizing one counter. If the result does not improve, return to the simpler implementation. Profiler replay/cache settings and other running GPU work can affect measurements. [Nsight Compute Profiling Guide](https://docs.nvidia.com/nsight-compute/ProfilingGuide/index.html)
As a starting point, use registers for one thread’s immediate values, consider shared memory for data reused within a block, and use global memory for large inputs, outputs or data passed between blocks. Then measure whether automatic caches already provide reuse, whether data moves between CPU and GPU, and whether explicit staging actually reduces work. This is a design starting point, not a performance ranking guaranteed on every GPU.
References
[NVIDIA CUDA Programming Guide: Programming Model](https://docs.nvidia.com/cuda/cuda-programming-guide/01-introduction/programming-model.html)
[NVIDIA CUDA C++ Best Practices Guide: Device Memory Spaces](https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html)
[NVIDIA CUDA Programming Guide: Unified Memory](https://docs.nvidia.com/cuda/cuda-programming-guide/04-special-topics/unified-memory.html)
[NVIDIA Nsight Compute: Profiling Guide](https://docs.nvidia.com/nsight-compute/ProfilingGuide/index.html)
[AMD HIP: Introduction to the HIP Programming Model](https://rocm.docs.amd.com/projects/HIP/en/latest/understand/programming_model.html)