edited by
876 views
1 votes
1 votes

In a system, integer has size of $4$ bytes. The system has $1024$ KB set associative cache with associativity $2$ and block size of $32$ bytes. Consider the program below. Assuming that initially A was not present in cache, cache hit ratio is ____

for(int i=0;i < 64;i++)
{
    A[i] = A[i]+2;
    A[i+1] = A[i]+3;
}
edited by

1 Answer

Best answer
1 votes
1 votes
Size of one Block = 32 B = 8 Integers.

We are accessing 64 integers which corresponds to $64/8 = 8$ blocks (as array is stored in continuous memory locations).

No. of sets in the cache = 1024/(32 * 2) = 16.

So, there won't be any collision for the cache blocks here.

Now here, for a single iteration we have 4 memory references, 3 to A[i] and one to A[i+1]. When A[0] is brought to cache as told in first line A[0]-A[1] are also taken to cache. So, no. of cache misses and hits in each iteration goes like these:

1, 3
0, 4
0, 4
0, 4
0, 4
0, 4
0, 4
1, 3 -- in the seventh iteration access A[i+1] causes the next cache line to be filled.
0, 4
....

So we have 2 cache miss in the first 8 iterations and 1 for every remaining consecutive 8 iterations.

The cycle repeats every 8 iterations and since $64 \mod 8= 0$, we have no remaining iterations. We have 4 memory access per iteration and 64 iterations. So, hit ratio for entire program is

$ = \frac{30+ 31\times7}{4 \times 64 } = \frac{247}{256}.$
edited by

Related questions

2 votes
2 votes
2 answers
1
8 votes
8 votes
4 answers
2
0 votes
0 votes
1 answer
3
nirupama thakur asked Mar 17, 2018
2,004 views
In some problems we multiply only with the second part of the equation with (1-H1) component and leave the first part. Whereas in other cases we multiply with cache hit a...