{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Al locality items with nearby addresses tend to be

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: on 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 to be referenced again in the near future   block Spa?al locality:   Items with nearby addresses tend to be referenced close together in :me   How do caches take advantage of this? Caches and Locality block 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 paTern   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 Caches and Locality University of Washington Another Locality Example int sum_array_3d(int a[M][N][N]) { int i, j, k, sum = 0; }     for (i = 0; i < N; i++) for (j = 0; j < N; j++) for (k = 0; k < M; k++) sum += a[k][i][j]; return sum; What is wrong with this code? How can it be fixed? Caches and Locality University of Washington Memory and Caches           Cache basics Principle of locality Memory hierarchies Cache organiza?on Program op?miza?ons that consider caches Caches  ­ Memory Hierarchy 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” Caches  ­ Memory Hierarchy University of Washington Cache...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern