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 I University of Washington Roadmap Data & addressing


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

  2. University ¡of ¡Washington ¡ Roadmap ¡ Data ¡& ¡addressing ¡ Integers ¡& ¡floats ¡ Machine ¡code ¡& ¡C ¡ C: ¡ Java: ¡ x86 ¡assembly ¡ Car c = new Car(); car *c = malloc(sizeof(car)); programming ¡ c.setMiles(100); c->miles = 100; Procedures ¡& ¡ c.setGals(17); c->gals = 17; stacks ¡ float mpg = float mpg = get_mpg(c); Arrays ¡& ¡structs ¡ c.getMPG(); free(c); Memory ¡& ¡caches ¡ Processes ¡ Assembly ¡ get_mpg: Virtual ¡memory ¡ pushq %rbp language: ¡ movq %rsp, %rbp Memory ¡allocaPon ¡ ... Java ¡vs. ¡C ¡ popq %rbp ret OS: ¡ Machine ¡ 0111010000011000 100011010000010000000010 code: ¡ 1000100111000010 110000011111101000011111 Computer ¡ system: ¡ 2 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  3. University ¡of ¡Washington ¡ Themes ¡of ¡CSE ¡351 ¡  Interfaces ¡and ¡abstracPons ¡  So ¡far: ¡data ¡type ¡abstrac:ons ¡in ¡C; ¡x86 ¡instruc:on ¡set ¡architecture ¡ (interface ¡to ¡hardware) ¡  Today: ¡abstrac:ons ¡of ¡ memory ¡  Soon: ¡process ¡and ¡virtual ¡memory ¡abstrac:ons ¡  RepresentaPon ¡  Integers, ¡floats, ¡addresses, ¡arrays, ¡structs ¡  TranslaPon ¡  Understand ¡the ¡assembly ¡code ¡that ¡will ¡be ¡generated ¡from ¡C ¡code ¡  Control ¡flow ¡  Procedures ¡and ¡stacks; ¡buffer ¡overflows ¡ 3 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  4. University ¡of ¡Washington ¡ Making ¡memory ¡accesses ¡fast! ¡  Cache ¡basics ¡  Principle ¡of ¡locality ¡  Memory ¡hierarchies ¡  Cache ¡organizaPon ¡  Program ¡opPmizaPons ¡that ¡consider ¡caches ¡ 4 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  5. University ¡of ¡Washington ¡ How ¡does ¡execuPon ¡Pme ¡grow ¡with ¡SIZE? ¡ int array[SIZE]; int A = 0; for (int i = 0 ; i < 200000 ; ++ i) { for (int j = 0 ; j < SIZE ; ++ j) { A += array[j]; } } TIME Plot SIZE 5 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  6. University ¡of ¡Washington ¡ Actual ¡Data ¡ Time ¡ SIZE ¡ 6 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  7. University ¡of ¡Washington ¡ Problem: ¡Processor-­‑Memory ¡Bo^leneck ¡ Processor ¡performance ¡ doubled ¡about ¡ ¡ Bus ¡bandwidth ¡ every ¡18 ¡months ¡ evolved ¡much ¡slower ¡ Main ¡ CPU ¡ Reg ¡ Memory ¡ Core ¡2 ¡Duo: ¡ Core ¡2 ¡Duo: ¡ Can ¡process ¡at ¡least ¡ Bandwidth ¡ 256 ¡Bytes/cycle ¡ 2 ¡Bytes/cycle ¡ Latency ¡ 100 ¡cycles ¡ Problem: ¡lots ¡of ¡wai4ng ¡on ¡memory ¡ 7 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  8. University ¡of ¡Washington ¡ Problem: ¡Processor-­‑Memory ¡Bo^leneck ¡ Processor ¡performance ¡ doubled ¡about ¡ ¡ Bus ¡bandwidth ¡ every ¡18 ¡months ¡ evolved ¡much ¡slower ¡ Main ¡ CPU ¡ Reg ¡ Cache ¡ Memory ¡ Core ¡2 ¡Duo: ¡ Core ¡2 ¡Duo: ¡ Can ¡process ¡at ¡least ¡ Bandwidth ¡ 256 ¡Bytes/cycle ¡ 2 ¡Bytes/cycle ¡ Latency ¡ 100 ¡cycles ¡ Solu4on: ¡caches ¡ 8 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  9. University ¡of ¡Washington ¡ Cache ¡  English ¡definiPon: ¡a ¡hidden ¡storage ¡space ¡for ¡provisions, ¡ weapons, ¡and/or ¡treasures ¡ ¡  CSE ¡definiPon: ¡computer ¡memory ¡with ¡short ¡access ¡Pme ¡used ¡ for ¡the ¡storage ¡of ¡frequently ¡or ¡recently ¡used ¡instrucPons ¡or ¡ data ¡(i-­‑cache ¡and ¡d-­‑cache) ¡ ¡ more ¡generally, ¡ ¡ used ¡to ¡opPmize ¡data ¡transfers ¡between ¡system ¡elements ¡ with ¡different ¡characterisPcs ¡(network ¡interface ¡cache, ¡I/O ¡ cache, ¡etc.) ¡ 9 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  10. University ¡of ¡Washington ¡ General ¡Cache ¡Mechanics ¡ Smaller, ¡faster, ¡more ¡expensive ¡ Cache ¡ 8 ¡ 9 ¡ 14 ¡ 3 ¡ memory ¡caches ¡a ¡subset ¡of ¡ the ¡blocks ¡ Data ¡is ¡copied ¡in ¡block-­‑sized ¡ transfer ¡units ¡ Larger, ¡slower, ¡cheaper ¡memory ¡ Memory ¡ viewed ¡as ¡parPPoned ¡into ¡“blocks” ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 8 ¡ 9 ¡ 10 ¡ 11 ¡ 12 ¡ 13 ¡ 14 ¡ 15 ¡ 10 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  11. University ¡of ¡Washington ¡ General ¡Cache ¡Concepts: ¡Hit ¡ Data ¡in ¡block ¡b ¡is ¡needed ¡ Request: ¡14 ¡ Block ¡b ¡is ¡in ¡cache: ¡ Cache ¡ 8 ¡ 9 ¡ 14 ¡ 3 ¡ 14 ¡ Hit! ¡ Memory ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 8 ¡ 9 ¡ 10 ¡ 11 ¡ 12 ¡ 13 ¡ 14 ¡ 15 ¡ 11 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  12. University ¡of ¡Washington ¡ General ¡Cache ¡Concepts: ¡Miss ¡ Data ¡in ¡block ¡b ¡is ¡needed ¡ Request: ¡12 ¡ Block ¡b ¡is ¡not ¡in ¡cache: ¡ Cache ¡ 8 ¡ 9 ¡ 14 ¡ 3 ¡ 12 ¡ Miss! ¡ Block ¡b ¡is ¡fetched ¡from ¡ Request: ¡12 ¡ 12 ¡ memory ¡ Block ¡b ¡is ¡stored ¡in ¡cache ¡ Memory ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ • Placement ¡policy: ¡ determines ¡where ¡b ¡goes ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ • Replacement ¡policy: ¡ 8 ¡ 9 ¡ 10 ¡ 11 ¡ determines ¡which ¡block ¡ 12 12 ¡ ¡ 13 ¡ 14 ¡ 15 ¡ gets ¡evicted ¡(vic:m) ¡ 12 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  13. University ¡of ¡Washington ¡ Cost ¡of ¡Cache ¡Misses ¡  Huge ¡difference ¡between ¡a ¡hit ¡and ¡a ¡miss ¡  Could ¡be ¡100x, ¡if ¡just ¡L1 ¡and ¡main ¡memory ¡  Would ¡you ¡believe ¡99% ¡hits ¡is ¡twice ¡as ¡good ¡as ¡97%? ¡  Consider: ¡ ¡ ¡Cache ¡hit ¡:me ¡of ¡1 ¡cycle ¡ ¡Miss ¡penalty ¡of ¡100 ¡cycles ¡  Average ¡access ¡:me: ¡  97% ¡hits: ¡ ¡1 ¡cycle ¡+ ¡0.03 ¡* ¡100 ¡cycles ¡= ¡4 ¡cycles ¡  99% ¡hits: ¡ ¡1 ¡cycle ¡+ ¡0.01 ¡* ¡100 ¡cycles ¡= ¡2 ¡cycles ¡  This ¡is ¡why ¡“miss ¡rate” ¡is ¡used ¡instead ¡of ¡“hit ¡rate” ¡ 13 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  14. University ¡of ¡Washington ¡ Why ¡Caches ¡Work ¡  Locality: ¡Programs ¡tend ¡to ¡use ¡data ¡and ¡instrucPons ¡with ¡ addresses ¡near ¡or ¡equal ¡to ¡those ¡they ¡have ¡used ¡recently ¡  Temporal ¡locality: ¡ ¡ ¡  Recently ¡referenced ¡items ¡are ¡likely ¡ ¡ block ¡ to ¡be ¡referenced ¡again ¡in ¡the ¡near ¡future ¡  Why ¡is ¡this ¡important? ¡ ¡  SpaPal ¡locality: ¡ ¡ ¡  Items ¡with ¡nearby ¡addresses ¡tend ¡ ¡ block ¡ to ¡be ¡referenced ¡close ¡together ¡in ¡:me ¡  How ¡do ¡caches ¡take ¡advantage ¡of ¡this? ¡ ¡ 14 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  15. University ¡of ¡Washington ¡ Example: ¡Locality? ¡ sum = 0; for (i = 0; i < n; i++) sum += a[i]; return sum;  Data: ¡  Temporal: ¡ sum ¡referenced ¡in ¡each ¡itera:on ¡  Spa:al: ¡array ¡ a[] ¡ accessed ¡in ¡stride-­‑1 ¡pabern ¡  InstrucPons: ¡  Temporal: ¡cycle ¡through ¡loop ¡repeatedly ¡  Spa:al: ¡reference ¡instruc:ons ¡in ¡sequence ¡  Being ¡able ¡to ¡assess ¡the ¡locality ¡of ¡code ¡is ¡a ¡crucial ¡skill ¡ for ¡a ¡programmer ¡ ¡ 15 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

  16. University ¡of ¡Washington ¡ Locality ¡Example ¡#1 ¡ int sum_array_rows(int a[M][N]) { int i, j, sum = 0; a[0][0] ¡ a[0][1] ¡ a[0][2] ¡ a[0][3] ¡ a[1][0] ¡ a[1][1] ¡ a[1][2] ¡ a[1][3] ¡ for (i = 0; i < M; i++) a[2][0] ¡ a[2][1] ¡ a[2][2] ¡ a[2][3] ¡ for (j = 0; j < N; j++) sum += a[i][j]; ¡ ¡1: ¡a[0][0] ¡ ¡ ¡2: ¡a[0][1] ¡ return sum; ¡ ¡3: ¡a[0][2] ¡ } ¡ ¡4: ¡a[0][3] ¡ ¡ ¡5: ¡a[1][0] ¡ ¡ ¡6: ¡a[1][1] ¡ ¡ ¡7: ¡a[1][2] ¡ ¡ ¡8: ¡a[1][3] ¡ ¡ ¡9: ¡a[2][0] ¡ 10: ¡a[2][1] ¡ 11: ¡a[2][2] ¡ 12: ¡a[2][3] ¡ stride-­‑1 ¡ 16 ¡ Winter ¡2013 ¡ Memory ¡and ¡Caches ¡I ¡

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