Question

In: Computer Science

Assume a computer with a cache that holds 64 bytes and has a block size of...

Assume a computer with a cache that holds 64 bytes and has a block size of 32 bytes. Direct address mapping is used and from the beginning the cache is empty. The following program sequence is executed:

for (col = 0; col < 2; col++) {

for (row = 0; row < 4; row++)

A[row][col] = B[row] * C[col]; }

Assume that for the variables row and col registers are used.
The matrix A consists of 4 rows and 4 columns with integers (one word long). A is located in the RAM with start address 0 and is stored in rows (A [0] [0], A [0] [1], ... ).
Array B consists of 4 integers (one word long). B is located in RAM with start address 64.
The arrayC consists of 4 integers (one word long). C is located in RAM with start address 80.
What will be the hit probability for the program sequence? What will be the hit probability if 2-way set associative address mapping (with LRU when changing blocks) is used instead of direct address mapping? Also write explanations of how the calculations are done and interpret the results. (Note that the outer loop runs twice and the inner one four times. There will be a total of 24 memory references.)

Solutions

Expert Solution

Number of lines in cache

= Cache size / Line size

= 32 words / 8 words

= 4 lines

Since each element of the array occupies 4 words, so-

Number of elements that can be placed in one line = 2

Now, let us analyze the statement-

A[i] = A[i] + 10;

For each i,

  • Firstly, the value of A[i] is read.
  • Secondly, 10 is added to the A[i].
  • Thirdly, the updated value of A[i] is written back.

Thus,

  • For each i, A[i] is accessed two times.
  • Two memory accesses are required-one for read operation and other for write operation.

Assume the cache is all empty initially.

In the first loop iteration,

  • First, value of A[0] has to be read.
  • Since cache is empty, so A[0] is brought in the cache.
  • Along with A[0], element A[1] also enters the cache since each block can hold 2 elements of the array.

  • Thus, For A[0], a miss occurred for the read operation.
  • Now, 10 is added to the value of A[0].
  • Now, the updated value has to be written back to A[0].
  • Again cache memory is accessed to get A[0] for writing its updated value.
  • This time, for A[0], a hit occurs for the write operation.

In the second loop iteration,

  • First, value of A[1] has to be read.
  • A[1] is already present in the cache.
  • Thus, For A[1]. a hit occurs for the read operation.
  • Now, 10 is added to the value of A[1].
  • Now, the updated value has to be written back to A[1].
  • Again cache memory is accessed to get A[1] for writing its updated value.
  • Again, for A[1], a hit occurs for the write operation.

In the similar manner, for every next two consecutive elements-

  • There will be a miss for the read operation for the first element.
  • There will be a hit for the write operation for the first element.
  • There will be a hit for both read and write operations for the second element.

Likewise, for 100 elements, we will have 50 such pairs in cache and in every pair, there will be one miss and three hits.

Thus,

  • Total number of hits = 50 x 3 = 150
  • Total number of misses = 50 x 1 = 50
  • Total number of references = 200 (100 for read and 100 for write)

Thus,

  • Hit ratio = 150 / 200 = 3 / 4 = 0.75
  • Miss ratio = 50 / 200 = 1 / 4 = 0.25

Related Solutions

A direct mapped cache has 16 blocks and block size is 64-bits (8 bytes). a. Where...
A direct mapped cache has 16 blocks and block size is 64-bits (8 bytes). a. Where will the memory block 45 reside in cache? (5 b. Where will be the memory address 1667 mapped in cache
Suppose a computer using direct mapped cache has 232 bytes of main memory and a cache...
Suppose a computer using direct mapped cache has 232 bytes of main memory and a cache of 1024 blocks, where each block contains 32 bytes. [2] How many blocks of main memory does this computer have? [4] Show the format of a memory address as seen by cache; be sure to include the field names as well as their sizes. [3] Given the memory address 0x00001328, to which cache block will this address map? (Give you answer in decimal.) A...
Computer archieture 1. Assume that the cache size is 512kB, and each cache line is 128...
Computer archieture 1. Assume that the cache size is 512kB, and each cache line is 128 Bytes. If it’s a 4-way associative cache, how many sets are there? If it’s a 2-way associative cache, how many sets are there? Let’s assume the cache is initially empty, and LRU policy is used for cache line replacement. If the following memory blocks are accessed: Mem-block # 7, 1031, 2055, 4103, 1031, 7, 2055, 3079, 1031, 3079 What is the cache hit/miss rate...
Suppose a computer using direct mapped cache has 224 bytes of byte-addressable main memory, and a...
Suppose a computer using direct mapped cache has 224 bytes of byte-addressable main memory, and a cache of 128 blocks, where each cache block contains 8 bytes. For fully associative cache, to which block of cache the address 0x189B5A maps? Group of answer choices Block 6 Block 75 Not enough information Block 10
Consider a disk with block size B = 512 bytes. A block pointer is P =...
Consider a disk with block size B = 512 bytes. A block pointer is P = 6 bytes long, and a record pointer is PR = 7 bytes long. A file has r = 30,000 EMPLOYEE records of fixed length. Each record has the following fields: Name (30 bytes),Ssn (9 bytes), Department_code (9 bytes), Address (40 bytes), Phone (10 bytes), Birth_date (8 bytes), Sex (1 byte), Job_code (4 bytes), and Salary (4 bytes, real number). An additional byte is used...
Below are listed parameters for different direct-mapped cache designs. Cache Data Size: 32 KiB Cache Block...
Below are listed parameters for different direct-mapped cache designs. Cache Data Size: 32 KiB Cache Block Size: 2 words Cache Access Time: 1 cycle Word: 4 bytes. Calculate the total number of bits required for the cache listed above, assuming a 32-bit address. Given that total size, find the total size of the closest direct-mapped cache with 16-word blocks of equal size or greater. Explain why the second cache, despite its larger data size, might provide slower performance than the...
Consider a 4-way set-associative cache, 4 rows, a line size of 128 bytes and a write-back...
Consider a 4-way set-associative cache, 4 rows, a line size of 128 bytes and a write-back policy. The following requests are made to memory: Load: 0b0011111001000101 Load: 0b1000111110110100 Load: 0b0110101111110100 Store: 0b0010110000000110 Store: 0b1111001001110101 Store: 0b1110000111000001 Load: 0b0000000010100110 Load: 0b0101001001001101 Assuming the machine is in cold-start, profile the contents to the cache after all of the requests have been made. State any assumption you make (if needed).
6. Assume a computer has a physical memory organized into 64-bit words. Using hexadecimal notation, give...
6. Assume a computer has a physical memory organized into 64-bit words. Using hexadecimal notation, give the word address and offset within the word for each of the following byte addresses. Byte address Word address Offset 0x000b 0x03ff 0x07fc
6 C++ Questions: 19. Assuming an int is size 4 bytes, what is the size in...
6 C++ Questions: 19. Assuming an int is size 4 bytes, what is the size in memory of the below array: int cards[10] = {7, 4, 7, 5, 7}; 20. In the array from question 19, what is the value of the below elements: cards[1]; cards[8]; Assume you have an array with 128 integers which is sorted from lowest to highest. 21a. You are searching for a value which is contained in the array using the binary search algorithm. What...
Consider a computer system with a 64-bit logical address and 8-KB page size. The system supports...
Consider a computer system with a 64-bit logical address and 8-KB page size. The system supports up to 1024 MB of physical memory: How many entries are there in each of the following in the page table? Describe how a logical address may be used to obtain the frame number. You may use the virtual address 14533956 to illustrate your answer. make it short and clear , please type in your keyboard.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT