Skip to content

Commit d722083

Browse files
Implement enhanced prefetching and MESI protocol
1 parent 16324dd commit d722083

34 files changed

+7614
-43845
lines changed

.gitignore

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
# Prerequisites
2-
*.d
3-
*.vscode
1+
# Build directories
2+
build/
3+
bin/
4+
lib/
5+
out/
6+
cmake-build-*/
47

58
# Compiled Object files
6-
*.slo
7-
*.lo
89
*.o
910
*.obj
11+
*.slo
12+
*.lo
1013

1114
# Precompiled Headers
1215
*.gch
@@ -17,20 +20,69 @@
1720
*.dylib
1821
*.dll
1922

20-
# Fortran module files
21-
*.mod
22-
*.smod
23-
2423
# Compiled Static libraries
25-
*.lai
26-
*.la
2724
*.a
2825
*.lib
2926

3027
# Executables
3128
*.exe
3229
*.out
3330
*.app
31+
cachesim
32+
33+
# Generated documentation
34+
docs/generated/
35+
docs/html/
36+
docs/xml/
37+
docs/latex/
38+
39+
# CMake generated files
40+
CMakeCache.txt
41+
CMakeFiles/
42+
CMakeScripts/
43+
cmake_install.cmake
44+
install_manifest.txt
45+
CTestTestfile.cmake
46+
compile_commands.json
47+
_deps/
48+
49+
# IDE specific files
50+
.idea/
51+
.vscode/
52+
.vs/
53+
*.swp
54+
*.swo
55+
*~
56+
.DS_Store
57+
*.code-workspace
58+
59+
# Temporary files
60+
temp/
61+
tmp/
62+
*.log
63+
*.tmp
64+
65+
# Simulation results
66+
results/
67+
*.csv
68+
*.json
69+
70+
# Generated traces
71+
traces/generated/
72+
73+
# Dependency files
74+
*.d
75+
76+
# User-specific config
77+
config.local.json
78+
79+
# Backup files
80+
*.bak
81+
*.backup
82+
*~
83+
*.orig
3484

35-
# Cachesim-specific files
36-
cachesim
85+
# Core dumps
86+
core
87+
core.*
88+
.cache/

CHANGELOG.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Changelog
2+
3+
All notable changes to the Cache Simulator project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.0] - 2025-03-12
9+
10+
### Overview
11+
*First stable release with full C++17 support*
12+
13+
This release marks the first stable version of the Cache Simulator, featuring a comprehensive simulation framework for cache and memory hierarchy systems. The simulator provides flexible configuration options, detailed statistics tracking, and advanced features such as adaptive prefetching and cache coherence.
14+
15+
### Added
16+
- Initial release of the Cache Simulator with enhanced features
17+
- Comprehensive CMake build system with C++17 support
18+
- Modern project structure with separate source, test, and utility directories
19+
- Configurable multi-level cache hierarchy
20+
- Detailed statistics collection and reporting
21+
- Parallel build support via CMake and Make
22+
- Documentation system with markdown guides and examples
23+
24+
### Core Functionality
25+
- `StreamBuffer` class for sequential prefetching implementation
26+
- `StridePredictor` class for stride-based prefetching with confidence tracking
27+
- `AdaptivePrefetcher` class providing a dynamic prefetching system that adjusts strategy based on workload
28+
- `MESIProtocol` class implementing the MESI cache coherence protocol
29+
- `Cache` class with support for various configurations and replacement policies
30+
- `MemoryHierarchy` class orchestrating the entire cache hierarchy
31+
- `TraceParser` utility for processing memory access traces
32+
- LRU replacement policy implementation
33+
34+
### Developer Tools
35+
- Unit testing framework for validating cache behavior
36+
- Memory profiler for analyzing access patterns
37+
- Trace parser utility for handling different memory trace formats
38+
- Trace generator tool for creating test traces with various patterns
39+
- Benchmarking utilities for performance comparison
40+
- Visualization tools for statistics and cache behavior
41+
- Git structure with proper .gitignore and organization
42+
- Bash scripts for automation and batch simulation
43+
44+
### Documentation
45+
- Detailed README with project overview, directory structure, and usage instructions
46+
- Design documentation explaining architecture and algorithms
47+
- Examples documentation with usage scenarios and case studies
48+
- Code documentation with comprehensive comments
49+
- CONTRIBUTING guide for new developers
50+
- TODO list for future development
51+
52+
### Testing
53+
- Unit tests for core components:
54+
- Cache hit/miss behavior
55+
- LRU replacement policy
56+
- Write-back functionality
57+
- Prefetching effectiveness
58+
- MESI protocol state transitions
59+
- Validation tests with known trace patterns
60+
- Performance benchmarks for different configurations
61+
62+
### Fixed
63+
- Constructor initialization order in Cache class
64+
- Memory hierarchy trace processing compatibility with modern interfaces
65+
- Nodiscard attribute handling for method return values
66+
- String_view temporary object lifetime issues
67+
68+
### Future Development
69+
- Identified TODOs for future enhancements (see TODO.md for details):
70+
- Multi-processor simulation
71+
- Additional replacement policies
72+
- Victim cache implementation
73+
- Performance optimizations
74+
- Visualization tools and GUI
75+
- Power and area modeling
76+
77+
[1.0.0]: https://github.com/muditbhargava66/cache-simulator/releases/tag/v1.0.0

CMakeLists.txt

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(CacheSimulator VERSION 1.0.0 LANGUAGES CXX)
3+
4+
# Set C++17 as the required standard
5+
set(CMAKE_CXX_STANDARD 17)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
set(CMAKE_CXX_EXTENSIONS OFF)
8+
9+
# Set default build type if not specified
10+
if(NOT CMAKE_BUILD_TYPE)
11+
set(CMAKE_BUILD_TYPE Release)
12+
endif()
13+
14+
# Output directories
15+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
16+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
17+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
18+
19+
# Generate compile_commands.json for code completion engines
20+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
21+
22+
# Common compiler flags
23+
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
24+
add_compile_options(-Wall -Wextra -Wpedantic -Werror=return-type)
25+
26+
# Add debug flags
27+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -O0")
28+
29+
# Add release flags
30+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
31+
elseif(MSVC)
32+
add_compile_options(/W4 /permissive- /Zc:__cplusplus)
33+
34+
# Enable exceptions
35+
add_compile_options(/EHsc)
36+
endif()
37+
38+
# Include directories
39+
include_directories(
40+
${PROJECT_SOURCE_DIR}/src
41+
${PROJECT_SOURCE_DIR}/src/core
42+
${PROJECT_SOURCE_DIR}/src/utils
43+
)
44+
45+
# Define source files
46+
file(GLOB_RECURSE CORE_SOURCES "src/core/*.cpp")
47+
file(GLOB_RECURSE UTILS_SOURCES "src/utils/*.cpp")
48+
file(GLOB MAIN_SOURCES "src/main.cpp")
49+
50+
# Define header files
51+
file(GLOB_RECURSE CORE_HEADERS "src/core/*.h")
52+
file(GLOB_RECURSE UTILS_HEADERS "src/utils/*.h")
53+
54+
# Create a list of all sources
55+
set(ALL_SOURCES ${CORE_SOURCES} ${UTILS_SOURCES} ${MAIN_SOURCES})
56+
set(ALL_HEADERS ${CORE_HEADERS} ${UTILS_HEADERS})
57+
58+
# Define library for tests to link against
59+
add_library(cachesim_lib STATIC ${CORE_SOURCES} ${UTILS_SOURCES})
60+
61+
# Define main executable
62+
add_executable(cachesim ${MAIN_SOURCES})
63+
target_link_libraries(cachesim cachesim_lib)
64+
65+
# Create trace generator tool
66+
file(GLOB TOOLS_SOURCES "tools/*.cpp")
67+
foreach(TOOL_SOURCE ${TOOLS_SOURCES})
68+
get_filename_component(TOOL_NAME ${TOOL_SOURCE} NAME_WE)
69+
add_executable(${TOOL_NAME} ${TOOL_SOURCE})
70+
target_link_libraries(${TOOL_NAME} cachesim_lib)
71+
set_target_properties(${TOOL_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tools)
72+
endforeach()
73+
74+
# Enable testing
75+
enable_testing()
76+
77+
# Add unit tests
78+
file(GLOB_RECURSE UNIT_TEST_SOURCES "tests/unit/*.cpp")
79+
foreach(TEST_SOURCE ${UNIT_TEST_SOURCES})
80+
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
81+
add_executable(${TEST_NAME} ${TEST_SOURCE})
82+
target_link_libraries(${TEST_NAME} cachesim_lib)
83+
set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/unit)
84+
add_test(NAME ${TEST_NAME} COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/unit/${TEST_NAME})
85+
endforeach()
86+
87+
# Add validation tests
88+
file(GLOB_RECURSE VALIDATION_TEST_SOURCES "tests/validation/*.cpp")
89+
foreach(TEST_SOURCE ${VALIDATION_TEST_SOURCES})
90+
get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE)
91+
add_executable(${TEST_NAME} ${TEST_SOURCE})
92+
target_link_libraries(${TEST_NAME} cachesim_lib)
93+
set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/validation)
94+
add_test(NAME ${TEST_NAME} COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/tests/validation/${TEST_NAME})
95+
endforeach()
96+
97+
# Install targets
98+
install(TARGETS cachesim
99+
RUNTIME DESTINATION bin
100+
)
101+
102+
# Install trace files
103+
install(DIRECTORY traces/
104+
DESTINATION share/cachesim/traces
105+
)
106+
107+
# Install scripts
108+
install(DIRECTORY scripts/
109+
DESTINATION share/cachesim/scripts
110+
USE_SOURCE_PERMISSIONS
111+
)
112+
113+
# Documentation target if Doxygen is available
114+
find_package(Doxygen)
115+
if(DOXYGEN_FOUND)
116+
set(DOXYGEN_INPUT_DIR ${PROJECT_SOURCE_DIR}/src)
117+
set(DOXYGEN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/docs)
118+
set(DOXYGEN_INDEX_FILE ${DOXYGEN_OUTPUT_DIR}/html/index.html)
119+
set(DOXYGEN_CONFIG_FILE ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
120+
121+
configure_file(${PROJECT_SOURCE_DIR}/docs/Doxyfile.in ${DOXYGEN_CONFIG_FILE} @ONLY)
122+
123+
add_custom_command(OUTPUT ${DOXYGEN_INDEX_FILE}
124+
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_CONFIG_FILE}
125+
MAIN_DEPENDENCY ${DOXYGEN_CONFIG_FILE} ${ALL_HEADERS}
126+
COMMENT "Generating API documentation with Doxygen"
127+
VERBATIM
128+
)
129+
130+
add_custom_target(doc DEPENDS ${DOXYGEN_INDEX_FILE})
131+
endif()
132+
133+
# Package configuration
134+
set(CPACK_PACKAGE_NAME "cachesim")
135+
set(CPACK_PACKAGE_VENDOR "Your Organization")
136+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Cache and Memory Hierarchy Simulator")
137+
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
138+
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
139+
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
140+
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
141+
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CacheSimulator ${PROJECT_VERSION}")
142+
include(CPack)
143+
144+
# Print configuration summary
145+
message(STATUS "")
146+
message(STATUS "Cache Simulator Build Configuration:")
147+
message(STATUS " Version: ${PROJECT_VERSION}")
148+
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
149+
message(STATUS " C++ Compiler: ${CMAKE_CXX_COMPILER}")
150+
message(STATUS " C++ Standard: C++${CMAKE_CXX_STANDARD}")
151+
message(STATUS " Installation path: ${CMAKE_INSTALL_PREFIX}")
152+
message(STATUS "")

0 commit comments

Comments
 (0)