Al locality items with nearby addresses tend to be

Info iconThis 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

This document was uploaded on 04/04/2014.

Ask a homework question - tutors are online