Memory Hierarchy—Improving Performance Professor Alvin R. Lebeck Computer Science 220 Fall 2008.

Slides:



Advertisements
Similar presentations
Anshul Kumar, CSE IITD CSL718 : Memory Hierarchy Cache Performance Improvement 23rd Feb, 2006.
Advertisements

Lecture 8: Memory Hierarchy Cache Performance Kai Bu
1 Adapted from UCB CS252 S01, Revised by Zhao Zhang in IASTATE CPRE 585, 2004 Lecture 14: Hardware Approaches for Cache Optimizations Cache performance.
1 COMP 206: Computer Architecture and Implementation Montek Singh Wed, Nov 2, 2005 Mon, Nov 7, 2005 Topic: Caches (contd.)
Caches Vincent H. Berk October 21, 2005
1 COMP 206: Computer Architecture and Implementation Montek Singh Wed., Nov. 10, 2003 Topic: Caches (contd.)
EE Architecture of Digital Systems Lecture 3 Cache Memory
CS252/Culler Lec 4.1 1/31/02 CS203A Graduate Computer Architecture Lecture 14 Cache Design Taken from Prof. David Culler’s notes.
EENG449b/Savvides Lec /1/04 April 1, 2004 Prof. Andreas Savvides Spring EENG 449bG/CPSC 439bG Computer.
Reducing Cache Misses (Sec. 5.3) Three categories of cache misses: 1.Compulsory –The very first access to a block cannot be in the cache 2.Capacity –Due.
Computer Architecture
EENG449b/Savvides Lec /13/04 April 13, 2004 Prof. Andreas Savvides Spring EENG 449bG/CPSC 439bG Computer.
ENGS 116 Lecture 141 Caches and Main Memory Vincent H. Berk November 5 th, 2008 Reading for Today: Sections C.4 – C.7 Reading for Wednesday: Sections 5.1.
1 COMP 206: Computer Architecture and Implementation Montek Singh Wed, Nov 9, 2005 Topic: Caches (contd.)
1 COMP 206: Computer Architecture and Implementation Montek Singh Wed., Oct. 30, 2002 Topic: Caches (contd.)
ENGS 116 Lecture 131 Caches and Virtual Memory Vincent H. Berk October 31 st, 2008 Reading for Today: Sections C.1 – C.3 (Jouppi article) Reading for Monday:
CS252/Kubiatowicz Lec 3.1 1/24/01 CS252 Graduate Computer Architecture Lecture 3 Caches and Memory Systems I January 24, 2001 Prof. John Kubiatowicz.
Reducing Cache Misses 5.1 Introduction 5.2 The ABCs of Caches 5.3 Reducing Cache Misses 5.4 Reducing Cache Miss Penalty 5.5 Reducing Hit Time 5.6 Main.
EENG449b/Savvides Lec /7/05 April 7, 2005 Prof. Andreas Savvides Spring g449b EENG 449bG/CPSC 439bG.
CES 524 May 6 Eleven Advanced Cache Optimizations (Ch 5) parallel architectures (Ch 4) Slides adapted from Patterson, UC Berkeley.
1 IBM 360 Model 85 (1968) had a cache, which helped it outperform the more complex Model 91 (Tomasulo’s algorithm) Maurice Wilkes published the first paper.
Lec17.1 °Q1: Where can a block be placed in the upper level? (Block placement) °Q2: How is a block found if it is in the upper level? (Block identification)
CSC 4250 Computer Architectures December 5, 2006 Chapter 5. Memory Hierarchy.
Lecture 13 Cache Storage System
1 Improving on Caches CS #4: Pseudo-Associative Cache Also called column associative Idea –start with a direct mapped cache, then on a miss check.
CPE 631 Caches Electrical and Computer Engineering University of Alabama in Huntsville Aleksandar Milenkovic
Memory Hierarchy— Motivation, Definitions, Four Questions about Memory Hierarchy, Improving Performance Professor Alvin R. Lebeck Computer Science 220.
Computer Architecture Ch5-1 Ping-Liang Lai ( 賴秉樑 ) Lecture 5 Review of Memory Hierarchy (Appendix C in textbook) Computer Architecture 計算機結構.
Lecture 08: Memory Hierarchy Cache Performance Kai Bu
CPE 631 Caches Electrical and Computer Engineering University of Alabama in Huntsville Aleksandar Milenkovic,
Chapter 5 Memory III CSE 820. Michigan State University Computer Science and Engineering Miss Rate Reduction (cont’d)
M E M O R Y. Computer Performance It depends in large measure on the interface between processor and memory. CPI (or IPC) is affected CPI = Cycles per.
Lecture 15 Calculating and Improving Cache Perfomance
Nov. 15, 2000Systems Architecture II1 Machine Organization (CS 570) Lecture 8: Memory Hierarchy Design * Jeremy R. Johnson Wed. Nov. 15, 2000 *This lecture.
Improving Direct-Mapped Cache Performance by the Addition of a Small Fully-Associative Cache And Pefetch Buffers Norman P. Jouppi Presenter:Shrinivas Narayani.
Chapter 5 Memory Hierarchy Design
Cache (Memory) Performance Optimization. Average memory access time = Hit time + Miss rate x Miss penalty To improve performance: reduce the miss rate.
Pradondet Nilagupta (Based on notes Robert F. Hodson --- CNU)
1 Adapted from UC Berkeley CS252 S01 Lecture 17: Reducing Cache Miss Penalty and Reducing Cache Hit Time Hardware prefetching and stream buffer, software.
COMP 206 Computer Architecture and Implementation Unit 8b: Cache Misses Siddhartha Chatterjee Fall 2000.
Memory Hierarchy— Five Ways to Reduce Miss Penalty.
CS203 – Advanced Computer Architecture Cache. Memory Hierarchy Design Memory hierarchy design becomes more crucial with recent multi-core processors:
Chapter 5 Memory Hierarchy Design. 2 Many Levels in Memory Hierarchy Pipeline registers Register file 1st-level cache (on-chip) 2nd-level cache (on same.
1 Memory Hierarchy Design Chapter 5. 2 Cache Systems CPUCache Main Memory Data object transfer Block transfer CPU 400MHz Main Memory 10MHz Bus 66MHz CPU.
Lecture 12: Design with Genetic Algorithms Memory I
/ Computer Architecture and Design
COMP 740: Computer Architecture and Implementation
CPS220 Computer System Organization Lecture 18: The Memory Hierarchy
Soner Onder Michigan Technological University
Memory Hierarchy 3 Cs and 6 Ways to Reduce Misses
The University of Adelaide, School of Computer Science
Lecture 9: Memory Hierarchy (3)
现代计算机体系结构 主讲教师:张钢 教授 天津大学计算机学院 课件、作业、讨论网址:
11 Advanced Cache Optimizations
5.2 Eleven Advanced Optimizations of Cache Performance
CPE 631 Lecture 06: Cache Design
CS252 Graduate Computer Architecture Lecture 7 Cache Design (continued) Feb 12, 2002 Prof. David Culler.
CS252 Graduate Computer Architecture Lecture 4 Cache Design
Graduate Computer Architecture Lec 8 – Caches
January 24, 2001 Prof. John Kubiatowicz
Lecture 14: Reducing Cache Misses
CS203A Graduate Computer Architecture Lecture 13 Cache Design
CPE 631 Lecture 05: CPU Caches
Memory Hierarchy.
Siddhartha Chatterjee
/ Computer Architecture and Design
ECE 463/563, Microprocessor Architecture, Prof. Eric Rotenberg
Cache - Optimization.
Cache Memory Rabi Mahapatra
Cache Performance Improvements
Presentation transcript:

Memory Hierarchy—Improving Performance Professor Alvin R. Lebeck Computer Science 220 Fall 2008

2 © Alvin R. Lebeck 2008 Admin Work on Projects Read NUCA paper

3 © Alvin R. Lebeck 2008 Review: ABCs of caches Associativity Block size Capacity Number of sets S = C/(BA) 1-way (Direct-mapped) –A = 1, S = C/B N-way set-associative Fully associativity –S = 1, C = BA Know how a specific piece of data is found –Index, tag, block offset

4 © Alvin R. Lebeck 2008 CPS 220 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

5 © Alvin R. Lebeck 2008 CPS 220 Cache Performance CPUtime = IC x (CPI execution + (Mem accesses per instruction x Miss rate x Miss penalty)) x Clock cycle time hits are included in CPI execution 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

6 © Alvin R. Lebeck 2008 Example Miss penalty 50 clocks Miss rate 2% Base CPI references per instruction Compute the CPUtime CPUtime = IC x (2.0 + (1.33 x 0.02 x 50)) x Clock CPUtime = IC x 3.33 x Clock So CPI increased from 2.0 to 3.33 with a 2% miss rate

7 © Alvin R. Lebeck 2008 Example 2 Two caches: both 64KB, 32 byte blocks, miss penalty 70ns, 1.3 references per instruction, CPI 2.0 w/ perfect cache direct mapped –Cycle time 2ns –Miss rate 1.4% 2-way associative –Cycle time increases by 10% –Miss rate 1.0% Which is better? –Compute average memory access time –Compute CPU time

8 © Alvin R. Lebeck 2008 Example 2 Continued Ave Mem Acc Time = Hit time + (miss rate x miss penalty) –1-way: (0.014 x 70) = 2.98ns –2-way: (0.010 x 70) = 2.90ns CPUtime = IC x CPIexec x Cycle –CPIexec = CPIbase + ((memacc/inst) x Miss rate x miss penalty) –Note: miss penalty x cycle time = 70ns –1-way: IC x ((2.0 x 2.0) + (1.3x0.014x70)) = 5.27 x IC –2-way: IC x ((2.0 x 2.2) + (1.3x0.010x70)) = 5.31 x IC

9 © Alvin R. Lebeck 2008 CPS 220 Review: Cache Performance CPUtime = IC x (CPI execution + Mem accesses per instruction x Miss rate x Miss penalty) x Clock cycle time hits are included in CPI execution 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

10 © Alvin R. Lebeck 2008 CPS 220 Improving Cache Performance Ave Mem Acc Time = Hit time + (miss rate x miss penalty) 1. Reduce the miss rate, 2. Reduce the miss penalty, or 3. Reduce the time to hit in the cache.

11 © Alvin R. Lebeck 2008 CPS 220 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)

12 © Alvin R. Lebeck 2008 CPS 220 How Can We Reduce Misses? Change Block Size? Which of 3Cs affected? Change Associativity? Which of 3Cs affected? Change Program/Compiler? Which of 3Cs affected?

13 © Alvin R. Lebeck 2008 CPS Reduce Misses via Larger Block Size

14 © Alvin R. Lebeck 2008 CPS Reduce Misses via Higher Associativity 2:1 Cache Rule: –Miss Rate DM cache size N ~= Miss Rate 2-way 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

15 © Alvin R. Lebeck 2008 CPS 220 Example: Avg. Memory Access Time vs. Miss Rate Example: assume Clock Cycle = 1.10 for 2-way, 1.12 for 4-way, 1.14 for 8-way vs. Clock cycle for direct mapped Cache SizeAssociativity (KB)1-way2-way4-way8-way (Red means A.M.A.T. not improved by more associativity)

16 © Alvin R. Lebeck 2008 CPS Reducing Conflict 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 TAG DATA ? TAG DATA ? CPU Mem

17 © Alvin R. Lebeck 2008 CPS Reducing Conflict 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) Drawback: CPU pipeline is hard if hit takes 1 or 2 cycles –Better for caches not tied directly to processor Hit Time Pseudo Hit Time Miss Penalty Time

18 © Alvin R. Lebeck 2008 CPS Reducing Misses by HW Prefetching of Instruction & Data E.g., Instruction Prefetching –Alpha 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 –Pointers vs. arrays –Kedem: Markov predictor (address correlation) Prefetching relies on extra memory bandwidth that can be used without penalty

19 © Alvin R. Lebeck 2008 CPS Reducing Misses by SW Prefetching Data Data Prefetch –Load data into register (HP PA-RISC loads) binding –Cache Prefetch: load into cache (MIPS IV, PowerPC, SPARC v. 9) non-binding –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?

20 © Alvin R. Lebeck 2008 CPS 220 Improving Cache Performance 1. Reduce the miss rate, 2. Reduce the miss penalty, or 3. Reduce the time to hit in the cache.

21 © Alvin R. Lebeck 2008 CPS 220 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)

22 © Alvin R. Lebeck 2008 CPS Reducing Misses by Program/Compiler Optimizations Instructions –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

23 © Alvin R. Lebeck 2008 CPS 220 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

24 © Alvin R. Lebeck 2008 CPS 220 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 What is miss rate before and after?

25 © Alvin R. Lebeck 2008 CPS 220 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

26 © Alvin R. Lebeck 2008 CPS 220 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

27 © Alvin R. Lebeck 2008 CPS 220 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 6 loop variant exists Conflict Misses?

28 © Alvin R. Lebeck 2008 CPS 220 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 Reducing Conflict Misses by Blocking

29 © Alvin R. Lebeck 2008 CPS 220 Summary of Program/Compiler Optimizations to Reduce Cache Misses

30 © Alvin R. Lebeck 2008 Layout and Cache Behavior Tile elements spread out in memory because of column- major mapping Fixed mapping into cache Self-interference in cache Memory Cache Cache Mapping

31 © Alvin R. Lebeck 2008 Making Tiles Contiguous Elements of a quadrant are contiguous Recursive layout Elements of a tile are contiguous No self-interference in cache MemoryCache Mapping

32 © Alvin R. Lebeck 2008 Non-linear Layout Functions Different locality properties Different inclusion properties Different addressing costs 4-D blockedMorton orderHilbert order

33 © Alvin R. Lebeck 2008 Performance Improvement

34 © Alvin R. Lebeck 2008 Comparison with TSS

35 © Alvin R. Lebeck 2008 CPS 220 Summary 3 Cs: Compulsory, Capacity, Conflict –How to eliminate them Program Transformations –Change Algorithm –Change Data Layout Implication: Think about caches if you want high performance!