Lecture 16: Memory Hierarchy Misses, 3 Cs and 7 Ways to Reduce Misses Professor Randy H. Katz Computer Science 252 Spring 1996

Similar documents
Lecture 16: Memory Hierarchy Misses, 3 Cs and 7 Ways to Reduce Misses. Professor Randy H. Katz Computer Science 252 Fall 1995

Memory Cache. Memory Locality. Cache Organization -- Overview L1 Data Cache

Lecture 11 Reducing Cache Misses. Computer Architectures S

Improving Cache Performance. Reducing Misses. How To Reduce Misses? 3Cs Absolute Miss Rate. 1. Reduce the miss rate, Classifying Misses: 3 Cs

Lecture 9: Improving Cache Performance: Reduce miss rate Reduce miss penalty Reduce hit time

DECstation 5000 Miss Rates. Cache Performance Measures. Example. Cache Performance Improvements. Types of Cache Misses. Cache Performance Equations

Memory Hierarchy 3 Cs and 6 Ways to Reduce Misses

Improving Cache Performance. Dr. Yitzhak Birk Electrical Engineering Department, Technion

Types of Cache Misses: The Three C s

Cache Memory: Instruction Cache, HW/SW Interaction. Admin

Classification Steady-State Cache Misses: Techniques To Improve Cache Performance:

Lecture 7: Memory Hierarchy 3 Cs and 7 Ways to Reduce Misses Professor David A. Patterson Computer Science 252 Fall 1996

Lec 12 How to improve cache performance (cont.)

NOW Handout Page 1. Review: Who Cares About the Memory Hierarchy? EECS 252 Graduate Computer Architecture. Lec 12 - Caches

CPE 631 Lecture 06: Cache Design

Aleksandar Milenkovich 1

CMSC 611: Advanced Computer Architecture. Cache and Memory

Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier

Cache performance Outline

Computer Architecture Spring 2016

CISC 662 Graduate Computer Architecture Lecture 18 - Cache Performance. Why More on Memory Hierarchy?

NOW Handout Page # Why More on Memory Hierarchy? CISC 662 Graduate Computer Architecture Lecture 18 - Cache Performance

Aleksandar Milenkovich 1

Topics. Digital Systems Architecture EECE EECE Need More Cache?

Chapter 5. Topics in Memory Hierachy. Computer Architectures. Tien-Fu Chen. National Chung Cheng Univ.

CS/ECE 250 Computer Architecture

CS422 Computer Architecture

Copyright 2012, Elsevier Inc. All rights reserved.

EITF20: Computer Architecture Part 5.1.1: Virtual Memory

EITF20: Computer Architecture Part4.1.1: Cache - 2

Memory Hierarchy Design. Chapter 5

Advanced optimizations of cache performance ( 2.2)

CSE 502 Graduate Computer Architecture

EITF20: Computer Architecture Part 5.1.1: Virtual Memory

Cache Performance! ! Memory system and processor performance:! ! Improving memory hierarchy performance:! CPU time = IC x CPI x Clock time

Chapter-5 Memory Hierarchy Design

Announcements. ! Previous lecture. Caches. Inf3 Computer Architecture

Cache Performance! ! Memory system and processor performance:! ! Improving memory hierarchy performance:! CPU time = IC x CPI x Clock time

5008: Computer Architecture

Graduate Computer Architecture. Handout 4B Cache optimizations and inside DRAM

Levels in a typical memory hierarchy

CSE 502 Graduate Computer Architecture. Lec Advanced Memory Hierarchy

Lecture 11. Virtual Memory Review: Memory Hierarchy

CSE 502 Graduate Computer Architecture. Lec Advanced Memory Hierarchy and Application Tuning

L2 cache provides additional on-chip caching space. L2 cache captures misses from L1 cache. Summary

Q3: Block Replacement. Replacement Algorithms. ECE473 Computer Architecture and Organization. Memory Hierarchy: Set Associative Cache

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

Graduate Computer Architecture. Handout 4B Cache optimizations and inside DRAM

! 11 Advanced Cache Optimizations! Memory Technology and DRAM optimizations! Virtual Machines

Memory Hierarchy Motivation, Definitions, Four Questions about Memory Hierarchy

Cache Performance (H&P 5.3; 5.5; 5.6)

Outline. 1 Reiteration. 2 Cache performance optimization. 3 Bandwidth increase. 4 Reduce hit time. 5 Reduce miss penalty. 6 Reduce miss rate

Lecture 13: Memory Systems -- Cache Op7miza7ons CSE 564 Computer Architecture Summer 2017

The memory gap. 1980: no cache in µproc; level cache on Alpha µproc

EITF20: Computer Architecture Part4.1.1: Cache - 2

Lecture 19: Memory Hierarchy Five Ways to Reduce Miss Penalty (Second Level Cache) Admin

COSC4201. Chapter 4 Cache. Prof. Mokhtar Aboelaze York University Based on Notes By Prof. L. Bhuyan UCR And Prof. M. Shaaban RIT

COSC4201. Chapter 5. Memory Hierarchy Design. Prof. Mokhtar Aboelaze York University

Recap: The Big Picture: Where are We Now? The Five Classic Components of a Computer. CS152 Computer Architecture and Engineering Lecture 20.

CS 2461: Computer Architecture 1

Caching Basics. Memory Hierarchies

Memory Hierarchies 2009 DAT105

Performance (1/latency) Capacity Access Time Cost. CPU Registers 100s Bytes <1 ns. Cache K Bytes M Bytes 1-10 ns.01 cents/byte

Outline. EECS 252 Graduate Computer Architecture. Lec 16 Advanced Memory Hierarchy. Why More on Memory Hierarchy? Review: 6 Basic Cache Optimizations

COEN6741. Computer Architecture and Design

CS 252 Graduate Computer Architecture. Lecture 8: Memory Hierarchy

Lecture 18: Memory Hierarchy Main Memory and Enhancing its Performance Professor Randy H. Katz Computer Science 252 Spring 1996

LRU. Pseudo LRU A B C D E F G H A B C D E F G H H H C. Copyright 2012, Elsevier Inc. All rights reserved.

Announcements. ECE4750/CS4420 Computer Architecture L6: Advanced Memory Hierarchy. Edward Suh Computer Systems Laboratory

Memory Hierarchy Computing Systems & Performance MSc Informatics Eng. Memory Hierarchy (most slides are borrowed)

Memory Hierarchy Computing Systems & Performance MSc Informatics Eng. Memory Hierarchy (most slides are borrowed)

Page 1. Multilevel Memories (Improving performance using a little cash )

3Introduction. Memory Hierarchy. Chapter 2. Memory Hierarchy Design. Computer Architecture A Quantitative Approach, Fifth Edition

CS 152 Computer Architecture and Engineering. Lecture 8 - Memory Hierarchy-III

The Memory Hierarchy & Cache Review of Memory Hierarchy & Cache Basics (from 350):

Memory Hierarchy. Maurizio Palesi. Maurizio Palesi 1

Lecture 10 Advanced Memory Hierarchy

MEMORY HIERARCHY DESIGN. B649 Parallel Architectures and Programming

Memories. CPE480/CS480/EE480, Spring Hank Dietz.

Speicherarchitektur. Who Cares About the Memory Hierarchy? Technologie-Trends. Speicher-Hierarchie. Referenz-Lokalität. Caches

Memory Hierarchy. Slides contents from:

Review: Who Cares About the Memory Hierarchy? Processor Only Thus Far in Course: CPU cost/performance, ISA, Pipelined Execution 1000 Performance CPU

Lecture 12. Memory Design & Caches, part 2. Christos Kozyrakis Stanford University

CS222: Cache Performance Improvement

Lec 11 How to improve cache performance

COSC 6385 Computer Architecture. - Memory Hierarchies (II)

Advanced Computer Architecture- 06CS81-Memory Hierarchy Design

MEMORY HIERARCHY DESIGN

Memory Hierarchy Basics. Ten Advanced Optimizations. Small and Simple

Virtual memory why? Virtual memory parameters Compared to first-level cache Parameter First-level cache Virtual memory. Virtual memory concepts

Topics. Computer Organization CS Improving Performance. Opportunity for (Easy) Points. Three Generic Data Hazards

CS 152 Computer Architecture and Engineering. Lecture 8 - Memory Hierarchy-III

Lecture-18 (Cache Optimizations) CS422-Spring

CS 152 Computer Architecture and Engineering. Lecture 8 - Memory Hierarchy-III

Modern Computer Architecture

Advanced Caching Techniques (2) Department of Electrical Engineering Stanford University

Agenda. Cache-Memory Consistency? (1/2) 7/14/2011. New-School Machine Structures (It s a bit more complicated!)

SE-292 High Performance Computing. Memory Hierarchy. R. Govindarajan Memory Hierarchy

Reducing Miss Penalty: Read Priority over Write on Miss. Improving Cache Performance. Non-blocking Caches to reduce stalls on misses

Memory Hierarchy Basics

Transcription:

Lecture 16: Memory Hierarchy Misses, 3 Cs and 7 Ways to Reduce Misses Professor Randy H. Katz Computer Science 252 Spring 1996 RHK.S96 1

Review: Who Cares About the Memory Hierarchy? Processor Only Thus Far in Course: CPU cost/performance, ISA, Pipelined Execution 1000 CPU-DRAM Gap CPU 100 10 DRAM 1 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 1980: no cache in µproc; 1995 2-level cache, 60% trans. on Alpha 21164 µproc (150 clock cycles for a miss!) RHK.S96 2

Review: Four Questions for Memory Hierarchy Designers Q1: Where can a block be placed in the upper level? (Block placement) Fully Associative, Set Associative, Direct Mapped Q2: How is a block found if it is in the upper level? (Block identification) Tag/Block Q3: Which block should be replaced on a miss? (Block replacement) Random, LRU Q4: What happens on a write? (Write strategy) Write Back or Write Through (with Write Buffer) RHK.S96 3

Review: Cache Performance CPU time = (CPU execution clock cycles + Memory stall clock cycles) x clock cycle time Memory stall clock cycles = (Reads x Read miss rate x Read miss penalty + Writes x Write miss rate x Write miss penalty) Memory stall clock cycles = Memory accesses x Miss rate x Miss penalty RHK.S96 4

Review: Cache Performance CPUtime = IC x (CPI execution + Mem accesses per instruction x Miss rate x Miss penalty) x Clock cycle time Misses per instruction = Memory accesses per instruction x Miss rate CPUtime = IC x (CPI execution + Misses per instruction x Miss penalty) x Clock cycle time RHK.S96 5

Review: Improving Cache Performance 1. Reduce the miss rate, 2. Reduce the miss penalty, or 3. Reduce the time to hit in the cache. RHK.S96 6

Reducing Misses Classifying Misses: 3 Cs Compulsory The first access to a block is not in the cache, so the block must be brought into the cache. These are also called cold start misses or first reference misses. (Misses in Infinite Cache) Capacity If the cache cannot contain all the blocks needed during execution of a program, capacity misses will occur due to blocks being discarded and later retrieved. (Misses in Size X Cache) Conflict If the block-placement strategy is set associative or direct mapped, conflict misses (in addition to compulsory and capacity misses) will occur because a block can be discarded and later retrieved if too many blocks map to its set. These are also called collision misses or interference misses. (Misses in N-way Associative, Size X Cache) RHK.S96 7

3Cs Absolute Miss Rate Miss Rate per Type 0.14 0.12 0.1 0.08 0.06 0.04 0.02 1-way 2-way 4-way Conflict 8-way Capacity 0 1 2 4 8 16 32 64 128 Cache Size (KB) Compulsory RHK.S96 8

2:1 Cache Rule Miss Rate per Type 0.14 0.12 0.1 0.08 0.06 0.04 0.02 1-way 2-way 4-way Conflict 8-way Capacity 0 1 2 4 8 16 32 64 128 Cache Size (KB) Compulsory RHK.S96 9

3Cs Relative Miss Rate Miss Rate per Type 100% 80% 60% 40% 20% 1-way 2-way 4-way 8-way Capacity Conflict 0% 1 2 4 8 16 32 Cache Size (KB) 64 128 Compulsory RHK.S96 10

How Can Reduce Misses? Change Block Size? Which of 3Cs affected? Change Associativity? Which of 3Cs affected? Change Compiler? Which of 3Cs affected? RHK.S96 11

1. Reduce Misses via Larger Block Size 25% Miss Rate 20% 15% 10% 5% 0% 1K 4K 16K 64K 256K 16 32 64 128 256 Block Size (bytes) RHK.S96 12

2. Reduce Misses via Higher Associativity 2:1 Cache Rule: Miss Rate DM cache size N Miss Rate FA cache size N/2 Beware: Execution time is only final measure! Will Clock Cycle time increase? Hill [1988] suggested hit time external cache +10%, internal + 2% for 2-way vs. 1-way RHK.S96 13

Example: Avg. Memory Access Time vs. Miss Rate Example: assume CCT = 1.10 for 2-way, 1.12 for 4-way, 1.14 for 8-way vs. CCT direct mapped Cache Size Associativity (KB) 1-way 2-way 4-way 8-way 1 2.33 2.15 2.07 2.01 2 1.98 1.86 1.76 1.68 4 1.72 1.67 1.61 1.53 8 1.46 1.48 1.47 1.43 16 1.29 1.32 1.32 1.32 32 1.20 1.24 1.25 1.27 64 1.14 1.20 1.21 1.23 128 1.10 1.17 1.18 1.20 (Red means A.M.A.T. not improved by more associativity) RHK.S96 14

3. Reducing Misses via Victim Cache How to combine fast hit time of Direct Mapped yet still avoid conflict misses? Add buffer to place data discarded from cache Jouppi [1990]: 4-entry victim cache removed 20% to 95% of conflicts for a 4 KB direct mapped data cache RHK.S96 15

4. Reducing Misses via Pseudo- Associativity How to combine fast hit time of Direct Mapped and have the lower conflict misses of 2-way SA cache? Divide cache: on a miss, check other half of cache to see if there, if so have a pseudo-hit (slow hit) Hit Time Pseudo Hit Time Miss Penalty Time Drawback: CPU pipeline is hard if hit takes 1 or 2 cycles Better for caches not tied directly to processor RHK.S96 16

5. Reducing Misses by HW Prefetching of Instruction & Data E.g., Instruction Prefetching Alpha 21064 fetches 2 blocks on a miss Extra block placed in stream buffer On miss check stream buffer Works with data blocks too: Jouppi [1990] 1 data stream buffer got 25% misses from 4KB cache; 4 streams got 43% Palacharla & Kessler [1994] for scientific programs for 8 streams got 50% to 70% of misses from 2 64KB, 4-way set associative caches Prefetching relies on extra memory bandwidth that can be used without penalty RHK.S96 17

Data Prefetch 6. Reducing Misses by SW Prefetching Data Load data into register (HP PA-RISC loads) Cache Prefetch: load into cache (MIPS IV, PowerPC, SPARC v. 9) Special prefetching instructions cannot cause faults; a form of speculative execution Issuing Prefetch Instructions takes time Is cost of prefetch issues < savings in reduced misses? RHK.S96 18

Instructions 7. Reducing Misses by Compiler Optimizations Reorder procedures in memory so as to reduce misses Profiling to look at conflicts McFarling [1989] reduced caches misses by 75% on 8KB direct mapped cache with 4 byte blocks Data Merging Arrays: improve spatial locality by single array of compound elements vs. 2 arrays Loop Interchange: change nesting of loops to access data in order stored in memory Loop Fusion: Combine 2 independent loops that have same looping and some variables overlap Blocking: Improve temporal locality by accessing blocks of data repeatedly vs. going down whole columns or rows RHK.S96 19

Merging Arrays Example /* Before */ int val[size]; int key[size]; /* After */ struct merge { int val; int key; }; struct merge merged_array[size]; Reducing conflicts between val & key RHK.S96 20

Loop Interchange Example /* Before */ for (k = 0; k < 100; k = k+1) for (j = 0; j < 100; j = j+1) for (i = 0; i < 5000; i = i+1) x[i][j] = 2 * x[i][j]; /* After */ for (k = 0; k < 100; k = k+1) for (i = 0; i < 5000; i = i+1) for (j = 0; j < 100; j = j+1) x[i][j] = 2 * x[i][j]; Sequential accesses Instead of striding through memory every 100 words RHK.S96 21

Loop Fusion Example /* Before */ for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) a[i][j] = 1/b[i][j] * c[i][j]; for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) d[i][j] = a[i][j] + c[i][j]; /* After */ for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) { a[i][j] = 1/b[i][j] * c[i][j]; d[i][j] = a[i][j] + c[i][j];} 2 misses per access to a & c vs. one miss per access RHK.S96 22

Blocking Example /* Before */ for (i = 0; i < N; i = i+1) for (j = 0; j < N; j = j+1) {r = 0; for (k = 0; k < N; k = k+1){ r = r + y[i][k]*z[k][j];}; x[i][j] = r; }; Two Inner Loops: Read all NxN elements of z[] Read N elements of 1 row of y[] repeatedly Write N elements of 1 row of x[] Capacity Misses a function of N & Cache Size: 3 NxN => no capacity misses; otherwise... Idea: compute on BxB submatrix that fits RHK.S96 23

Blocking Example /* After */ for (jj = 0; jj < N; jj = jj+b) for (kk = 0; kk < N; kk = kk+b) for (i = 0; i < N; i = i+1) for (j = jj; j < min(jj+b-1,n); j = j+1) {r = 0; for (k = kk; k < min(kk+b-1,n); k = k+1) { r = r + y[i][k]*z[k][j];}; x[i][j] = x[i][j] + r; }; Capacity Misses from 2N 3 + N 2 to 2N 3 /B +N 2 B called Blocking Factor Conflict Misses Too? RHK.S96 24

Reducing Conflict Misses by Blocking 0.1 Miss Rate 0.05 Direct Mapped Cache 0 Blocking Factor Fully Associative Cache 0 50 100 150 Conflict misses in caches not FA vs. Blocking size Lam et al [1991] a blocking factor of 24 had a fifth the misses vs. 48 despite both fit in cache RHK.S96 25

Summary of Compiler Optimizations to Reduce Cache Misses vpenta (nasa7) gmty (nasa7) tomcatv btrix (nasa7) mxm (nasa7) spice cholesky (nasa7) compress 1 1.5 2 2.5 3 Performance Improvement merged arrays loop interchange loop fusion blocking RHK.S96 26

CPUtime = IC CPI Execution + Summary Memory accesses Instruction 3 Cs: Compulsory, Capacity, Conflict Misses Reducing Miss Rate 1. Reduce Misses via Larger Block Size 2. Reduce Misses via Higher Associativity 3. Reducing Misses via Victim Cache 4. Reducing Misses via Pseudo-Associativity 5. Reducing Misses by HW Prefetching Instr, Data 6. Reducing Misses by SW Prefetching Data 7. Reducing Misses by Compiler Optimizations Remember danger of concentrating on just one parameter when evaluating performance Next lecture: reducing Miss penalty Miss rate Miss penalty Clock cycle time RHK.S96 27