A high-fidelity CPU cache simulator implementing a multi-level memory hierarchy with L1, Victim Cache, and L2 caches.
# Simulate a 1KB L1 cache with 64-byte blocks, 2-way associativity
./cachesim -c 10 -b 6 -s 1 < traces/gcc.traceSample Output:
Cache Settings
--------------
L1 (C,B,S): (10,6,1). Replace policy: MIP
Victim cache entries: 2
L2 (C,B,S): (15,6,3). Replace policy: LIP. Early Restart: Disabled
Cache Statistics
----------------
Reads: 1000000
Writes: 500000
L1 accesses: 1500000
L1 hits: 1350000
L1 misses: 150000
L1 hit ratio: 0.900
L1 miss ratio: 0.100
L1 average access time (AAT): 3.456
...
No demo GIF yet? Record your terminal with asciinema or create a screenshot of sample output and add it to a
screenshots/folder.
- Multi-Level Cache Hierarchy: L1 Cache → Victim Cache → L2 Cache → DRAM
- Configurable Parameters: Cache size (C), block size (B), associativity (S)
- 4 Replacement Policies:
- MIP (MRU Insertion Policy)
- LIP (LRU Insertion Policy)
- FIFO (First-In-First-Out)
- Random (PRNG-based eviction)
- Write Strategies:
- L1: Write-back, Write-allocate (WBWA)
- L2: Write-through, Write-no-allocate (WTWNA)
- Victim Cache: Fully-associative buffer for evicted L1 blocks
- Comprehensive Statistics: Hit/miss ratios, average access time (AAT)
- Early Restart Support: Optional L2 optimization
| Component | Technology |
|---|---|
| Language | C++ (C++11) |
| Build | GNU Make |
| Compiler | g++ / clang++ |
| Platform | Linux, macOS |
- C++ compiler with C++11 support (g++ 4.8+ or clang++ 3.3+)
- GNU Make
- Memory trace files (format:
R/W 0xADDRESS)
# Clone the repository
git clone git@github.com:Samiurr10/Cache-Simulator.git
cd Cache-Simulator
# Build the simulator
make
# (Optional) Build with debug symbols
make DEBUG=1
# (Optional) Build with AddressSanitizer
make SANITIZE=1./cachesim [OPTIONS] < trace_file| Option | Description | Default |
|---|---|---|
-c C |
L1 cache size: 2^C bytes | 10 (1KB) |
-b B |
Block size: 2^B bytes | 6 (64B) |
-s S |
L1 associativity: 2^S ways | 1 (2-way) |
-v V |
Victim cache entries (0, 1, or 2) | 2 |
-C C |
L2 cache size: 2^C bytes | 15 (32KB) |
-S S |
L2 associativity: 2^S ways | 3 (8-way) |
-P P |
L2 replacement policy (mip/lip/fifo/random) | LIP |
-D |
Disable L2 cache | - |
-E |
Enable Early Restart on L2 | - |
-h |
Show help message | - |
# Basic simulation with default settings
./cachesim < traces/gcc.trace
# Direct-mapped L1 cache (1-way)
./cachesim -s 0 < traces/mcf.trace
# 4KB L1, 4-way set associative, no victim cache
./cachesim -c 12 -s 2 -v 0 < traces/libquantum.trace
# Disable L2 cache (L1 + Victim only)
./cachesim -D < traces/lbm.trace
# Enable Early Restart optimization
./cachesim -E < traces/milc.traceEach line contains an access type and hexadecimal address:
R 0x7fff5fbff8c0
W 0x7fff5fbff8c8
R 0x7fff5fbff8d0
R= Read (load)W= Write (store)
Cache-Simulator/
├── cachesim.cpp # Core cache simulation logic
├── cachesim.hpp # Data structures and configuration
├── cachesim_driver.cpp # Main driver and CLI parsing
├── Makefile # Build configuration
├── run.sh # Execution wrapper script
├── README.md # This file
├── LICENSE # MIT License
└── traces/ # (Add your trace files here)
└── *.trace
┌─────────────────────────────────────────────────────────────┐
│ CPU Request │
└─────────────────────────┬───────────────────────────────────┘
▼
┌─────────────┐
│ L1 Cache │ Write-back, Write-allocate
│ (C,B,S) │ MIP Replacement
└──────┬──────┘
│ Miss
▼
┌────────────────┐
│ Victim Cache │ Fully Associative
│ (0-2 entries)│ LRU Replacement
└───────┬────────┘
│ Miss
▼
┌─────────────┐
│ L2 Cache │ Write-through, Write-no-allocate
│ (C,B,S) │ LIP Replacement
└──────┬──────┘
│ Miss
▼
┌─────────────┐
│ DRAM │ 64 cycles + 2 cycles/word
└─────────────┘
- Add support for additional replacement policies (PLRU, RRIP)
- Implement prefetching strategies
- Add cache coherence simulation for multi-core
- Create visualization tool for cache behavior
- Support for compressed trace formats
- Add benchmark suite with standard traces
Problem: error: 'uint64_t' was not declared
# Solution: Ensure C++11 is enabled
make CXXFLAGS="-std=c++11"Problem: Linker errors with math functions
# Solution: Math library should be linked automatically, but if not:
make LIBS="-lm"Problem: Segmentation fault on large traces
# Build with AddressSanitizer to debug
make clean && make SANITIZE=1
./cachesim < trace.traceProblem: Invalid configuration error
- Ensure
4 <= B <= 7(block size exponent) - Ensure
L1 size < L2 sizewhen L2 is enabled - Ensure
L1 associativity <= L2 associativity - Victim cache entries must be 0, 1, or 2
Problem: Simulation is slow
# Build with optimizations
make clean && make FAST=1- ECE 4100 - Advanced Computer Architecture, Georgia Tech
- Cache taxonomy based on the Conte Cache Taxonomy model