6.2.7GPU Architecture

Memory hierarchy (global, shared, registers)

2,924 words13 min readdifficulty · medium

Overview

GPU memory hierarchy trades off capacity for speed, organizing storage into three main levels: registers (fastest, smallest), shared memory (medium speed, small), and global memory (slowest, largest). Understanding this hierarchy is critical for GPU performance because memory access latency can be 100-1000× longer than computation.

Figure — Memory hierarchy (global, shared, registers)

Core Concepts


1. Registers

Key Properties:

  • Latency: ~1 clock cycle
  • Capacity: 32-256 KB per SM (divided among all active threads)
  • Scope: Private to a single thread
  • Allocation: Automatic (compiler assigns local variables to registers)

2. Shared Memory

Key Properties:

  • Latency: ~30-100 clock cycles (roughly ~4-13× faster than global memory)
  • Capacity: 16-96 KB per SM (configurable, often reconfigurable with L1 cache on modern architectures)
  • Scope: Shared within a thread block
  • Access pattern: Organized into banks (typically 32 banks, 4-byte width)

3. Global Memory

Key Properties:

  • Latency: 400-800 clock cycles
  • Capacity: GBs (e.g., 8-80 GB on modern GPUs)
  • Scope: Global across entire device
  • Bandwidth: 200-1000 GB/s (high throughput but high latency)

Memory Hierarchy Summary Table

| Level | Latency (cycles) | Size | Scope | Managed By | |-------|------------------|-------|------------| | Registers | 1 | 32-256 KB/SM | Per-thread | Compiler | | Shared Memory | 30-100 | 16-96 KB/SM | Per-block | Programmer | | L1 Cache | 30-100 | 16-128 KB/SM | Per-SM | Hardware | | L2 Cache | ~200 | 0.5-6 MB | Global | Hardware | | Global Memory | 400-800 | GB | Global | Programmer |


Common Mistakes & Misconceptions


Recall Feynman Explanation (Explain to a 12-Year-Old)

Imagine you're doing homework and need to look up information:

Your desk (registers): The paper you're writing on and the pencil in your hand. Super fast to use - you don't even have to reach. But there's only room for one or two sheets.

Your backpack (shared memory): Books and notes you brought to your desk. Takes a second to grab, but way faster than walking across the room. You and your friends working on the same group project can share what's in one backpack.

The bookshelf (global memory): Across the room. Takes 10 seconds to walk there and back. But it holds hundreds of books.

The smart strategy: When you start a new problem, walk to the bookshelf ONCE, grab everything you need, stuff it in your backpack, and pull what you're actively using onto your desk. If you walk to the bookshelf for every single sentence you write, you'll spend all day walking and no time actually working.

That's exactly what GPUs do! They move data from slow global memory → fast shared memory → super-fast registers, and reuse it as much as possible at each level before going back for more.



Connections

  • GPU Thread Hierarchy - Thread blocks determine shared memory scope
  • Warp Execution Model - Memory coalescing depends on warp-level access patterns
  • Cache Architecture - L1/L2 caches complement the explicit hierarchy
  • Memory Bandwidth Optimization - Techniques to maximize throughput at each level
  • CUDA Memory Types - Software abstractions (constant, texture memory)
  • Memory Latency Hiding - Why occupancy matters for performance
  • Matrix Multiplication Optimization - Classic case study using all three levels
  • Roofline Model - Analyzing memory vs compute bottlenecks

Flashcards

What are the three main levels of GPU memory hierarchy from fastest to slowest?
Registers (per-thread, ~1 cycle), Shared Memory (per-block, ~30-100 cycles), Global Memory (device-wide, ~400-800 cycles).
What determines how many threads can run concurrently on an SM?
Register usage per thread (occupancy = total_registers / (threads × registers_per_thread)) and other limits like shared memory and thread block size.
What is a bank conflict in shared memory?
When multiple threads in a warp access different addresses that map to the same memory bank, causing accesses to serialize and increasing latency by the number of conflicts.
How does shared memory enable performance optimization?
By allowing threads in a block to cooperatively load data from slow global memory once, then reuse it multiple times from fast shared memory, reducing global memory traffic.
What is memory coalescing?
When consecutive threads in a warp access consecutive memory addresses, allowing the GPU to combine requests into a single wide memory transaction instead of multiple narrow ones.
Why does using many registers per thread hurt performance?
High register usage reduces occupancy (fewer concurrent threads), which reduces the GPU's ability to hide memory latency by switching between threads.
What is the scope of shared memory?
Per thread block - only threads within the same block can access the same shared memory, and data is not visible across different blocks.
Approximately how much faster is shared memory than global memory in latency terms?
Roughly 4-13× faster (~30-100 cycles for shared vs ~400-800 cycles for global), not 100×.
What is the typical size difference between registers and global memory?
Registers: ~100 KB per SM, Global memory: tens of GB - roughly 100,000× larger capacity with 400-800× higher latency.

Concept Map

governed by

motivated by

fastest smallest

medium speed

slowest largest

private per-thread in SM

more registers per thread

enables

solves

fast memory is expensive

GPU Memory Hierarchy

Capacity vs Speed Tradeoff

Memory Latency 100-1000x compute

Registers

Shared Memory

Global Memory

Register Pressure

Occupancy

Latency Hiding

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho beta, is GPU memory hierarchy ka core idea bahut simple hai — jaise kitchen mein aap cooking karte ho. Aapki pantry (global memory) sabse badi hai lekin wahan tak jaana time leta hai, counter par rakhi cheezein (shared memory) medium fast hain, aur jo cheez aapke haath mein hai (registers) woh instant use ho jaati hai. GPU mein bhi bilkul yahi funda hai — teen levels of memory jahan speed aur capacity ke beech tradeoff hota hai. Registers sabse fast (1 clock cycle) par sabse chhote, shared memory medium, aur global memory sabse bada par sabse slow (100-1000x zyada latency). Yeh baat samajhna isliye zaroori hai kyunki data ko move karna computation se 100 guna zyada mehenga hota hai.

Ab yahan asli game hai occupancy ka. GPU memory latency ko chhupata hai by switching between threads — matlab jab ek thread memory ka wait kar raha hota hai, GPU dusre thread pe kaam karta hai. Lekin har thread ko kuch registers chahiye hote hain, aur SM ka register budget fixed hota hai (jaise 65,536). Agar har thread zyada registers use karega, toh kam threads ek saath chal paayenge, aur GPU latency ko theek se hide nahi kar paayega — performance gir jaayegi. Isiliye example mein dekha ki 40 registers/thread se 75% occupancy mili, par agar 32 registers/thread kar dein toh 100% occupancy milti hai. Chhoti si register saving bhi bada farak laa sakti hai.

Practical life mein iska matlab yeh hai ki jab aap GPU code likhoge (jaise CUDA), toh aapko soch-samajh ke decide karna padega ki kaunsa data kahaan rakhna hai. Frequently-used data ko registers ya shared memory mein rakho, aur shared memory use karte waqt bank conflicts se bacho taaki access parallel rahe. Yeh intuition aapko fast, efficient GPU programs likhne mein help karega — jo aaj machine learning, graphics, aur scientific computing sab jagah kaam aata hai. Basically, memory hierarchy samajhna hi GPU performance ka asli secret hai.

Go deeper — visual, from zero

Test yourself — GPU Architecture

Connections