Cache Simulation Project


Cache Simulator

For this project you will create a data cache simulator. The simulator you'll implement needs to work for N-way associative cache, which can be of arbitrary size (in power of 2, up to 64KB). Use the LRU (least recently used) scheme for choosing the way/block to replace in the set. A CS5200 attendant needs to execute it individually. Two CS4200 attendants should team up for doing the project. Your teammate could be randomly selected by the instructor. A CS4200 attendant can do the project individually (say if a teammate is not available), but there is no bonus if doing it individually. For your simulation, assume a memory hierarchy that is BYTE addressable. Your simulator needs to support the following 4 parameters:

-t input_trace_file
-s size
-a associativity
-b block_size

The cache size (-s) and block size (-b) are in bytes. The associativity is in the power of 2. The input trace file is here go_ld_trace (ZIP file). The file containd the trace of load instructions executed for some program. Each line represents a Byte address referenced by an executed load instruction. To help compress the traces, instead of storing the absolute memory byte address, we store the difference from the last address in the trace. An example of reading in the traces can be found in read_ld_trace.c. You need to use it or code up its equivalent to restore the trace file to the absolute memory addresses (instead of the difference). You should have the start of the trace you see as follows, and then use that trace for your cache simulator.

Here is the start of the trace file "go_ld_trace trace" you will be working with; once restored (make sure you see the same load addresses) is:

536869800
536869816
1073839984
1073867968
1074199644
1074170256
536869696
1073839832
1074229644
1074196644


The output of running your cache simulator should look like:

>cache-sim -t go_ld_trace -s 1024 -b 32 -a 2

program_name: go_ld_trace
cache_size: 1024
block_size: 32
associativity: 2
total_lds: 1500000
cache_hits: 1005939
cache_misses: 494061
cache_miss_rate:0.33

The maximum values your simulator needs to suport for each of the parameters (s,b,a) is 64K bytes for the cache size, 256 bytes for the block size, and the full associativity.


What to turn in

For this project, GUI is not necessary. You should use C/C++, but using Java or c# is also fine. You will email me (and cc to yourself) the source code file of your simulator and a project report file with three required graphs (in MS Word) in ONE ZIP file before the due time. Your simulator will be examined in Lab 149 machines in the class time of the project due day; please have a hardcopy of the project report ready. In the project report file, you should also specify the workload distribution and credit/grade distribution between you and your teammate (if CS 420 attendants), say 50:50 (if default), 60:40, or others. Before turning the project in you need to make sure that your program compiles and runs on the machines in the Lab 149. I recommend that you consider to have the direct mapped cache working first. If any question, please talk to me.

Please do not copy any code from others. It is against academic integrity! If confirmed, you will lose all project value, and other pentalty may be applied.

Three graphs, say by Excel, are required together with the data analysis and evaluation in your project report file:

For the first one, a line will be drawn; the Y-axis for the graph will be the miss rate, and the X-axis for the graphs will be the size of the cache (given the fixed block size 32; fixed associativity 4). For results, you will need to run your cache simulator for "go" for cache sizes of 1KB, 2KB, 4KB, 8KB, 16 KB, 32KB, and 64KB of data.

For the second one, a line will be drawn; the Y-axis for the graph will be the miss rate, and the X-axis for the graphs will be the size of the block (given the fixed cache size 8192; fixed associativity 4). For results, you will need to run your cache simulator for "go" for block sizes of 1, 2, 4, 8, 16, 32, and 64.

For the third one, a line will be drawn; the Y-axis for the graph will be the miss rate, and the X-axis for the graphs will be the associativity (given the fixed cache size 8192; fixed block size 32). For results, you will need to run your cache simulator for "go" for associativity of 1, 2, 4, 8, 16, 32, and the fully associative.

Your simulator will be examined by using different parameters. The correct funcationality is the first and the primary metric. But the coding convention and execution speed are metrics too.


Below are sample results for the program go:

cache-sim -t go_ld_trace -s 1024 -b 32 -a 4
program_name: go_ld_trace
cache_size: 1024
block_size: 32
associativity: 4
total_lds: 1500000
cache_hits: 1036092
cache_misses: 463908
cache_miss_rate: 0.31

cache-sim -t go_ld_trace -s 2048 -b 32 -a 4
program_name: go_ld_trace
cache_size: 2048
block_size: 32
associativity: 4
total_lds: 1500000
cache_hits: 1212014
cache_misses: 287986
cache_miss_rate: 0.192

cache-sim -t go_ld_trace -s 2048 -b 32 -a 64
program_name: go_ld_trace
cache_size: 2048
block_size: 32
associativity: 64
total_lds: 1500000
cache_hits: 1232218
cache_misses: 267782
cache_miss_rate: 0.18

cache-sim -t go_ld_trace -s 8192 -b 32 -a 256
program_name: go_ld_trace
cache_size: 8192
block_size: 32
associativity: 256 (fully associative)
total_lds: 1500000
cache_hits: 1476159
cache_misses: 23841
cache_miss_rate: 0.0159

cache-sim -t go_ld_trace -s 4096 -b 32 -a 1
program_name: go_ld_trace
cache_size: 4096
block_size: 32
associativity: 1 (Direct Mapped Cache)
total_lds: 1500000
cache_hits: 1252626
cache_misses: 247374
cache_miss_rate: 0.1649