cache memories 15 213 introduc0on to computer systems
play

Cache Memories 15-213: Introduc0on to Computer Systems 10 th - PowerPoint PPT Presentation

Carnegie Mellon Cache Memories 15-213: Introduc0on to Computer Systems 10 th Lecture, Sep. 23, 2010. Instructors: Randy Bryant and Dave OHallaron 1 Carnegie


  1. Carnegie Mellon Cache ¡Memories ¡ 15-­‑213: ¡Introduc0on ¡to ¡Computer ¡Systems ¡ 10 th ¡Lecture, ¡Sep. ¡23, ¡2010. ¡ Instructors: ¡ ¡ Randy ¡Bryant ¡and ¡Dave ¡O’Hallaron ¡ 1

  2. Carnegie Mellon Today ¡  Cache ¡memory ¡organiza7on ¡and ¡opera7on ¡  Performance ¡impact ¡of ¡caches ¡  The ¡memory ¡mountain ¡  Rearranging ¡loops ¡to ¡improve ¡spa0al ¡locality ¡  Using ¡blocking ¡to ¡improve ¡temporal ¡locality ¡ 2

  3. Carnegie Mellon Cache ¡Memories ¡  Cache ¡memories ¡are ¡small, ¡fast ¡SRAM-­‑based ¡memories ¡ managed ¡automa7cally ¡in ¡hardware. ¡ ¡  Hold ¡frequently ¡accessed ¡blocks ¡of ¡main ¡memory ¡  CPU ¡looks ¡first ¡for ¡data ¡in ¡caches ¡(e.g., ¡L1, ¡L2, ¡and ¡L3), ¡ then ¡in ¡main ¡memory. ¡  Typical ¡system ¡structure: ¡ CPU chip Register file Cache ALU memories System bus Memory bus Main I/O Bus interface memory bridge 3

  4. Carnegie Mellon General ¡Cache ¡Organiza7on ¡(S, ¡E, ¡B) ¡ E ¡= ¡2 e ¡lines ¡per ¡set ¡ set ¡ line ¡ S ¡= ¡2 s ¡sets ¡ Cache ¡size: ¡ C ¡= ¡S ¡x ¡E ¡x ¡B ¡data ¡bytes ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ B-­‑1 ¡ v ¡ valid ¡bit ¡ B ¡= ¡2 b ¡bytes ¡per ¡cache ¡block ¡(the ¡data) ¡ 4

  5. Carnegie Mellon Cache ¡Read ¡ • Locate ¡set ¡ • Check ¡if ¡any ¡line ¡in ¡set ¡ has ¡matching ¡tag ¡ E ¡= ¡2 e ¡lines ¡per ¡set ¡ • Yes ¡+ ¡line ¡valid: ¡hit ¡ • Locate ¡data ¡star@ng ¡ at ¡offset ¡ Address ¡of ¡word: ¡ t ¡bits ¡ s ¡bits ¡ b ¡bits ¡ S ¡= ¡2 s ¡sets ¡ tag ¡ set ¡ block ¡ index ¡ offset ¡ data ¡begins ¡at ¡this ¡offset ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ B-­‑1 ¡ valid ¡bit ¡ B ¡= ¡2 b ¡bytes ¡per ¡cache ¡block ¡(the ¡data) ¡ 5

  6. Carnegie Mellon Example: ¡Direct ¡Mapped ¡Cache ¡(E ¡= ¡1) ¡ Direct ¡mapped: ¡One ¡line ¡per ¡set ¡ Assume: ¡cache ¡block ¡size ¡8 ¡bytes ¡ Address ¡of ¡int: ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ t ¡bits ¡ 0…01 ¡ 100 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ find ¡set ¡ S ¡= ¡2 s ¡sets ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 6

  7. Carnegie Mellon Example: ¡Direct ¡Mapped ¡Cache ¡(E ¡= ¡1) ¡ Direct ¡mapped: ¡One ¡line ¡per ¡set ¡ Assume: ¡cache ¡block ¡size ¡8 ¡bytes ¡ Address ¡of ¡int: ¡ valid? ¡ ¡ ¡+ ¡ match: ¡assume ¡yes ¡= ¡hit ¡ t ¡bits ¡ 0…01 ¡ 100 ¡ v ¡ tag ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ block ¡offset ¡ 7

  8. Carnegie Mellon Example: ¡Direct ¡Mapped ¡Cache ¡(E ¡= ¡1) ¡ Direct ¡mapped: ¡One ¡line ¡per ¡set ¡ Assume: ¡cache ¡block ¡size ¡8 ¡bytes ¡ Address ¡of ¡int: ¡ valid? ¡ ¡ ¡+ ¡ match: ¡assume ¡yes ¡= ¡hit ¡ t ¡bits ¡ 0…01 ¡ 100 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ block ¡offset ¡ int ¡(4 ¡Bytes) ¡is ¡here ¡ No ¡match: ¡old ¡line ¡is ¡evicted ¡and ¡replaced ¡ 8

  9. Carnegie Mellon Direct-­‑Mapped ¡Cache ¡Simula7on ¡ t=1 ¡ s=2 ¡ b=1 ¡ M=16 ¡byte ¡addresses, ¡B=2 ¡bytes/block, ¡ ¡ x ¡ xx ¡ x ¡ S=4 ¡sets, ¡E=1 ¡Blocks/set ¡ Address ¡trace ¡(reads, ¡one ¡byte ¡per ¡read): ¡ miss ¡ ¡ 0 ¡[0000 2 ], ¡ ¡ hit ¡ ¡1 ¡[0001 2 ], ¡ ¡ ¡ miss ¡ ¡7 ¡[0111 2 ], ¡ ¡ ¡ miss ¡ ¡8 ¡[1000 2 ], ¡ ¡ ¡ miss ¡ ¡0 ¡[0000 2 ] ¡ v ¡ Tag ¡ Block ¡ 1 ¡ 0 ¡ 1 ¡ 1 ¡ 1 ¡ 0 ¡ 0 ¡ ? ¡ M[0-­‑1] ¡ M[8-­‑9] ¡ M[0-­‑1] ¡ ? ¡ Set ¡0 ¡ Set ¡1 ¡ Set ¡2 ¡ Set ¡3 ¡ 1 ¡ 0 ¡ M[6-­‑7] ¡ 9

  10. Carnegie Mellon Ignore ¡the ¡variables ¡sum, ¡i, ¡j ¡ A ¡Higher ¡Level ¡Example ¡ assume: ¡cold ¡(empty) ¡cache, ¡ a[0][0] ¡goes ¡here ¡ int sum_array_rows(double a[16][16]) { int i, j; double sum = 0; for (i = 0; i < 16; i++) for (j = 0; j < 16; j++) sum += a[i][j]; return sum; } int sum_array_cols(double a[16][16]) { int i, j; double sum = 0; for (j = 0; i < 16; i++) 32 ¡B ¡= ¡4 ¡doubles ¡ for (i = 0; j < 16; j++) sum += a[i][j]; return sum; blackboard ¡ } 10

  11. Carnegie Mellon E-­‑way ¡Set ¡Associa7ve ¡Cache ¡(Here: ¡E ¡= ¡2) ¡ E ¡= ¡2: ¡Two ¡lines ¡per ¡set ¡ Assume: ¡cache ¡block ¡size ¡8 ¡bytes ¡ Address ¡of ¡short ¡int: ¡ t ¡bits ¡ 0…01 ¡ 100 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ find ¡set ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 11

  12. Carnegie Mellon E-­‑way ¡Set ¡Associa7ve ¡Cache ¡(Here: ¡E ¡= ¡2) ¡ E ¡= ¡2: ¡Two ¡lines ¡per ¡set ¡ Assume: ¡cache ¡block ¡size ¡8 ¡bytes ¡ Address ¡of ¡short ¡int: ¡ t ¡bits ¡ 0…01 ¡ 100 ¡ compare ¡both ¡ valid? ¡ ¡+ ¡ ¡ match: ¡yes ¡= ¡hit ¡ v ¡ tag ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ block ¡offset ¡ 12

  13. Carnegie Mellon E-­‑way ¡Set ¡Associa7ve ¡Cache ¡(Here: ¡E ¡= ¡2) ¡ E ¡= ¡2: ¡Two ¡lines ¡per ¡set ¡ Assume: ¡cache ¡block ¡size ¡8 ¡bytes ¡ Address ¡of ¡short ¡int: ¡ t ¡bits ¡ 0…01 ¡ 100 ¡ compare ¡both ¡ valid? ¡ ¡+ ¡ ¡ match: ¡yes ¡= ¡hit ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ block ¡offset ¡ short ¡int ¡(2 ¡Bytes) ¡is ¡here ¡ No ¡match: ¡ ¡ • One ¡line ¡in ¡set ¡is ¡selected ¡for ¡evic7on ¡and ¡replacement ¡ • Replacement ¡policies: ¡random, ¡least ¡recently ¡used ¡(LRU), ¡… ¡ 13

  14. Carnegie Mellon 2-­‑Way ¡Set ¡Associa7ve ¡Cache ¡Simula7on ¡ t=2 ¡ s=1 ¡ b=1 ¡ M=16 ¡byte ¡addresses, ¡B=2 ¡bytes/block, ¡ ¡ xx ¡ x ¡ x ¡ S=2 ¡sets, ¡E=2 ¡blocks/set ¡ Address ¡trace ¡(reads, ¡one ¡byte ¡per ¡read): ¡ miss ¡ ¡ 0 ¡[0000 2 ], ¡ ¡ hit ¡ ¡1 ¡[0001 2 ], ¡ ¡ ¡ miss ¡ ¡7 ¡[0111 2 ], ¡ ¡ ¡ miss ¡ ¡8 ¡[1000 2 ], ¡ ¡ ¡ hit ¡ ¡0 ¡[0000 2 ] ¡ v ¡ Tag ¡ Block ¡ 1 ¡ 0 ¡ 00 ¡ ? ¡ M[0-­‑1] ¡ ? ¡ Set ¡0 ¡ 0 ¡ 1 ¡ 10 ¡ M[8-­‑9] ¡ 0 ¡ 1 ¡ 01 ¡ M[6-­‑7] ¡ Set ¡1 ¡ 0 ¡ 14

  15. Carnegie Mellon A ¡Higher ¡Level ¡Example ¡ Ignore ¡the ¡variables ¡sum, ¡i, ¡j ¡ assume: ¡cold ¡(empty) ¡cache, ¡ int sum_array_rows(double a[16][16]) a[0][0] ¡goes ¡here ¡ { int i, j; double sum = 0; for (i = 0; i < 16; i++) for (j = 0; j < 16; j++) sum += a[i][j]; return sum; } 32 ¡B ¡= ¡4 ¡doubles ¡ int sum_array_rows(double a[16][16]) { int i, j; double sum = 0; for (j = 0; i < 16; i++) for (i = 0; j < 16; j++) sum += a[i][j]; blackboard ¡ return sum; } 15

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend