the hardware so ware interface
play

The Hardware/So<ware Interface CSE351 Winter 2013 Memory - PowerPoint PPT Presentation

University of Washington The Hardware/So<ware Interface CSE351 Winter 2013 Memory and Caches II University of Washington Types of Cache Misses Cold


  1. University ¡of ¡Washington ¡ The ¡Hardware/So<ware ¡Interface ¡ CSE351 ¡Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  2. University ¡of ¡Washington ¡ Types ¡of ¡Cache ¡Misses ¡  Cold ¡(compulsory) ¡miss ¡  Occurs ¡on ¡very ¡first ¡access ¡to ¡a ¡block ¡  Conflict ¡miss ¡  Occurs ¡when ¡some ¡block ¡is ¡evicted ¡out ¡of ¡the ¡cache, ¡but ¡then ¡that ¡block ¡ is ¡referenced ¡again ¡later ¡  Conflict ¡misses ¡occur ¡when ¡the ¡cache ¡is ¡large ¡enough, ¡but ¡mulDple ¡data ¡ blocks ¡all ¡map ¡to ¡the ¡same ¡slot ¡  e.g., ¡if ¡blocks ¡0 ¡and ¡8 ¡map ¡to ¡the ¡same ¡cache ¡slot, ¡then ¡referencing ¡ 0, ¡8, ¡0, ¡8, ¡... ¡would ¡miss ¡every ¡Dme ¡  Conflict ¡misses ¡may ¡be ¡reduced ¡by ¡increasing ¡the ¡associaDvity ¡of ¡ the ¡cache ¡  Capacity ¡miss ¡  Occurs ¡when ¡the ¡set ¡of ¡acDve ¡cache ¡blocks ¡(the ¡working ¡set) ¡is ¡larger ¡ than ¡the ¡cache ¡(just ¡won’t ¡fit) ¡ 2 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  3. University ¡of ¡Washington ¡ General ¡Cache ¡OrganizaJon ¡(S, ¡E, ¡B) ¡ E ¡= ¡2 e ¡lines ¡per ¡set ¡ set ¡ line ¡ S ¡= ¡2 s ¡sets ¡ cache ¡size: ¡ S ¡x ¡E ¡x ¡B ¡ ¡data ¡bytes ¡ v ¡ tag ¡ 0 ¡ 1 ¡ 2 ¡ B-­‑1 ¡ valid ¡bit ¡ B ¡= ¡2 b ¡bytes ¡of ¡data ¡per ¡cache ¡line ¡(the ¡data ¡block) ¡ 3 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  4. University ¡of ¡Washington ¡ 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 ¡byte ¡in ¡memory: ¡ 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 ¡of ¡data ¡per ¡cache ¡line ¡(the ¡data ¡block) ¡ 4 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  5. University ¡of ¡Washington ¡ 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 ¡ 5 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  6. University ¡of ¡Washington ¡ Example: ¡Direct-­‑Mapped ¡Cache ¡(E ¡= ¡1) ¡ Direct-­‑mapped: ¡One ¡line ¡per ¡set ¡ Assume: ¡cache ¡block ¡size ¡8 ¡bytes ¡ Address ¡of ¡int: ¡ valid? ¡ ¡ ¡+ ¡ match?: ¡yes ¡= ¡hit ¡ t ¡bits ¡ 0…01 ¡ 100 ¡ v ¡ tag tag ¡ ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ block ¡offset ¡ 6 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  7. University ¡of ¡Washington ¡ Example: ¡Direct-­‑Mapped ¡Cache ¡(E ¡= ¡1) ¡ Direct-­‑mapped: ¡One ¡line ¡per ¡set ¡ Assume: ¡cache ¡block ¡size ¡8 ¡bytes ¡ Address ¡of ¡int: ¡ valid? ¡ ¡ ¡+ ¡ match?: ¡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 ¡ 7 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  8. University ¡of ¡Washington ¡ Assume ¡sum, ¡i, ¡j ¡in ¡registers ¡ Address ¡of ¡an ¡aligned ¡element ¡ Example ¡(for ¡E ¡= ¡1) ¡ of ¡a: ¡ ¡ aa...ayyyyxxxx000 Assume: ¡cold ¡(empty) ¡cache ¡ int sum_array_rows(double a[16][16]) 3 ¡bits ¡for ¡set, ¡5 ¡bits ¡for ¡offset ¡ { aa...ayyy yxx xx000 int i, j; 0,4: ¡ aa...a000 001 00000 2,0: ¡ aa...a001 000 00000 1,0: ¡ aa...a000 100 00000 0,0: ¡ aa...a000 000 00000 double sum = 0; for (i = 0; i < 16; i++) 4,0 ¡ 4,1 ¡ 4,2 ¡ 4,3 ¡ 0,0 ¡ 0,1 ¡ 0,2 ¡ 0,3 ¡ 2,0 ¡ 2,1 ¡ 2,2 ¡ 2,3 ¡ 0,0 ¡ 0,1 ¡ 0,2 ¡ 0,3 ¡ for (j = 0; j < 16; j++) 0,4 ¡ 0,5 ¡ 0,6 ¡ 0,7 ¡ sum += a[i][j]; return sum; 0,8 ¡ 0,9 ¡ 0,a ¡ 0,b ¡ } 0,c ¡ 0,d ¡ 0,e ¡ 0,f ¡ 3,0 ¡ 3,1 ¡ 3,2 ¡ 3,3 ¡ 1,0 ¡ 1,1 ¡ 1,2 ¡ 1,3 ¡ 1,0 ¡ 1,1 ¡ 1,2 ¡ 1,3 ¡ int sum_array_cols(double a[16][16]) 1,4 ¡ 1,5 ¡ 1,6 ¡ 1,7 ¡ { int i, j; 1,8 ¡ 1,9 ¡ 1,a ¡ 1,b ¡ double sum = 0; 1,c ¡ 1,d ¡ 1,e ¡ 1,f ¡ for (j = 0; j < 16; j++) for (i = 0; i < 16; i++) 32 ¡B ¡= ¡4 ¡doubles ¡ 32 ¡B ¡= ¡4 ¡doubles ¡ sum += a[i][j]; return sum; 4 ¡misses ¡per ¡row ¡of ¡array ¡ every ¡access ¡a ¡miss ¡ } 4*16 ¡= ¡64 ¡misses ¡ 16*16 ¡= ¡256 ¡misses 8 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  9. University ¡of ¡Washington ¡ Example ¡(for ¡E ¡= ¡1) ¡ In ¡this ¡example, ¡cache ¡blocks ¡are ¡ 16 ¡bytes; ¡8 ¡sets ¡in ¡cache ¡ ¡How ¡many ¡block ¡offset ¡bits? ¡ ¡How ¡many ¡set ¡index ¡bits? ¡ float dotprod(float x[8], float y[8]) { ¡ Address ¡bits: ¡it....t ¡sss ¡bbbb ¡ float sum = 0; int i; ¡B ¡= ¡16 ¡= ¡2 b : ¡b=4 ¡offset ¡bits ¡ ¡S ¡= ¡ ¡ ¡8 ¡= ¡2 s : ¡s=3 ¡index ¡bits ¡ for (i = 0; i < 8; i++) ¡ sum += x[i]*y[i]; 0: ¡ ¡000....0 ¡000 ¡0000 ¡ return sum; 128: ¡000....1 ¡000 ¡0000 ¡ } 160: ¡000....1 ¡010 ¡0000 ¡ ¡ x[0] ¡ x[1] ¡ x[2] ¡ x[3] ¡ y[0] ¡ y[1] ¡ y[2] ¡ y[3] ¡ x[0] ¡ x[1] ¡ x[2] ¡ x[3] ¡ y[0] ¡ y[1] ¡ y[2] ¡ y[3] ¡ x[0] ¡ x[1] ¡ x[2] ¡ x[3] ¡ x[0] ¡ x[1] ¡ x[2] ¡ x[3] ¡ x[4] ¡ x[5] ¡ x[6] ¡ x[7] ¡ if ¡x ¡and ¡y ¡have ¡aligned ¡ ¡ if ¡x ¡and ¡y ¡have ¡unaligned ¡ ¡ y[0] ¡ y[1] ¡ y[2] ¡ y[3] ¡ starJng ¡addresses, ¡ ¡ starJng ¡addresses, ¡ ¡ y[4] ¡ y[5] ¡ y[6] ¡ y[7] ¡ e.g., ¡&x[0] ¡= ¡0, ¡&y[0] ¡= ¡128 ¡ e.g., ¡&x[0] ¡= ¡0, ¡&y[0] ¡= ¡160 ¡ 9 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  10. University ¡of ¡Washington ¡ E-­‑way ¡Set-­‑AssociaJve ¡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 10 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  11. University ¡of ¡Washington ¡ E-­‑way ¡Set-­‑AssociaJve ¡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 ¡ tag ¡ v tag ¡ 0 1 2 3 4 5 6 7 v tag ¡ 0 1 2 3 4 5 6 7 block ¡offset ¡ 11 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

  12. University ¡of ¡Washington ¡ E-­‑way ¡Set-­‑AssociaJve ¡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 ¡evicJon ¡and ¡replacement ¡ • Replacement ¡policies: ¡random, ¡least ¡recently ¡used ¡(LRU), ¡… ¡ 12 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡II ¡

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