Five memory spaces, very different speeds
On a GPU the word "memory" hides a hierarchy spanning ~3 orders of magnitude in latency. A kernel can see:
- Registers — per-thread, on-chip, ~1 cycle.
- Shared memory — per-block, on-chip, ~20-30 cycles.
- L1/L2 cache — automatic, ~30/200 cycles.
- Constant memory — read-only, broadcast-optimised, cached.
- Global memory — device-wide VRAM, ~400-800 cycles.
- Local memory — per-thread but physically in global memory.
The whole performance-tuning game on GPUs is: keep hot data in fast tiers, touch global memory as little as possible, and make the global accesses you can't avoid look the way the hardware likes.
