Some tips on Cachelab

| categories: programming | View Comments

Ok.. This lab is actually not that difficult. I just made some supid error in the c code which wasted me like 4 hours to find it out.

There are two parts in this lab. Part A asks you to finish a cache simulator, and part B requires you to write a program to transpose matrix with limited cache miss.

For part A, it should be quite easy since only hit count, miss count and eviction count are required. So just malloc some memory and then process each trace and update cache status after each trace. The results are there then.

For part B, it is a little tricky for the case 64 * 64 matrix. What I did is that use a 4 * 8 subset in matrix B as a buffer so it could always be hit when reading or writing these memories.

Assume blow is a submatrix S with size of 8 * 8. And we also vertically seperate the 4 * 8 buffer into to parts, B1 and B2.

|---+---|
| 1 | 2 |
|---+---|
| 3 | 4 |
|---+---|

So if we want to transpose SAn into SBm, the SBm would be like:

|----+----|
| 1' | 2' |
|----|----|
| 3' | 4' |
|----|----|

Then the buffer would be of great help for us.

Opperations are like:

  • 1 T-> buffer 1
  • 2 T-> buffer 2
  • 4 T-> 4'
  • buffer 2 -> 3'
  • 3 T-> buffer 2
  • buffer 1 -> 1'
  • buffer 2 -> 2'

Here T stands for transpose and '->' stands for move, all operations are based on a 4*4 submatrix base.

These operations designed in 4 * 4 should only causes 16 misses for the transpose of a 8 * 8 submatrix. There would be some submatrixs left, but they are easy to handle.

blog comments powered by Disqus