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.
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.
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.
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.