Lec14-Cache_measurement

Huge difference between a hit and a miss could 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: in memory • Average access time = hit time + (miss rate × miss penalty) Stephen Chong, Harvard University 6 Wait, what do those numbers mean? • 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 time of 1 cycle miss penalty of 100 cycles • Average access time: • 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” Stephen Chong, Harvard University 7 Writing Cache Friendly Code • Repeated references to variables are good (temporal locality) • Stride-1 reference patterns are good (spatial locality) • Examples: • cold cache, 4-byte words, 4-word cache blocks int sum_array_rows(int a[M][N]) { int i, j, sum = 0; int sum_array_cols(int a[M][N]) { int i, j, sum = 0; for (i = 0; i < M; i++) for (j = 0; j < N; j++) sum += a[i][j]; return sum; } for (j = 0; j < N; j++) for (i = 0; i < M; i++) sum += a[i][j]; return sum; } Miss rate = Stephen Chong, Harvard University 1/4 = 25% Miss rate = 100% 8 Determining cache characteristics • Say you have a machine but don’t know its cache size or speeds. • How would you figure these values out? • Idea: Write a program to measure the cache's behavior and performance. • Program needs to perform memory accesses with different locality patterns. • Simple approach: • Allocate array of size W words • Loop over the array repeatedly with stride S and measure memory access time • Vary W and S to estimate cache characteristics S = 4 words Stephen Chong, Harvard University W = 32 words 9 Determining cache characteristics S = 4 words W = 32 words • What happens as you vary W and S? • Changing W varies total amount of memory accessed by program • As W gets larger than one cache level, performance of program will drop • Changing S varies the spatial locality of each access...
View Full Document

This note was uploaded on 10/19/2012 for the course CS 61 taught by Professor Eddiekohler during the Fall '12 term at Carnegie Mellon.

Ask a homework question - tutors are online