Memory Hierarchy
int a[1024];
for (i = 0; i < 1024; i++)
sum += a[i];In the loop above, an int is 4 bytes, a cache line is 64 bytes, and the array is not cached and starts on a line boundary. Without prefetching, what is the miss rate for reading the array?
- A12.5%
- B6.25%
- C100%
Show answer and explanation
Answer: B. 6.25%
A 64-byte line holdsints. Reading in order misses once on the first element of each line and hits on the remaining 15, so the miss rate is. For 1,024 elements that ismisses. 12.5% would result from thinking only eight elements fit in a line. 100% occurs only when one element per line is used, such as reading every 16th element (every 64 bytes).
- A. 12.5% results from assuming eight elements per line.
- B. Correct. One miss every 16 elements gives 1/16 = 6.25%.
- C. 100% occurs with strided access that uses one element per line.