more caches yes
play

More $ (caches, yes) Trick or treat! Midterm - PowerPoint PPT Presentation

University of Washington More $ (caches, yes) Trick or treat! Midterm ques>ons? Note: prac+ce midterms posted HW 2 due today Lab


  1. University ¡of ¡Washington ¡ More ¡$ ¡(caches, ¡yes) ¡ ¢ Trick ¡or ¡treat! ¡ ¢ Midterm ¡ques>ons? ¡ § Note: ¡prac+ce ¡midterms ¡posted ¡ ¢ HW ¡2 ¡due ¡today ¡ ¢ Lab ¡3 ¡will ¡be ¡released ¡soon ¡ § You ¡will ¡implement ¡a ¡buffer ¡overflow ¡a9ack! ¡Huahuahua! ¡ J ¡ ¡ 1 ¡

  2. University ¡of ¡Washington ¡ Deja-vu int array[SIZE]; int A = 0; for (int i = 0 ; i < 200000 ; ++ i) { for (int j = 0 ; j < SIZE ; ++ j) { A += array[j]; } } Runtime Plot SIZE 2 ¡

  3. University ¡of ¡Washington ¡ Not ¡to ¡forget… ¡ CPU A little of super fast memory (cache$) Lots of slower Mem 3 ¡

  4. 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 ¡par>>oned ¡into ¡“blocks” ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 8 ¡ 9 ¡ 10 ¡ 11 ¡ 12 ¡ 13 ¡ 14 ¡ 15 ¡ 4 ¡

  5. 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 ¡ Hit! ¡ Memory ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 8 ¡ 9 ¡ 10 ¡ 11 ¡ 12 ¡ 13 ¡ 14 ¡ 15 ¡ 5 ¡

  6. 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 ¡ Miss! ¡ Oh ¡no! ¡What ¡now? ¡ Request: ¡12 ¡ Memory ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 8 ¡ 9 ¡ 10 ¡ 11 ¡ 12 ¡ 13 ¡ 14 ¡ 15 ¡ 6 ¡

  7. 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 ¡ Miss! ¡ Block ¡b ¡is ¡fetched ¡from ¡ Request: ¡12 ¡ memory ¡ Memory ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 8 ¡ 9 ¡ 10 ¡ 11 ¡ 12 ¡ 13 ¡ 14 ¡ 15 ¡ 7 ¡

  8. 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 ¡ 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 ¡ 13 ¡ 14 ¡ 15 ¡ gets ¡evicted ¡(vic+m) ¡ 8 ¡

  9. University ¡of ¡Washington ¡ Cache ¡Performance ¡Metrics ¡ Miss ¡Rate ¡ ¢ § Frac+on ¡of ¡memory ¡references ¡not ¡found ¡in ¡cache ¡(misses ¡/ ¡accesses) ¡ = ¡1 ¡– ¡hit ¡rate ¡ § Typical ¡numbers ¡(in ¡percentages): ¡ CPU 3-­‑10% ¡for ¡L1 ¡ § can ¡be ¡quite ¡small ¡(e.g., ¡< ¡1%) ¡for ¡L2, ¡depending ¡on ¡size, ¡etc. ¡ § Hit ¡Time ¡ ¢ § Time ¡to ¡deliver ¡a ¡line ¡in ¡the ¡cache ¡to ¡the ¡processor ¡ $ includes ¡+me ¡to ¡determine ¡whether ¡the ¡line ¡is ¡in ¡the ¡cache ¡ § § Typical ¡numbers: ¡ 1-­‑2 ¡clock ¡cycle ¡for ¡L1 ¡ § 5-­‑20 ¡clock ¡cycles ¡for ¡L2 ¡ § Miss ¡Penalty ¡ ¢ Memory § Addi+onal ¡+me ¡required ¡because ¡of ¡a ¡miss ¡ typically ¡50-­‑200 ¡cycles ¡for ¡main ¡memory ¡( trend: ¡increasing! ) ¡ § 9 ¡

  10. University ¡of ¡Washington ¡ Lets ¡think ¡about ¡those ¡numbers ¡ ¢ 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 ¡ 10 ¡

  11. University ¡of ¡Washington ¡ Lets ¡think ¡about ¡those ¡numbers ¡ ¢ 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” ¡ 11 ¡

  12. University ¡of ¡Washington ¡ Why ¡do ¡caches ¡work? ¡ 12 ¡

  13. University ¡of ¡Washington ¡ Why ¡Caches ¡Work ¡ ¢ Locality: ¡Programs ¡tend ¡to ¡use ¡data ¡and ¡instruc>ons ¡with ¡ addresses ¡near ¡or ¡equal ¡to ¡those ¡they ¡have ¡used ¡recently ¡ ¡ 13 ¡

  14. University ¡of ¡Washington ¡ Why ¡Caches ¡Work ¡ ¢ Locality: ¡Programs ¡tend ¡to ¡use ¡data ¡and ¡instruc>ons ¡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? ¡ ¡ 14 ¡

  15. University ¡of ¡Washington ¡ Why ¡Caches ¡Work ¡ ¢ Locality: ¡Programs ¡tend ¡to ¡use ¡data ¡and ¡instruc>ons ¡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 ¡ ¢ Spa>al ¡locality? ¡ ¡ ¡ ¡ 15 ¡

  16. University ¡of ¡Washington ¡ Why ¡Caches ¡Work ¡ ¢ Locality: ¡Programs ¡tend ¡to ¡use ¡data ¡and ¡instruc>ons ¡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 ¡ ¢ Spa>al ¡locality: ¡ ¡ ¡ § Items ¡with ¡nearby ¡addresses ¡ tend ¡ ¡ to ¡be ¡referenced ¡close ¡together ¡in ¡+me ¡ block ¡ § How ¡do ¡caches ¡take ¡advantage ¡of ¡this? ¡ ¡ 16 ¡

  17. University ¡of ¡Washington ¡ Example: ¡Locality? ¡ sum = 0; for (i = 0; i < n; i++) sum += a[i]; return sum; 17 ¡

  18. 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 ¡pa9ern ¡ 18 ¡

  19. 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 ¡pa9ern ¡ ¢ Instruc>ons: ¡ § Temporal: ¡cycle ¡through ¡loop ¡repeatedly ¡ § Spa+al: ¡reference ¡instruc+ons ¡in ¡sequence ¡ 19 ¡

  20. 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 ¡pa9ern ¡ ¢ Instruc>ons: ¡ § 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 ¡ ¡ 20 ¡

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