Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@
"editor.formatOnSave": true,
"editor.insertSpaces": true,
"editor.detectIndentation": true,
"editor.rulers": [80, 100],
"editor.rulers": [
80,
100
],
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 100,
"files.trimTrailingWhitespace": true,
Expand All @@ -133,5 +136,6 @@
"**/*.code-search": true
},
"git.ignoreLimitWarning": true,
"terminal.integrated.cwd": "${workspaceFolder}"
"terminal.integrated.cwd": "${workspaceFolder}",
"python.formatting.provider": "yapf"
}
32 changes: 21 additions & 11 deletions libCacheSim-python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,32 @@ else()
message(FATAL_ERROR "Pre-built libCacheSim library not found. Please build the main project first: cd .. && cmake -G Ninja -B build && ninja -C build")
endif()

python_add_library(_libcachesim MODULE
src/pylibcachesim.cpp
include_directories(src)

python_add_library(libcachesim_python MODULE
src/export.cpp
src/export_cache.cpp
src/export_reader.cpp
src/export_analyzer.cpp
src/export_misc.cpp
src/exception.cpp
${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin/cli_reader_utils.c
${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin/traceUtils/traceConvLCS.cpp
${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin/traceUtils/traceConvOracleGeneral.cpp
${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin/traceUtils/utils.cpp
WITH_SOABI
)

set_target_properties(_libcachesim PROPERTIES
set_target_properties(libcachesim_python PROPERTIES
POSITION_INDEPENDENT_CODE ON
INSTALL_RPATH_USE_LINK_PATH TRUE
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH "$ORIGIN"
)

target_compile_definitions(_libcachesim PRIVATE VERSION_INFO=${PROJECT_VERSION})
target_compile_definitions(libcachesim_python PRIVATE VERSION_INFO=${PROJECT_VERSION})

target_link_libraries(_libcachesim PRIVATE
target_link_libraries(libcachesim_python PRIVATE
${LIBCACHESIM_TARGET}
pybind11::headers
pybind11::module
Expand All @@ -102,8 +112,8 @@ target_link_libraries(_libcachesim PRIVATE
# Add platform-specific link options and libraries
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
# GNU ld option, only available on Linux
target_link_options(_libcachesim PRIVATE -Wl,--no-as-needed)
target_link_libraries(_libcachesim PRIVATE dl)
target_link_options(libcachesim_python PRIVATE -Wl,--no-as-needed)
target_link_libraries(libcachesim_python PRIVATE dl)
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# macOS doesn't need --no-as-needed
# dl functions are part of the system library on macOS
Expand All @@ -112,21 +122,21 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
# Find argp library on macOS
find_library(ARGP_LIBRARY argp PATHS /opt/homebrew/lib /usr/local/lib)
if(ARGP_LIBRARY)
target_link_libraries(_libcachesim PRIVATE ${ARGP_LIBRARY})
target_link_libraries(libcachesim_python PRIVATE ${ARGP_LIBRARY})
endif()

# Find and link other dependencies that might be needed
find_library(INTL_LIBRARY intl PATHS /opt/homebrew/lib /usr/local/lib)
if(INTL_LIBRARY)
target_link_libraries(_libcachesim PRIVATE ${INTL_LIBRARY})
target_link_libraries(libcachesim_python PRIVATE ${INTL_LIBRARY})
endif()
else()
# Other platforms - try to link dl if available
find_library(DL_LIBRARY dl)
if(DL_LIBRARY)
target_link_libraries(_libcachesim PRIVATE ${DL_LIBRARY})
target_link_libraries(libcachesim_python PRIVATE ${DL_LIBRARY})
endif()
endif()

# install to wheel directory
install(TARGETS _libcachesim LIBRARY DESTINATION libcachesim)
install(TARGETS libcachesim_python LIBRARY DESTINATION libcachesim)
103 changes: 58 additions & 45 deletions libCacheSim-python/libcachesim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,83 +2,96 @@

from __future__ import annotations

from ._libcachesim import (
from .libcachesim_python import (
Cache,
Reader,
ReaderInitParam,
Request,
ReqOp,
TraceType,
SamplerType,
AnalysisParam,
AnalysisOption,
__doc__,
__version__,
open_trace,
process_trace,
process_trace_python_hook,
)
from .eviction import (
ARC,
Belady,
BeladySize,
Cacheus,
Clock,

from .cache import (
CacheBase,
# Core algorithms
LRU,
FIFO,
LeCaR,
LFU,
LFUDA,
LRB,
LRU,
PythonHookCachePolicy,
QDLP,
ARC,
Clock,
Random,
# Advanced algorithms
S3FIFO,
Sieve,
SLRU,
ThreeLCache,
TinyLFU,
LIRS,
TwoQ,
SLRU,
WTinyLFU,
)
from .trace_generator import (
create_zipf_requests,
create_uniform_requests,
LeCaR,
LFUDA,
ClockPro,
Cacheus,
# Optimal algorithms
Belady,
BeladySize,
# Plugin cache
PythonHookCachePolicy,
)

from .trace_reader import TraceReader
from .trace_analyzer import TraceAnalyzer
from .synthetic_reader import SyntheticReader, create_zipf_requests, create_uniform_requests
from .util import Util
from .data_loader import DataLoader

__all__ = [
# Core classes
"Cache",
"Reader",
"Request",
"ReaderInitParam",
# Trace types and operations
"TraceType",
"ReqOp",
# Cache policies
"TraceType",
"SamplerType",
"AnalysisParam",
"AnalysisOption",
# Cache base class
"CacheBase",
# Core cache algorithms
"LRU",
"FIFO",
"LFU",
"ARC",
"Clock",
"LFU",
"LFUDA",
"SLRU",
"Random",
# Advanced cache algorithms
"S3FIFO",
"Sieve",
"TinyLFU",
"WTinyLFU",
"LIRS",
"TwoQ",
"ThreeLCache",
"Belady",
"BeladySize",
"LRB",
"QDLP",
"SLRU",
"WTinyLFU",
"LeCaR",
"LFUDA",
"ClockPro",
"Cacheus",
# Custom cache policy
# Optimal algorithms
"Belady",
"BeladySize",
# Plugin cache
"PythonHookCachePolicy",
# Functions
"open_trace",
"process_trace",
"process_trace_python_hook",
# Readers and analyzers
"TraceReader",
"TraceAnalyzer",
"SyntheticReader",
# Trace generators
"create_zipf_requests",
"create_uniform_requests",
# Utilities
"Util",
# Data loader
"DataLoader",
# Metadata
"__doc__",
"__version__",
Expand Down
Loading
Loading