1 / 17

Cache Read Operations and Miss Rate Analysis in an 1024-byte Direct-Mapped Cache

This problem involves analyzing the total number of read operations and the miss rate in a 1024-byte direct-mapped cache with 16-byte blocks. The code provided involves reading values from a structured grid. The problem also explores different loop scenarios and their impact on cache performance.

mapesj
Download Presentation

Cache Read Operations and Miss Rate Analysis in an 1024-byte Direct-Mapped Cache

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Problem 6.15 • 1024-byte direct-mapped cache • 16-byte blocks • sizeof(int) = 4 • struct algae_position{ int x; int y; }; • Struct algae_position grid[16][16]; • grid begins at memory address 0 • Some code: int total_x = 0, total_y = 0; int i, j; for (i = 0; i < 16; i++){ for (j=0; j < 16; j++){ total_x += grid[i][j].x; } } for (i = 0; i < 16; i++){ for (j=0; j < 16; j++){ total_y += grid[i][j].y; } }

  2. Problem 6.15 • What is the total number of reads? • What is the total number of reads that miss in the cache? • What is the miss rate?

  3. Problem 6.15 • Total number of reads:

  4. Problem 6.15 • Total number of reads: • One read per iteration of the each loop. • 16*16 = 256 Iterations in loop 1 • 16*16 = 256 iterations in loop 2 • 256+256 = 512 reads total

  5. Problem 6.15 • What is the total number of reads that miss the cache? • What does our cache look like?

  6. Problem 6.15 • 1024-byte direct-mapped cache • 16-byte blocks • There are 1024 bytes / (16 bytes/set) = 64 blocks • sizeof(int) = 4 • struct algae_position{ int x; int y; }; • sizeof(algae_position) = 8; • Each block can hold two algae_position’s • Struct algae_position grid[16][16]; • grid begins at memory address 0

  7. Problem 6.15 • struct algae_position{ int x; int y; }; • sizeof(algae_position) = 8; • Each block can hold two algae_position’s • Struct algae_position grid[16][16]; • grid begins at memory address 0 • Access to grid[0][0] or grid[0][1] will cause both ([0][0] and [0][1]) to be stored in block 0. • Access to grid[0][2] or grid[0][3] will cause both to be stored in block 1. • Etc…

  8. Problem 6.15 • 1024-byte direct-mapped cache • 16-byte blocks • There are 1024 bytes / (8 bytes/block) = 128 blocks struct algae_position{ int x; int y; }; • sizeof(algae_position) = 8; • Each block can hold two algae_position’s • Struct algae_position grid[16][16]; • grid begins at memory address 0 • Access to grid[0][0] or grid[0][1] will cause both ([0][0] and [0][1]) to be stored in block 0. • There are 64 blocks total, each block can hold 2 algae_position’s. • The first row of grid[][] will take up the first 8 blocks. • The cache will be full after we read the first 128 / 8 = 16 rows of grid[][]. • Any reads after that will evict previously stored items in the cache.

  9. Problem 6.15 • There are 128 blocks total, each block can hold 2 algae_position’s. • The first row of grid[][] will take up the first 8 blocks. • The cache will be full after we read the first 128/8 = 16 rows of grid[][]. • Any reads after that will evict previously stored items in the cache. • This means that we can consider each loop separately since all the first 16 rows the second loop is accessing will have been evicted by the later reads (of the last 16 rows) of the first loop.

  10. Problem 6.15 /* First loop */ for (i = 0; i < 16; i++){ for (j = 0; j < 16; j++){ total_x += grid[i][j].x; } } • In the first loop: • Access grid[0][0].x -- Miss • Both grid[0][0] and grid[0][1] are stored in block 0. • Access grid[0][1].x -- Hit • Access grid[0][2].x –- Miss • Access grid[0][3].x –- Hit • ... • 256 reads, 128 of them are misses.

  11. Problem 6.15 /* Second loop */ for (i = 0; i < 16; i++){ for (j = 0; j < 16; j++){ total_y += grid[i][j].y; } } • In the first loop: • Access grid[0][0].y -- Miss • Both grid[0][0] and grid[0][1] are stored in block 0. • Access grid[0][1].y -- Hit • Access grid[0][2].y –- Miss • Access grid[0][3].y –- Hit • ... • 256 reads, 128 of them are misses.

  12. Problem 6.15 • What is the total number of reads? • 512 • What is the total number of reads that miss in the cache? • 128 (first loop) + 128 (second loop) = 256 • What is the miss rate? • 256 misses/ 512 reads = 50%

  13. Problem 6.16 • What if our loop looked like this? for (i =0; i < 16; i++){ for (j = 0; j < 16; j++){ total_x += grid[j][i].x; total_y += grid[j][i].y; } }

  14. Problem 6.16 • What if our loop looked like this? for (i =0; i < 16; i++){ for (j = 0; j < 16; j++){ total_x += grid[j][i].x; total_y += grid[j][i].y; } }

  15. Problem 6.16 • What if our loop looked like this? for (i =0; i < 16; i++){ for (j = 0; j < 16; j++){ total_x += grid[j][i].x; total_y += grid[j][i].y; } } • We are going down column by column to sum the coordinates. • The cache can only hold half of the elements in the array, so that means that a read to grid[8][0] will evict the block that was loaded when we read grid[0][0]. Since this block also contained grid[0][1], the first read of grid[0][1] will be a miss. • Each iteration will have one hit and one miss. • This means we have 256 hits and 256 misses (50% miss rate).

  16. Problem 6.17 • What if our loop looked like this? for (i =0; i < 16; i++){ for (j = 0; j < 16; j++){ total_x += grid[i][j].x; total_y += grid[i][j].y; } }

  17. Problem 6.17 • What if our loop looked like this? for (i =0; i < 16; i++){ for (j = 0; j < 16; j++){ total_x += grid[i][j].x; total_y += grid[i][j].y; } } • Stride-one reference pattern. • We will read grid[0][0].x (cold miss), grid[0][0].y (hit), grid[0][1].x (hit), grid[0][1].y (hit). • The next two iterations will have the same number of hits/misses. • 25% of the 512 reads will be misses.

More Related