This project provides a model for simulating cache performance, including different cache configurations and replacement policies.
pip install cache-performance-modelCache is an abstract base class for different cache models. It provides common functionality and properties for cache simulation.
DirectMappedCache is a class for simulating a direct-mapped cache. It inherits from Cache and implements the read and write methods.
SetAssociativeCache is a class for simulating a set-associative cache. It inherits from Cache and implements the read and write methods. It supports different replacement policies such as RANDOM, FIFO, LRU, NMRU, and PLRU.
FullyAssociativeCache is a class for simulating a fully associative cache. It inherits from Cache and implements the read and write methods. It supports different replacement policies such as RANDOM, FIFO, LRU, NMRU, and PLRU.
from cache_performance_model.cache_model import DirectMappedCache
# Create a direct-mapped cache instance
cache = DirectMappedCache(cache_line_bytes=64, cache_size_kib=4)
# Perform read and write operations
cache.read(0x1A2B3C4D)
cache.write(0x1A2B3C4D)
# Print cache statistics
cache.stats()from cache_performance_model.cache_model import SetAssociativeCache
from cache_performance_model.types import ReplacementPolicy
# Create a set-associative cache instance with LRU replacement policy
cache = SetAssociativeCache(cache_line_bytes=64, cache_size_kib=4, n_way=4, replacement_policy=ReplacementPolicy.LRU)
# Perform read and write operations
cache.read(0x1A2B3C4D)
cache.write(0x1A2B3C4D)
# Print cache statistics
cache.stats()from cache_performance_model.cache_model import FullyAssociativeCache
from cache_performance_model.types import ReplacementPolicy
# Create a fully associative cache instance with RANDOM replacement policy
cache = FullyAssociativeCache(cache_line_bytes=64, cache_size_kib=4, replacement_policy=ReplacementPolicy.RANDOM)
# Perform read and write operations
cache.read(0x1A2B3C4D)
cache.write(0x1A2B3C4D)
# Print cache statistics
cache.stats()To install the required dependencies, run:
pip install -r requirements.txtTo build the documentation, run:
nox -s docsThe HTML pages will be in docs/_build/html.
gcc -o test utils/test.c
valgrind --tool=lackey --trace-mem=yes --log-file=results.txt ./test
python3 utils/run_tracer.py