CSCI206 - Computer Organization & Programming

Slides:



Advertisements
Similar presentations
SE-292 High Performance Computing
Advertisements

SE-292 High Performance Computing Memory Hierarchy R. Govindarajan
Cache Memory Exercises. Questions I Given: –memory is little-endian and byte addressable; memory size; –number of cache blocks, size of cache block –An.
Practical Caches COMP25212 cache 3. Learning Objectives To understand: –Additional Control Bits in Cache Lines –Cache Line Size Tradeoffs –Separate I&D.
How caches take advantage of Temporal locality
Review CPSC 321 Andreas Klappenecker Announcements Tuesday, November 30, midterm exam.
Computer ArchitectureFall 2007 © November 12th, 2007 Majd F. Sakr CS-447– Computer Architecture.
1  1998 Morgan Kaufmann Publishers Chapter Seven Large and Fast: Exploiting Memory Hierarchy.
Caches The principle that states that if data is used, its neighbor will likely be used soon.
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.
©UCB CS 161 Ch 7: Memory Hierarchy LECTURE 24 Instructor: L.N. Bhuyan
Computer ArchitectureFall 2007 © November 12th, 2007 Majd F. Sakr CS-447– Computer Architecture.
Caches – basic idea Small, fast memory Stores frequently-accessed blocks of memory. When it fills up, discard some blocks and replace them with others.
Storage HierarchyCS510 Computer ArchitectureLecture Lecture 12 Storage Hierarchy.
Caches – basic idea Small, fast memory Stores frequently-accessed blocks of memory. When it fills up, discard some blocks and replace them with others.
CMPE 421 Parallel Computer Architecture
Lecture 10 Memory Hierarchy and Cache Design Computer Architecture COE 501.
CSCI 232© 2005 JW Ryder1 Cache Memory Organization Direct Mapping Fully Associative Set Associative (very popular) Sector Mapping.
1 CMPE 421 Advanced Computer Architecture Accessing a Cache PART1.
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.
Virtual Memory. Virtual Memory: Topics Why virtual memory? Virtual to physical address translation Page Table Translation Lookaside Buffer (TLB)
Additional Slides By Professor Mary Jane Irwin Pennsylvania State University Group 3.
CML CML CS 230: Computer Organization and Assembly Language Aviral Shrivastava Department of Computer Science and Engineering School of Computing and Informatics.
Lecture Objectives: 1)Explain the relationship between miss rate and block size in a cache. 2)Construct a flowchart explaining how a cache miss is handled.
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.
11 Intro to cache memory Kosarev Nikolay MIPT Nov, 2009.
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.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
Exam 2 Review Two’s Complement Arithmetic Ripple carry ALU logic and performance Look-ahead techniques, performance and equations Basic multiplication.
Additional Slides By Professor Mary Jane Irwin Pennsylvania State University Group 1.
Memory Hierarchy and Cache Design (3). Reducing Cache Miss Penalty 1. Giving priority to read misses over writes 2. Sub-block placement for reduced miss.
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Cache Memory.
COSC2410: LAB 19 INTRODUCTION TO MEMORY/CACHE DIRECT MAPPING 1.
Cache Memory Yi-Ning Huang. Principle of Locality Principle of Locality A phenomenon that the recent used memory location is more likely to be used again.
CSCI206 - Computer Organization & Programming
COSC3330 Computer Architecture
Memory Hierarchy Ideal memory is fast, large, and inexpensive
Improving Memory Access The Cache and Virtual Memory
Address – 32 bits WRITE Write Cache Write Main Byte Offset Tag Index Valid Tag Data 16K entries 16.
Tutorial Nine Cache CompSci Semester One 2016.
The Goal: illusion of large, fast, cheap memory
Improving Memory Access 1/3 The Cache and Virtual Memory
CAM Content Addressable Memory
Memory Hierarchy Virtual Memory, Address Translation
Consider a Direct Mapped Cache with 4 word blocks
Morgan Kaufmann Publishers Memory & Cache
Morgan Kaufmann Publishers
CSCI206 - Computer Organization & Programming
Systems Architecture II
Lecture 22: Cache Hierarchies, Memory
Direct Mapping.
CPE 631 Lecture 05: Cache Design
Module IV Memory Organization.
Memory Hierarchy Memory: hierarchy of components of various speeds and capacities Hierarchy driven by cost and performance In early days Primary memory.
CDA 5155 Caches.
ECE232: Hardware Organization and Design
Morgan Kaufmann Publishers Memory Hierarchy: Cache Basics
EE108B Review Session #6 Daxia Ge Friday February 23rd, 2007
Caches III CSE 351 Autumn 2018 Instructor: Justin Hsia
CS-447– Computer Architecture Lecture 20 Cache Memories
Basic Cache Operation Prof. Eric Rotenberg
Memory Hierarchy Memory: hierarchy of components of various speeds and capacities Hierarchy driven by cost and performance In early days Primary memory.
Chapter Five Large and Fast: Exploiting Memory Hierarchy
Cache Memory Rabi Mahapatra
Cache Memory and Performance
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:

CSCI206 - Computer Organization & Programming Direct Mapped Caches zyBook: 12.3

Constructing the cache The cache algorithm determines what data should be stored in the cache Another question is where in the cache should the data be stored? needs to be fast to check for hit/miss The direct mapped cache is the simplest cache algorithm

Direct mapped (DM) cache Each memory address is directly mapped to exactly one (and only one) location in the cache Cache is smaller than main memory, so many addresses map to the same location in the cache When memory is accessed it is stored in the cache, any prior data at that cache location is removed (overwritten)

Address Value 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 DM Cache Example Suppose we have a 4-bit main memory address range (16 words) and a 2-bit cache memory address range (4 words) Index Value 1 2 3

DM Cache Access For example, access memory address 3 First compute index 3 % 4 = 3 Is the data at this index valid? Is this data from address 3 or 7, 11, 15? Need additional data in the cache - valid (1-bit) set to 1 if data is valid - tag, the upper portion of the address bits TAG CACHE INDEX MEMORY ADDRESS

DM Cache Access (address 7) Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Access (address 7) index = 7 mod 4 = 3 tag = 7 >> 2 = 01 Index Value Valid Tag 1 2 3 H 01 TAG CACHE INDEX 01 11 MEMORY ADDRESS 0111

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 4 8 1 2 3 D Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 4 8 Index Value Valid Tag 1 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 1 2 Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 Index Value Valid Tag 1 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 1 F Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 Index Value Valid Tag 1 F 01 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 1 F Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 Index Value Valid Tag 1 F 01 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 A 1 Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 Index Value Valid Tag A 1 01 F 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 A Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Index Value Valid Tag A 1 01 F 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Index Value Valid Tag I 1 10 F 01 2 3 D 00 Tag in cache (01) doesn’t match the address tag (10)

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 I Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Index Value Valid Tag I 1 10 F 01 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 HIT Index Value Valid Tag I 1 10 F 01 2 3 D 00 Tag in address (00) match that in cache (00)

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 HIT Index Value Valid Tag I 1 10 F 01 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 HIT Index Value Valid Tag E 1 01 F 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 HIT Index Value Valid Tag E 1 01 F 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 HIT Index Value Valid Tag I 1 10 F 01 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 HIT Index Value Valid Tag I 1 10 F 01 2 3 D 00

DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 Address Value A 1 B 2 C 3 D 4 E 5 F 6 G 7 H 8 I 9 J 10 K 11 L 12 M 13 N 14 O 15 P DM Cache Example ADDR CACHE INDEX TAG RESULT 3 00 MISS 5 1 01 4 8 10 HIT Index Value Valid Tag I 1 10 F 01 2 3 D 00 hit rate = 2/8

Designing a 4KB MIPS DM Cache MIPS address space is 32-bit, word aligned Cache indexes are also word aligned lower two bits of address are the byte offset 4 KB cache has 1 K words (4 bytes / word) 1 K cache indexes = 10 bit index (2^10 = 1024) MEMORY ADDRESS (32 BIT) TAG CACHE INDEX BYTE OFFSET 20 BITS 10 BITS 2 BITS

4 KB MIPS DM Cache

Exploiting Spatial Locality Load extra words near other memory accesses into the cache For example lw $t0, 16($s0) load 16($s0) through 32($s0) into the cache

Organize Cache into Blocks Rather than caching words, cache blocks block size is a power of 2 for easy indexing On a miss, a whole block is cached To exploit spatial locality Example, 4 KB cache with 16 Byte blocks MEMORY ADDRESS (32 BIT) TAG BLOCK INDEX BLOCK OFFSET BYTE OFFSET 20 BITS 8 BITS 2 BITS 16 bytes/block = 4 words/block 4 KB / 16 B/block = 256 blocks need 2 bit block offset and 8 bit block index

DM Cache Access (block address) (number of blocks)

Optimal Block Size FIGURE 5.11 Miss rate versus block size. The miss rate goes up if the block size is too large relative to the cache size. Each line represents a cache of different size.

16 KB MIPS DM cache w/ 64 B blocks 16 KB / 64 B = 256 cache indexes (lines) 8 bits for index 64 B / 4 B = 16 words per cache line 4 bits for block offset 2 bits for byte offset Sometimes the block offset and byte offset are combined into a single offset field. MEMORY ADDRESS (32 BIT) TAG CACHE INDEX BLOCK OFFSET BYTE OFFSET 18 BITS 8 BITS 4 BITS 2 BITS

16 KB MIPS DM cache w/ 64 B blocks