ECE 5755: Modern Computer Systems and Architecture
Lecture 10: Memory Hierarchy
Lynn Ann Conway, an American computer scientist, electrical engineer, and transgender activist, invested generalized dynamic instruction handling, a key advanced in out-of-order execution. Her work was also instrumental in VLSI chip design and electronic design automation.
Today’s agenda
Photos, illustrations, graphics here.
Memory Hierarchy Design
Smaller, fast expensive memory close to the core (Cache, $)
Larger, slower, cheaper memory farther away
Photos, illustrations, graphics here.
Memory Wall in Modern GPUs
AI and Memory Wall. Gholami et. al. https://arxiv.org/pdf/2403.14123
Since the plot ended: HBM bandwidth per GPU
GPU (year) | Memory | TB/s |
H100 (2022) | HBM3 | 3.35 |
MI300X (2023) | HBM3 | 5.3 |
B200 (2024) | HBM3e | 8 |
MI355X (2025) | HBM3e | 8 |
Rubin (2026) | HBM4 | 22 |
Peak FLOPS grew faster still: H100 ≈ 2 PF (FP8) → B200 ≈ 9 PF (FP4) → Rubin 50 PF (NVFP4).
Machine balance keeps rising: ≈ 590 → 1,100 → 2,300 FLOP per byte of HBM.
Photos, illustrations, graphics here.
What do we put in smaller, faster memories?
Photos, illustrations, graphics here.
Knowing that You Found It: Tags
0
1
1021
1022
1023
2
3
[4:0]
tag [31:15]
data
index [14:5]
<<
address
=
hit?
wordlines
Photos, illustrations, graphics here.
How do caches work?
Photos, illustrations, graphics here.
Functional view of caches
# find frame(s)
If (look up tag != stored tag) {
# miss
Evict block in frame
Replace block from memory (or next level in memory hierarchy)
}
Return memory corresponding to lookup address
Photos, illustrations, graphics here.
Direct mapped cache
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
Photos, illustrations, graphics here.
Direct mapped cache
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| |
| |
| |
| |
0: Miss
00 | Mem(0) |
00 | Mem(1) |
00 | Mem(2) |
00 | Mem(3) |
4: Miss
00 | Mem(0) |
| |
| |
| |
1: Miss
01 | Mem(4) |
00 | Mem(1) |
00 | Mem(2) |
00 | Mem(3) |
3: Hit
00 | Mem(0) |
00 | Mem(1) |
| |
| |
2: Miss
01 | Mem(4) |
00 | Mem(1) |
00 | Mem(2) |
00 | Mem(3) |
4: Hit
00 | Mem(0) |
00 | Mem(1) |
00 | Mem(2) |
| |
3: Miss
01 | Mem(4) |
00 | Mem(1) |
00 | Mem(2) |
00 | Mem(3) |
15: Miss
01
Mem(4)
11
Mem(15)
References: 8
Misses: 6
Hits: 2
Photos, illustrations, graphics here.
The architecture of a direct mapped cache
What locality are we exploiting?
Photos, illustrations, graphics here.
Handling cache hits
Read hits (I$ and D$) – this is what we want!
Photos, illustrations, graphics here.
Write-through caching
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
00 | Mem(0) |
| |
| |
| |
0: Miss
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
| |
| |
| |
| |
0: Miss
00 | Mem(0) |
| |
| |
| |
4: Miss
01
Mem(4)
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
| |
| |
| |
| |
0: Miss
00 | Mem(0) |
| |
| |
| |
4: Miss
01 | Mem(4) |
| |
| |
| |
0: Miss
00
Mem(0)
01
Mem(4)
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
| |
| |
| |
| |
0: Miss
00 | Mem(0) |
| |
| |
| |
4: Miss
01 | Mem(4) |
| |
| |
| |
0: Miss
00 | Mem(0) |
| |
| |
| |
4: Miss
00
Mem(0)
01
Mem(4)
01
Mem(4)
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
| |
| |
| |
| |
0: Miss
01 | Mem(4) |
| |
| |
| |
0: Miss
00 | Mem(0) |
| |
| |
| |
4: Miss
00 | Mem(0) |
| |
| |
| |
4: Miss
01 | Mem(4) |
| |
| |
| |
0: Miss
01 | Mem(4) |
| |
| |
| |
0: Miss
00 | Mem(0) |
| |
| |
| |
4: Miss
00 | Mem(0) |
| |
| |
| |
4: Miss
00
Mem(0)
00
Mem(0)
00
Mem(0)
01
Mem(4)
01
Mem(4)
01
Mem(4)
01
Mem(4)
References: 8
Misses: 8
Hits:0
Photos, illustrations, graphics here.
What types of misses do we have in caches?
Photos, illustrations, graphics here.
Handling Cache Misses
or (in write back caches…)
Or (in write-through caches with a write buffer)
Photos, illustrations, graphics here.
How do we exploit spatial locality?
Photos, illustrations, graphics here.
How do we exploit spatial locality?
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
References: 8
Misses:4
Hits:4
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
00 | Mem(1) | Mem(0) |
| | |
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
00 | Mem(1) | Mem(0) |
| | |
1: Hit
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
00 | Mem(1) | Mem(0) |
| | |
1: Hit
00 | Mem(1) | Mem(0) |
| | |
2: Miss
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
00 | Mem(1) | Mem(0) |
| | |
1: Hit
00 | Mem(1) | Mem(0) |
| | |
2: Miss
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
00 | Mem(1) | Mem(0) |
| | |
1: Hit
00 | Mem(1) | Mem(0) |
| | |
2: Miss
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
3: Hit
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
01
Mem(5)
00 | Mem(1) | Mem(0) |
| | |
1: Hit
00 | Mem(1) | Mem(0) |
| | |
2: Miss
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
3: Hit
4: Miss
Mem(4)
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
01
Mem(5)
00 | Mem(1) | Mem(0) |
| | |
1: Hit
00 | Mem(1) | Mem(0) |
| | |
2: Miss
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
3: Hit
4: Miss
01 | Mem(5) | Mem(4) |
00 | Mem(3) | Mem(2) |
3: Hit
Mem(4)
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
01
Mem(5)
00 | Mem(1) | Mem(0) |
| | |
1: Hit
00 | Mem(1) | Mem(0) |
| | |
2: Miss
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
3: Hit
4: Miss
01 | Mem(5) | Mem(4) |
00 | Mem(3) | Mem(2) |
3: Hit
01 | Mem(5) | Mem(4) |
00 | Mem(3) | Mem(2) |
4: Hit
Mem(4)
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
01
Mem(5)
00 | Mem(1) | Mem(0) |
| | |
1: Hit
00 | Mem(1) | Mem(0) |
| | |
2: Miss
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
3: Hit
4: Miss
01 | Mem(5) | Mem(4) |
00 | Mem(3) | Mem(2) |
3: Hit
01 | Mem(5) | Mem(4) |
00 | Mem(3) | Mem(2) |
4: Hit
01 | Mem(5) | Mem(4) |
00 | Mem(3) | Mem(2) |
15: Miss
Mem(4)
11
Mem(15)
Mem(14)
Photos, illustrations, graphics here.
Taking advantage of spatial locality…
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
0 | 1 | 2 | 3 | 4 | 3 | 4 | 15 |
| | |
| | |
0: Miss
01
Mem(5)
References: 8
Misses:4
Hits:4
Before it was
6 misses + 2 hits
00 | Mem(1) | Mem(0) |
| | |
1: Hit
00 | Mem(1) | Mem(0) |
| | |
2: Miss
00 | Mem(1) | Mem(0) |
00 | Mem(3) | Mem(2) |
3: Hit
4: Miss
01 | Mem(5) | Mem(4) |
00 | Mem(3) | Mem(2) |
3: Hit
01 | Mem(5) | Mem(4) |
00 | Mem(3) | Mem(2) |
4: Hit
01 | Mem(5) | Mem(4) |
00 | Mem(3) | Mem(2) |
15: Miss
Mem(4)
11
Mem(15)
Mem(14)
Photos, illustrations, graphics here.
Block size tradeoffs
Photos, illustrations, graphics here.
Multi-word block considerations
Photos, illustrations, graphics here.
Multi-word block considerations
Photos, illustrations, graphics here.
Multi-word block considerations
Photos, illustrations, graphics here.
Multi-word block considerations
Photos, illustrations, graphics here.
Cache Summary
Photos, illustrations, graphics here.
Cache Summary
Photos, illustrations, graphics here.
Cache Summary
Photos, illustrations, graphics here.
Reducing cache miss rates (part 1)
(block address) modulo (# sets in the cache)
Photos, illustrations, graphics here.
Set associative cache
0
Cache
Q2: How do we find it?
Use next 1 low order memory address bit to determine which cache set (i.e., modulo the number of sets in the cache)
Tag
Data
Q1: Is it there?
Compare all the cache tags in the set to the high order 3 memory address bits to tell if the memory block is in the cache
V
0000xx
0001xx
0010xx
0011xx
0100xx
0101xx
0110xx
0111xx
1000xx
1001xx
1010xx
1011xx
1100xx
1101xx
1110xx
1111xx
Two low order bits define the byte in the word (32-b words)
One word blocks
Set
1
0
1
Way
0
1
Photos, illustrations, graphics here.
Set associative cache
0
Cache
Q2: How do we find it?
Use next 1 low order memory address bit to determine which cache set (i.e., modulo the number of sets in the cache)
Tag
Data
Q1: Is it there?
Compare all the cache tags in the set to the high order 3 memory address bits to tell if the memory block is in the cache
V
0000xx
0001xx
0010xx
0011xx
0100xx
0101xx
0110xx
0111xx
1000xx
1001xx
1010xx
1011xx
1100xx
1101xx
1110xx
1111xx
Two low order bits define the byte in the word (32-b words)
One word blocks
Set
1
0
1
Way
0
1
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
| |
| |
| |
| |
0: Miss
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
| |
| |
| |
| |
0: Miss
4: Miss
000 | Mem(0) |
| |
010 | Mem(4) |
| |
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
| |
| |
| |
| |
0: Miss
4: Miss
000 | Mem(0) |
| |
010 | Mem(4) |
| |
0: Hit
000 | Mem(0) |
| |
010 | Mem(4) |
| |
Photos, illustrations, graphics here.
Lets look at another case…
0 | 4 | 0 | 4 | 0 | 4 | 0 | 4 |
| |
| |
| |
| |
0: Miss
4: Miss
000 | Mem(0) |
| |
010 | Mem(4) |
| |
0: Hit
000 | Mem(0) |
| |
010 | Mem(4) |
| |
4: Hit
000 | Mem(0) |
| |
010 | Mem(4) |
| |
References: 8
Misses: 2
Hits:6
(Before 8 misses)
Photos, illustrations, graphics here.
Four-way set associative cache
Photos, illustrations, graphics here.
Four-way set associative cache
Block offset
Byte offset
Index
Tag
Decreasing associativity
Fully associative
(only one set)
Tag is all the bits except
block and byte offset
Direct mapped
(only one way)
Smaller tags
Increasing associativity
Selects the set
Used for tag compare
Selects the word in the block
Photos, illustrations, graphics here.
Costs of associative caches
Photos, illustrations, graphics here.
Summary of Associativity
Photos, illustrations, graphics here.
Reducing Cache Miss Rates (part 2)
Use multiple levels of caches
Quiz # 1: CPIideal of 2, 100 cycle miss penalty (to main memory), 36% load/stores, a 2% (4%) L1I$ (D$) miss rate, add a UL2$ that has a 25 cycle miss penalty and a 0.5% miss rate
Photos, illustrations, graphics here.
Reducing Cache Miss Rates (part 2)
Use multiple levels of caches
CPIstalls = 2 + .02×25 + .36×.04×25 + .005×100 + .36×.005×100 = 3.54 (as compared to 5.44 with no L2$)
Photos, illustrations, graphics here.
Multi-level Cache Design Optimization
Photos, illustrations, graphics here.
Cache design parameters
| L1 (per core) | L2 (per core) | L3 / LLC (shared) |
Total size | 32–192 KB (I$ 32–192 KB; D$ 32–128 KB) | 1–3 MB (private) | 8–128 MB per die; up to 512 MB per socket (EPYC) |
Total size (64 B blocks) | 512 – 3,000 | 16 K – 48 K | 128 K – 2 M |
Block size (B) | 64 (128 on Apple, POWER, GPUs) | 64 | 64 |
Associativity | 4- to 12-way | 8- to 16-way | 12- to 16-way |
Hit time | 3–5 cycles (~1 ns) | 10–17 cycles (~3 ns) | 40–90 cycles (~10–20 ns) |
Miss penalty (to next level) | 10–17 cycles (L2 hit) | 40–90 cycles (L3 hit) | 300–500 cycles ≈ 80–100 ns (DRAM) |
Miss rate | 2–5% (local) | 0.1–2% (global) | Workload-dependent: ≈0 if the working set fits … ≈100% for streaming (e.g., LLM decode) |
Write policy | Write-back (GPU L1: write-through to L2) | Write-back | Write-back; often an L2 victim cache (AMD) |
Ranges span 2023–25 CPUs: AMD Zen 4/5, Intel Lion Cove, Arm Neoverse V2 (NVIDIA Grace), Apple M-series. Cycle counts assume ~4–5 GHz cores; DRAM latency is roughly constant in ns, so it grows in cycles as clocks rise.
Photos, illustrations, graphics here.
Example Machine Cache Designs
| Intel Pentium 4 (2004) | AMD Zen 5 (2024) | Intel Lion Cove (2024) | Arm Neoverse V2 / NVIDIA Grace (2023) |
L1 organization | Split I$ and D$ (trace cache ≈ I$) | Split I$ and D$ | Split I$ and D$; D$ has two levels ("L0" + "L1") | Split I$ and D$ |
L1 cache size | 8 KB D$; 96 KB trace cache | 32 KB I$; 48 KB D$ | 64 KB I$; 48 KB L0 D$ + 192 KB L1 D$ | 64 KB I$; 64 KB D$ |
L1 block size | 64 B | 64 B | 64 B | 64 B |
L1 associativity | 4-way | 8-way I$; 12-way D$ | 16-way I$; 12-way L0 D$; 12-way L1 D$ | 4-way I$; 4-way D$ |
L1 replacement | ~LRU | LRU (I$); D$ not disclosed | Not disclosed | Pseudo-LRU |
L1 write policy | Write-through | Write-back | Write-back | Write-back |
L1 D$ hit latency | 2 cycles | 4 cycles | 4 cycles (L0); 9 cycles (L1) | 4 cycles |
L2 organization | Unified | Unified, private per core | Unified, private per core | Unified, private per core |
L2 cache size | 512 KB | 1 MB | 2.5 MB (Lunar Lake) / 3 MB (Arrow Lake) | 1 MB (Grace); 2 MB option |
L2 block size | 128 B | 64 B | 64 B | 64 B |
L2 associativity | 8-way | 16-way | 10-way | 8-way |
L2 replacement | ~LRU | Not disclosed | Not disclosed | "Dynamic biased" (Arm TRM) |
L2 write policy | Write-back | Write-back; inclusive of L1 | Write-back | Write-back; inclusive of L1 |
L2 hit latency | ~16 cycles | 14 cycles | 17 cycles | ~10 cycles |
L3 (shared) | None | 32 MB per 8-core CCD, 16-way, filled by L2 victims (mostly exclusive), ~46 cycles; 96–128 MB with 3D V-Cache | 12 MB (3 MB slice per core), 12-way, 51–84 cycles | 114 MB system-level cache shared by 72 cores |
Sources: AMD Zen 4/Zen 5 Software Optimization Guides & Hot Chips 2024; Intel Lion Cove disclosures (Computex 2024) and Chips and Cheese measurements; Arm Neoverse V2 TRM; NVIDIA Grace/Vera documentation. Latencies are load-to-use, in core cycles.
Photos, illustrations, graphics here.
Questions of memory hiearchies
Photos, illustrations, graphics here.
Q3: Which block should be replaced on a miss?
Photos, illustrations, graphics here.
Q1/Q2: Where can block be placed/found?
| # of sets | Blocks per set |
Direct mapped | # of blocks in cache | 1 |
Set associative | (# of blocks in cache)/ associativity | Associativity (typically 2 to 16) |
Fully associative | 1 | # of blocks in cache |
| Location method | # of comparisons |
Direct mapped | Index | 1 |
Set associative | Index the set; compare set’s tags | Degree of associativity |
Fully associative | Compare all blocks tags | # of blocks |
Photos, illustrations, graphics here.
Q4: What happens on a write?
Photos, illustrations, graphics here.
More detailed questions…
Photos, illustrations, graphics here.
Block Placement + ID
Photos, illustrations, graphics here.
Block replacement
Photos, illustrations, graphics here.
Write Policies
Photos, illustrations, graphics here.
Write hit policies
Photos, illustrations, graphics here.
Write Hit Policies
Photos, illustrations, graphics here.
Write buffers
CPU
Cache
Write Buffer
Lower Levels of Memory
Photos, illustrations, graphics here.
Write buffers
Address| Data
Address| Data
Tag
Store Op
Data
Data Cache
Write Buffer
Entry
Photos, illustrations, graphics here.
Write buffer policies: performance/complexity tradeoffs
Stores
L2 Cache
Loads
Photos, illustrations, graphics here.
Write misses?
Photos, illustrations, graphics here.
Summary of Write Policies
Write Policy | Hit/Miss | Writes to |
WriteBack/Allocate | Both | L1 Cache |
WriteBack/NoAllocate | Hit | L1 Cache |
WriteBack/NoAllocate | Miss | L2 Cache |
WriteThrough/Allocate | Both | Both |
WriteThrough/NoAllocate | Hit | Both |
WriteThrough/NoAllocate | Miss | L2 Cache |
Photos, illustrations, graphics here.
Cache Performance
CPU time = (CPU execution cycles + Memory Stall Cycles)*Clock Cycle Time
AMAT = Hit Time + Miss Rate * Miss Penalty
Photos, illustrations, graphics here.
Reducing Miss Penalty
Photos, illustrations, graphics here.
Logistics
Photos, illustrations, graphics here.