To calculate the L1 D-cache miss rate for the given function, we first need to understand how the cache works and how memory accesses will be handled.
Since the cache is a 2-way set associative with 64KB size and 64-byte blocks, we have:
- Total sets: 64KB / (2 * 64B) = 64KB / 128B = 512 sets
- Each matrix is 128x128 integers, so the total size of each matrix is 128 * 128 * 4 bytes = 65,536 bytes
Now, let's analyze the memory accesses:
- Each loop iteration accesses a[i][j], b[i][j], and c[i][j], which are all 4 bytes each.
- The arrays a, b, and c are 16 bytes apart (4 integers * 4 bytes). Since the cache block size is 64 bytes, they will be in different cache lines.
Since a, b, and c are initially not in the cache, the first access to any element of each matrix will cause a compulsory miss. There will be 128 * 128 accesses for each matrix, leading to a total of 3 * (128 * 128) compulsory misses.
After the first access, subsequent accesses to elements within the same matrix will hit in the cache, as they are in the same 64-byte block. However, since the cache is 2-way associative, at most 2 elements from a, b, or c can be stored in a set at a time. If two elements from different matrices are loaded into the same set, a conflict miss will occur when accessing the third element from the third matrix.
To calculate the conflict misses, we need to determine how many elements from each matrix can be stored in the cache before a conflict occurs. For simplicity, we will assume that the matrices are accessed linearly (row by row). With 512 sets and 64-byte blocks, each set can hold 2 * 4 = 8 integers. Since there are 128 * 128 = 16384 integers in a matrix, we have:
Cacheable integers per set = 8
Total integers in a matrix = 16384
Conflict miss rate = (1 - (Cacheable integers per set / Total integers in a matrix))^3
Conflict miss rate = (1 - (8 / 16384))^3
Conflict miss rate ≈ (1 - (0.0005)^3 ≈ 1
So, conflict misses are negligible.
Total misses = Compulsory misses
Total misses = 3 * (128 * 128)
Total misses = 3 * 16384
Total misses = 49152
L1 D-cache miss rate = (Total misses) / (Total accesses)
Total accesses = 3 * (128 * 128) (accesses to a, b, and c)
Total accesses = 3 * 16384
Total accesses = 49152
L1 D-cache miss rate = 49152 / 49152
L1 D-cache miss rate = 1
So, the L1 D-cache miss rate of the matrix_add function is 100%, and all misses are contributed by compulsory misses as conflict misses are negligible.