CS 61C: Great Ideas in Computer Architecture Lecture 15: Caches, Part 2 Instructor: Sagar Karandikar

Slides:



Advertisements
Similar presentations
SE-292 High Performance Computing Memory Hierarchy R. Govindarajan
Advertisements

CS2100 Computer Organisation Cache II (AY2014/2015) Semester 2.
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Caches Part 2 Instructors: Krste Asanovic & Vladimir Stojanovic
1 Lecture 20: Cache Hierarchies, Virtual Memory Today’s topics:  Cache hierarchies  Virtual memory Reminder:  Assignment 8 will be posted soon (due.
331 Week13.1Spring :332:331 Computer Architecture and Assembly Language Spring 2006 Week 13 Basics of Cache [Adapted from Dave Patterson’s UCB CS152.
CS61C L22 Caches III (1) A Carle, Summer 2006 © UCB inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #22: Caches Andy.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
Review CPSC 321 Andreas Klappenecker Announcements Tuesday, November 30, midterm exam.
Computer Systems Organization: Lecture 11
Cache Memory Adapted from lectures notes of Dr. Patterson and Dr. Kubiatowicz of UC Berkeley.
1 COMP 206: Computer Architecture and Implementation Montek Singh Mon, Oct 31, 2005 Topic: Memory Hierarchy Design (HP3 Ch. 5) (Caches, Main Memory and.
1 COMP 206: Computer Architecture and Implementation Montek Singh Mon., Nov. 3, 2003 Topic: Memory Hierarchy Design (HP3 Ch. 5) (Caches, Main Memory and.
331 Lec20.1Fall :332:331 Computer Architecture and Assembly Language Fall 2003 Week 13 Basics of Cache [Adapted from Dave Patterson’s UCB CS152.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
ENEE350 Ankur Srivastava University of Maryland, College Park Based on Slides from Mary Jane Irwin ( )
Cs 61C L17 Cache.1 Patterson Spring 99 ©UCB CS61C Cache Memory Lecture 17 March 31, 1999 Dave Patterson (http.cs.berkeley.edu/~patterson) www-inst.eecs.berkeley.edu/~cs61c/schedule.html.
331 Lec20.1Spring :332:331 Computer Architecture and Assembly Language Spring 2005 Week 13 Basics of Cache [Adapted from Dave Patterson’s UCB CS152.
Review: The Memory Hierarchy
Computer ArchitectureFall 2008 © November 3 rd, 2008 Nael Abu-Ghazaleh CS-447– Computer.
Lecture 33: Chapter 5 Today’s topic –Cache Replacement Algorithms –Multi-level Caches –Virtual Memories 1.
Memory Hierarchy and Cache Design The following sources are used for preparing these slides: Lecture 14 from the course Computer architecture ECE 201 by.
Caches Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H 5.1, 5.2 (except writes)
CS3350B Computer Architecture Winter 2015 Lecture 3.2: Exploiting Memory Hierarchy: How? Marc Moreno Maza [Adapted from.
1 CMPE 421 Advanced Computer Architecture Caching with Associativity PART2.
CMPE 421 Parallel Computer Architecture
Lecture 10 Memory Hierarchy and Cache Design Computer Architecture COE 501.
The Memory Hierarchy 21/05/2009Lecture 32_CA&O_Engr Umbreen Sabir.
CS 3410, Spring 2014 Computer Science Cornell University See P&H Chapter: , 5.8, 5.15.
10/18: Lecture topics Memory Hierarchy –Why it works: Locality –Levels in the hierarchy Cache access –Mapping strategies Cache performance Replacement.
CSIE30300 Computer Architecture Unit 9: Improving Cache Performance Hsin-Chou Chi [Adapted from material by and
CS.305 Computer Architecture Improving Cache Performance Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly.
CS1104 – Computer Organization PART 2: Computer Architecture Lecture 10 Memory Hierarchy.
CSIE30300 Computer Architecture Unit 08: Cache Hsin-Chou Chi [Adapted from material by and
CPE432 Chapter 5A.1Dr. W. Abu-Sufah, UJ Chapter 5A: Exploiting the Memory Hierarchy, Part 2 Adapted from Slides by Prof. Mary Jane Irwin, Penn State University.
3-May-2006cse cache © DW Johnson and University of Washington1 Cache Memory CSE 410, Spring 2006 Computer Systems
1 CMPE 421 Parallel Computer Architecture PART4 Caching with Associativity.
1Chapter 7 Memory Hierarchies (Part 2) Outline of Lectures on Memory Systems 1. Memory Hierarchies 2. Cache Memory 3. Virtual Memory 4. The future.
Additional Slides By Professor Mary Jane Irwin Pennsylvania State University Group 3.
Computer Organization & Programming
Lecture 08: Memory Hierarchy Cache Performance Kai Bu
CS2100 Computer Organisation Cache II (AY2015/6) Semester 1.
Computer Organization CS224 Fall 2012 Lessons 45 & 46.
1 Chapter Seven. 2 Users want large and fast memories! SRAM access times are ns at cost of $100 to $250 per Mbyte. DRAM access times are ns.
Nov. 15, 2000Systems Architecture II1 Machine Organization (CS 570) Lecture 8: Memory Hierarchy Design * Jeremy R. Johnson Wed. Nov. 15, 2000 *This lecture.
CS.305 Computer Architecture Memory: Caches Adapted from Computer Organization and Design, Patterson & Hennessy, © 2005, and from slides kindly made available.
CPE232 Cache Introduction1 CPE 232 Computer Organization Spring 2006 Cache Introduction Dr. Gheith Abandah [Adapted from the slides of Professor Mary Irwin.
1 CMPE 421 Parallel Computer Architecture PART3 Accessing a Cache.
Improving Memory Access 2/3 The Cache and Virtual Memory
Lecture 20 Last lecture: Today’s lecture: Types of memory
CPE232 Improving Cache Performance1 CPE 232 Computer Organization Spring 2006 Improving Cache Performance Dr. Gheith Abandah [Adapted from the slides of.
CSE431 L20&21 Improving Cache Performance.1Irwin, PSU, 2005 CSE 431 Computer Architecture Fall 2005 Lecture 20&21. Improving Cache Performance Mary Jane.
CS 61C: Great Ideas in Computer Architecture (Machine Structures) Set-Associative Caches Instructors: Randy H. Katz David A. Patterson
CS 61C: Great Ideas in Computer Architecture Caches Part 2 Instructors: Nicholas Weaver & Vladimir Stojanovic
CS 110 Computer Architecture Lecture 15: Caches Part 2 Instructor: Sören Schwertfeger School of Information Science and Technology.
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.
CMSC 611: Advanced Computer Architecture
COSC3330 Computer Architecture
Cache Memory Presentation I
Morgan Kaufmann Publishers
Instructor: Justin Hsia
Memristor memory on its way (hopefully)
Instructors: Yuanqing Cheng
Morgan Kaufmann Publishers
EE108B Review Session #6 Daxia Ge Friday February 23rd, 2007
Caches III CSE 351 Autumn 2018 Instructor: Justin Hsia
Cache - Optimization.
Cache Memory Rabi Mahapatra
10/18: Lecture Topics Using spatial locality
Caches III CSE 351 Spring 2019 Instructor: Ruth Anderson
Overview Problem Solution CPU vs Memory performance imbalance
Presentation transcript:

CS 61C: Great Ideas in Computer Architecture Lecture 15: Caches, Part 2 Instructor: Sagar Karandikar 1

You Are Here! Parallel Requests Assigned to computer e.g., Search “Katz” Parallel Threads Assigned to core e.g., Lookup, Ads Parallel Instructions >1 one time e.g., 5 pipelined instructions Parallel Data >1 data one time e.g., Add of 4 pairs of words Hardware descriptions All one time Programming Languages Smart Phone Warehouse Scale Computer Software Hardware Harness Parallelism & Achieve High Performance Logic Gates Core … Memory (Cache) Input/Output Computer Main Memory Core Instruction Unit(s) Functional Unit(s) A 3 +B 3 A 2 +B 2 A 1 +B 1 A 0 +B 0 Today’s Lecture 2

Caches Review 3 Principle of Locality Temporal Locality and Spatial Locality Hierarchy of Memories (speed/size/cost per bit) to Exploit Locality Cache – copy of data in lower level of memory hierarchy Direct Mapped Caches Cache design choice: Write-Through vs. Write-Back

Processor Control Datapath Review: Adding Cache to Computer 4 PC Memory InputOutput Enable? Read/Write Address Write Data Read Data Processor-Memory Interface I/O-Memory Interfaces Program Data

How do we use this thing? Nothing changes from the programmer’s perspective: – Still issuing lw and sw instructions Everything we’ll talk about is in the hardware: – breaking down the address – indexing into the cache – choosing a block by checking tag – extracting bytes using the offset Why should a programmer care? – Understanding cache parameters = fast programs 5

Review: Processor Address Fields used by Cache Controller Block Offset: Byte address within block – #bits = log_2(block size in bytes) Index: Selects which index (set) we want # bits = log_2(number of sets) Tag: Remaining portion of processor address processor address size - offset bits - index bits Block offset Set Index Tag 6 Processor Address (32-bits total)

Working with a Direct Mapped Cache Byte Direct Mapped Cache TagDataValidIndex 7 Let’s say our cache is what we see on the left. From the picture, we see that there are 4 indices (sets) Given that it is a 16 Byte cache and that there are 4 sets (the same as blocks in a DM cache), each block is 4 bytes Our processor can address 2^6 bytes of memory, so it has 6 bit addresses

Mapping an address to our cache Using the info from the previous slide… – 16 Byte Direct Mapped Cache – 4 sets (sets, blocks, indices are all interchangeable in a direct mapped cache) – 4 byte blocks – Processor issues 6 bit addresses (i.e. has a 64 Byte address space) … We can figure out how to break down the address – Offset bits = log_2(block size) = log_2(4 byte blocks) = 2 – Index bits = log_2(number of sets) = log_2(4 sets) = 2 – Tag = = Offset 23 Index 4 Tag

Geometry of our D.M. Cache Byte Direct Mapped Cache Main Memory TagDataValid T I O Recall that our processor can only address 64 B of memory in this example So, we’ve drawn all of memory here: 16 rows, each 4 bytes wide We’ve drawn memory in the same “aspect ratio” as the cache - in units of blocks rather than bytes Since each block is 4 bytes wide, the addresses you see end in 0b00 Index 9

One word blocks, cache size = 1Ki words (or 4KiB) Direct Mapped Cache Hardware 20 Tag 10 Index Data IndexTagValid Block offset 20 Data 32 Hit 10 Valid bit ensures something useful in cache for this index Compare Tag with upper part of Address to see if a Hit Read data from cache instead of memory if a Hit Comparator

Cache Names for Each Organization “Fully Associative”: Block can go anywhere – First design in last lecture – Note: No Index field, but 1 comparator/block “Direct Mapped”: Block goes one place – Note: Only 1 comparator – Number of sets = number blocks “N-way Set Associative”: N places for a block – Number of sets = number of blocks / N – Fully Associative: N = number of blocks in cache – Direct Mapped: N = 1 11

Range of Set-Associative Caches For a fixed-size cache, each increase by a factor of 2 in associativity doubles the number of blocks per set (i.e., the number of “ways”) and halves the number of sets – decreases the size of the index by 1 bit and increases the size of the tag by 1 bit 12 Block offset Index Tag More Associativity (more ways) Note: IBM persists in calling sets “ways” and ways “sets”. They’re wrong.

Review: Write-Through vs. Write-Back Write-Through: – Simpler control logic – More predictable timing simplifies processor control logic – Easier to make reliable, since memory always has copy of data Write-Back – More complex control logic – More variable timing (0,1,2 memory accesses per cache access) – Usually reduces write traffic – Harder to make reliable, sometimes cache has only copy of data 13 So far we handled reads. What about writes?

Administrivia HW3 Out Proj2-2 Out Register your Project 3 Teams Yes, caches are hard, but don’t worry: – 1.5 discussions on caches – 1 lab on caches (where you use a simulator) – 1 more lecture on caches (after today) – Homework on caches – Guerrilla section on Caches next week Guerrilla section today, 6-8pm in Woz, on MIPS CPU The good news: You’re halfway done! 14

Example: Direct-Mapped $ with 4 Single-Word Lines, Worst-Case Reference String Consider the main memory address reference string miss 00 Mem(0) Mem(16) Mem(0) Mem(0) Mem(0) Mem(16) Mem(16) 0 00 Start with an empty cache - all blocks initially marked as not valid Effect due to “conflict” misses - two memory locations that map into the same cache block 8 requests, 8 misses 15

Alternative Block Placement Schemes DM placement: mem block 12 in 8 block cache: only one cache block where mem block 12 can be found—(12 modulo 8) = 4 SA placement: four sets x 2-ways (8 cache blocks), memory block 12 in set (12 mod 4) = 0; either element of the set FA placement: mem block 12 can appear in any cache blocks 16

Example: 2-Way Set Associative $ (4 words = 2 sets x 2 ways per set) 0 Cache Main Memory Q: 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) TagData Q: 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 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx T I O Way Set 0 1 One word blocks Two low order bits define the byte in the word (32b words) 17

Example: 4-Word 2-Way SA $ Same Reference String 0160 Consider the main memory address reference string miss hit 000 Mem(0) Start with an empty cache - all blocks initially marked as not valid 010 Mem(16) 000 Mem(0) 010 Mem(16) Solves the “conflict” effect that occurred in a direct-mapped cache (to a degree) Because now two memory locations that map into the same cache set can co-exist! But what if we did 0, 16, 32, 48, 0, 16, 32, 48, …? 8 requests, 2 misses 18 Set 0 Set 1 Way 0 Way 1 Way 0 Way 1

Different Organizations of an Eight-Block Cache Total size of $ in blocks is equal to number of sets x associativity. For fixed $ size (and block size), increasing associativity decreases number of sets while increasing number of elements per set. With eight blocks, an 8-way set- associative $ is same as a fully associative $. 19

One word blocks, cache size = 1Ki words (or 4KiB) Recall: Direct Mapped Cache Hardware 20 Tag 10 Index Data IndexTagValid Block offset 20 Data 32 Hit 20 Valid bit ensures something useful in cache for this index Compare Tag with upper part of Address to see if a Hit Read data from cache instead of memory if a Hit Comparator

Four-Way Set-Associative Cache 2 8 = 256 sets each with four ways (each with one block) Byte offset Data TagV Data TagV Data TagV Index Data TagV Index 22 Tag HitData 32 4x1 select Way 0Way 1Way 2Way 3 21

Four words/block, cache size = 1Ki words Not the same!: Multiword-Block Direct-Mapped Cache 8 Index Data IndexTagValid Byte offset 20 Tag HitData 32 Block offset 22

Range of Set-Associative Caches For a fixed-size cache, each increase by a factor of two in associativity doubles the number of blocks per set (i.e., the number or ways) and halves the number of sets – decreases the size of the index by 1 bit and increases the size of the tag by 1 bit Byte offsetIndexTag Decreasing associativity Fully associative (only one set) Tag is all the bits except byte offset Direct mapped (only one way) Smaller tags, only a single comparator Increasing associativity Selects the setUsed for tag compareSelects the byte(s) in the block 23

Costs of Set-Associative Caches N-way set-associative cache costs – N comparators (delay and area) – MUX delay (set selection) before data is available – Data available after set selection (and Hit/Miss decision). DM $: block is available before the Hit/Miss decision In Set-Associative, not possible to just assume a hit and continue and recover later if it was a miss When miss occurs, which way’s block selected for replacement? – Least Recently Used (LRU): one that has been unused the longest (principle of temporal locality) Must track when each way’s block was used relative to other blocks in the set For 2-way SA $, one bit per set → set to 1 when a block is referenced; reset the other way’s bit (i.e., “last used”) 24

Cache Replacement Policies Random Replacement – Hardware randomly selects a cache evict Least-Recently Used – Hardware keeps track of access history – Replace the entry that has not been used for the longest time – For 2-way set-associative cache, need one bit for LRU replacement Example of a Simple “Pseudo” LRU Implementation – Assume 64 Fully Associative entries – Hardware replacement pointer points to one cache entry – Whenever access is made to the entry the pointer points to: Move the pointer to the next entry – Otherwise: do not move the pointer – (example of “not-most-recently used” replacement policy) : Entry 0 Entry 1 Entry 63 Replacement Pointer 25

Benefits of Set-Associative Caches Choice of DM $ or SA $ depends on the cost of a miss versus the cost of implementation Largest gains are in going from direct mapped to 2-way (20%+ reduction in miss rate) 26

Clickers/Peer Instruction For a cache with constant total capacity, if we increase the number of ways by a factor of 2, which statement is false: A: The number of sets could be doubled B: The tag width could decrease C: The number of tags could stay the same D: The block size could be halved E: Tag width must increase 27

Break 28

Understanding Cache Misses: The 3Cs Compulsory (cold start or process migration, 1 st reference): – First access to a block in memory impossible to avoid; small effect for long running programs – Solution: increase block size (increases miss penalty; very large blocks could increase miss rate) Capacity: – Cache cannot contain all blocks accessed by the program – Solution: increase cache size (may increase access time) Conflict (collision): – Multiple memory locations mapped to the same cache location – Solution 1: increase cache size – Solution 2: increase associativity (may increase access time) 29

How to Calculate 3C’s using a Cache Simulator 1.Compulsory: set cache size to infinity and fully associative, and count number of misses 2.Capacity: Change cache size from infinity, usually in powers of 2, and count misses for each reduction in size – 16 MB, 8 MB, 4 MB, … 128 KB, 64 KB, 16 KB 3.Conflict: Change from fully associative to n-way set associative while counting misses – Fully associative, 16-way, 8-way, 4-way, 2-way, 1-way 30

3Cs Analysis Three sources of misses (SPEC2000 integer and floating-point benchmarks) – Compulsory misses 0.006%; not visible – Capacity misses, function of cache size – Conflict portion depends on associativity and cache size 31

Rules for Determining Miss Type for a Given Access Pattern in 61C 1) Compulsory: A miss is compulsory if and only if it results from accessing the data for the first time. If you have ever brought the data you are accessing into the cache before, it's not a compulsory miss, otherwise it is. 2) Conflict: A conflict miss is a miss that's not compulsory and that would have been avoided if the cache was fully associative. Imagine you had a cache with the same parameters but fully-associative (with LRU). If that would've avoided the miss, it's a conflict miss. 3) Capacity: This is a miss that would not have happened with an infinitely large cache. If your miss is not a compulsory or conflict miss, it's a capacity miss. 32

Cache Measurement Terms Hit rate: fraction of accesses that hit in the cache Miss rate: 1 – Hit rate Miss penalty: time to replace a block from lower level in memory hierarchy to cache Hit time: time to access cache memory (including tag comparison) Abbreviation: “$” = cache 33

Average Memory Access Time (AMAT) Average Memory Access Time (AMAT) is the average to access memory considering both hits and misses in the cache AMAT = Time for a hit + Miss rate x Miss penalty 34

Improving Cache Performance Reduce the time to hit in the cache – E.g., Smaller cache Reduce the miss rate – E.g., Bigger cache Reduce the miss penalty – E.g., Use multiple cache levels (next time) 35 AMAT = Time for a hit + Miss rate x Miss penalty

Impact of Larger Cache on AMAT? 1) Reduces misses (what kind(s)?) 2) Longer Access time (Hit time): smaller is faster – Increase in hit time will likely add another stage to the pipeline At some point, increase in hit time for a larger cache may overcome the improvement in hit rate, yielding a decrease in performance Computer architects expend considerable effort optimizing organization of cache hierarchy – big impact on performance and power! 36

Clickers: Impact of longer cache blocks on misses? For fixed total cache capacity and associativity, what is effect of longer blocks on each type of miss: – A: Decrease, B: Unchanged, C: Increase Compulsory? Capacity? Conflict? 37

Clickers: For fixed capacity and fixed block size, how does increasing associativity affect AMAT? 38

Cache Design Space Several interacting dimensions – Cache size – Block size – Associativity – Replacement policy – Write-through vs. write-back – Write allocation Optimal choice is a compromise – Depends on access characteristics Workload Use (I-cache, D-cache) – Depends on technology / cost Simplicity often wins Associativity Cache Size Block Size Bad Good LessMore Factor AFactor B 39

And, In Conclusion … Name of the Game: Reduce AMAT – Reduce Hit Time – Reduce Miss Rate – Reduce Miss Penalty Balance cache parameters (Capacity, associativity, block size) 40