Inferensys

Glossary

Memory Hierarchy

Memory hierarchy is the organization of memory subsystems into multiple levels—such as registers, caches, and main memory—with differing speeds, capacities, and costs, optimized to exploit data locality and improve system performance.
Developer building agentic RAG system, retrieval pipeline diagram on laptop, technical workspace with notes.
GPU MEMORY OPTIMIZATION

What is Memory Hierarchy?

A memory hierarchy is the organization of memory subsystems in a computing system into multiple levels with differing capacities, latencies, and bandwidths, designed to optimize data locality and overall performance.

A memory hierarchy organizes storage into distinct tiers—such as registers, shared memory, L1/L2 cache, and global memory—each with a trade-off between speed, capacity, and cost. This structure exploits the principle of locality, where frequently accessed data is kept in smaller, faster memory levels close to the processor. In GPU architectures, this hierarchy is critical for managing the massive parallelism of thousands of threads, ensuring high-bandwidth data feeds to streaming multiprocessors while masking the latency of accessing slower, high-capacity device memory.

Effective programming requires understanding this hierarchy to optimize memory access patterns. Techniques like coalesced global memory accesses and minimizing shared memory bank conflicts are essential for achieving peak bandwidth. Modern systems extend this concept through unified virtual memory and memory tiering, which automatically migrate data between GPU memory, host RAM, and even storage based on usage, creating a seamless, expansive address space managed by hardware and system software.

GPU MEMORY OPTIMIZATION

Key Characteristics of Memory Hierarchy

Memory hierarchy organizes storage into tiers with a fundamental trade-off: capacity and cost increase as you move away from the processor, while speed and bandwidth decrease. Optimizing data placement and movement across these tiers is critical for performance.

01

Access Latency & Bandwidth

The defining trade-off of the hierarchy. Latency is the time to retrieve a single piece of data, while bandwidth is the rate of sustained data transfer.

  • Registers: Sub-1 nanosecond latency, terabytes/sec of bandwidth.
  • L1/L2 Cache: ~1-10 ns latency, hundreds of GB/s bandwidth.
  • Shared Memory: ~10-20 ns latency, similar bandwidth to L1 (but software-managed).
  • Global Memory (HBM/GDDR): ~100-300 ns latency, 1-3 TB/s bandwidth (e.g., HBM3).
  • Host Memory (DDR): ~100-200 ns latency, ~50-100 GB/s bandwidth.
  • Storage (NVMe SSD): ~10-100 microseconds latency, ~5-10 GB/s bandwidth.

The goal is to keep frequently accessed data (hot data) in the fastest tiers.

02

Capacity & Cost Per Bit

Capacity scales inversely with speed. Faster memory uses more transistors and advanced packaging, making it significantly more expensive.

  • Registers: Kilobytes per SM. Highest cost/bit.
  • On-Chip Caches (L1/L2): Megabytes per GPU. High cost/bit.
  • Shared Memory: Kilobytes per Thread Block. Software-managed resource.
  • High Bandwidth Memory (HBM): Tens of Gigabytes (e.g., 80GB HBM3). High cost/bit, but essential for bandwidth.
  • Host DRAM: Hundreds of Gigabytes to Terabytes. Lower cost/bit.
  • NVMe Storage: Multiple Terabytes. Lowest cost/bit.

This cost structure forces systems to use small amounts of fast memory as a cache for larger, slower memory.

03

Data Locality Principles

Performance depends on exploiting two types of locality to minimize accesses to slower memory tiers:

  • Temporal Locality: Recently accessed data is likely to be accessed again soon. This justifies caching. Example: The KV Cache in a transformer's attention mechanism is a form of explicit temporal locality management.
  • Spatial Locality: Data near recently accessed data is likely to be accessed soon. This justifies fetching contiguous blocks (cache lines). Example: Ensuring GPU thread warps perform coalesced memory accesses to contiguous global memory addresses.

Algorithms and data structures must be designed to maximize both forms of locality.

04

Management & Coherency

Different hierarchy levels have distinct management models:

  • Hardware-Managed Caches (L1/L2): Transparent to software. Use cache coherency protocols (like MESI) in CPU systems to keep multiple cores' views of memory consistent. GPUs often use simpler, non-coherent caches for scalability.
  • Software-Managed Caches (Shared Memory): Programmer explicitly controls data movement (load/store). Offers predictable, low-latency access but requires careful design to avoid bank conflicts.
  • Unified Virtual Memory (UVM): Presents a single address space across CPU and GPU memory. Hardware/OS manages page migration and demand paging via GPU page faults, simplifying programming but adding overhead.
  • Peer-to-Peer (P2P): GPUs with NVLink can access each other's memory directly, creating a faster tier for multi-GPU communication than going through host memory.
05

Hierarchy in Modern GPU Architectures

A concrete example using NVIDIA's Hopper architecture:

  1. Registers: Fastest, private to each thread.
  2. L1 Cache / Shared Memory: 256 KB per Streaming Multiprocessor (SM). Configurable split (e.g., 128 KB L1 / 128 KB Shared).
  3. L2 Cache: Unified 50 MB cache shared across all SMs, servicing all memory traffic.
  4. HBM2e/HBM3 (Global Memory): 80-140 GB capacity, 2-3 TB/s bandwidth. Connected via ultra-wide memory interfaces.
  5. Host Memory (DDR): Accessed via PCIe or NVLink. Acts as a swapping pool for GPU memory oversubscription.
  6. NVMe Storage: Accessed via GPU Direct Storage (GDS), bypassing the CPU for direct loads into GPU memory.

Techniques like memory tiering aim to automate optimal data placement across this stack.

06

Optimization Implications

Understanding the hierarchy drives key optimization strategies:

  • Kernel Design: Structure computations to fit working sets in L1/Shared Memory, use coalesced accesses for global memory.
  • Memory Allocation: Use memory pools and stream-ordered allocators to reduce fragmentation and allocation overhead.
  • Data Transfer: Minimize host-device transfers, use pinned memory for bandwidth, leverage zero-copy or UVM where appropriate.
  • Model Optimization: Quantization and pruning directly reduce the model's footprint, allowing it to fit in faster memory tiers (e.g., keeping a full model in HBM vs. swapping).
  • System Configuration: Enabling Huge Pages reduces TLB misses, improving address translation performance for large memory workloads.

Failure to optimize leads to the processor being memory-bound, stalling while waiting for data.

ARCHITECTURE

Memory Hierarchy in GPU & AI Accelerators

Memory hierarchy is the structured organization of memory subsystems into multiple levels, each with distinct performance characteristics, to optimize data locality and throughput for parallel computing workloads.

A memory hierarchy organizes storage into tiers—from small, fast registers and shared memory to larger, slower global memory (HBM/GDDR) and host RAM. This structure is fundamental to GPU and AI accelerator architecture, designed to hide latency by keeping frequently used data close to compute units. Efficient data movement between these tiers, governed by access patterns and hardware scheduling, is critical for achieving peak FLOPS and memory bandwidth in parallel workloads like neural network inference and training.

Key optimization targets within this hierarchy include achieving coalesced memory access to global memory to maximize bandwidth, minimizing bank conflicts in shared memory, and leveraging caches (L1/L2) effectively. Advanced systems employ unified virtual memory and memory tiering to create a seamless address space across CPU and GPU, enabling techniques like demand paging and page migration to manage capacity. The hierarchy's design directly dictates kernel performance, influencing strategies for kernel fusion and memory pool management to reduce allocation overhead and fragmentation.

LATENCY & BANDWIDTH COMPARISON

Typical GPU Memory Hierarchy Levels

This table compares the key characteristics of the primary memory tiers within a modern GPU architecture, illustrating the trade-off between capacity, latency, and bandwidth that underpins optimization strategies for inference workloads.

Memory TierTypical CapacityTypical Latency (Cycles)Typical BandwidthManaged ByPrimary Use Case

Registers

< 1 KB per thread

1

10 TB/s

Compiler

Thread-local variables and operands

Shared Memory / L1 Cache

16-192 KB per SM

20-30

3 TB/s

Programmer / Hardware

Intra-block communication, software-managed cache

L2 Cache

20-80 MB per GPU

200-300

3-5 TB/s

Hardware

Global data reuse across SMs, coalescing buffer

High Bandwidth Memory (HBM)

16-120 GB per GPU

400-600

1-3 TB/s

Hardware / Driver

Primary workspace for model weights, activations, and KV cache

Unified Memory (CPU RAM)

System Dependent (e.g., 512 GB)

1000

25-100 GB/s (over PCIe)

Driver / OS (UVM)

Oversubscribed data, spillover from device memory

Storage (NVMe SSD)

System Dependent (e.g., 4 TB)

1,000,000

3-7 GB/s

OS / GDS

Checkpoint loading, extreme oversubscription backing store

MEMORY HIERARCHY

Frequently Asked Questions

Memory hierarchy organizes a system's memory into multiple levels with different speeds, capacities, and costs, optimizing for data locality and overall performance. In GPU computing, this concept is critical for managing the trade-offs between latency, bandwidth, and capacity across registers, caches, and various types of DRAM.

A memory hierarchy is the organization of memory subsystems in a computing system into multiple levels—such as registers, shared memory, L1/L2 cache, and global memory—with differing capacities, latencies, and bandwidths, optimized for data locality. For GPUs, it is critically important because it directly dictates the performance and scalability of parallel workloads. The massive parallelism of GPUs requires feeding thousands of threads with data; a well-managed hierarchy ensures that frequently accessed data resides in fast, low-latency memory (like caches or shared memory), while larger datasets reside in higher-capacity but slower global memory. Efficient use of this hierarchy minimizes stalls and is fundamental to achieving peak FLOPS (Floating-Point Operations Per Second) and memory bandwidth.

Key GPU memory levels, from fastest/smallest to slowest/largest, typically include:

  • Registers: Private to each thread, ultra-low latency.
  • Shared Memory / L1 Cache: Shared within a thread block, software-managed for explicit data reuse.
  • L2 Cache: Shared across all Streaming Multiprocessors (SMs) on the GPU, hardware-managed.
  • Global Memory (HBM/GDDR): The main GPU DRAM, high bandwidth but higher latency.
  • Unified Memory (System RAM/SSD): Accessed via UVM (Unified Virtual Memory) as a slower, capacity-backed tier.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.