Skip to content

Commit a5d7c1e

Browse files
committed
Pybind refactor
1 parent e205c13 commit a5d7c1e

31 files changed

Lines changed: 2625 additions & 3318 deletions

.vscode/settings.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@
108108
"editor.formatOnSave": true,
109109
"editor.insertSpaces": true,
110110
"editor.detectIndentation": true,
111-
"editor.rulers": [80, 100],
111+
"editor.rulers": [
112+
80,
113+
100
114+
],
112115
"editor.wordWrap": "wordWrapColumn",
113116
"editor.wordWrapColumn": 100,
114117
"files.trimTrailingWhitespace": true,
@@ -133,5 +136,6 @@
133136
"**/*.code-search": true
134137
},
135138
"git.ignoreLimitWarning": true,
136-
"terminal.integrated.cwd": "${workspaceFolder}"
139+
"terminal.integrated.cwd": "${workspaceFolder}",
140+
"python.formatting.provider": "yapf"
137141
}

libCacheSim-python/CMakeLists.txt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,32 @@ else()
7676
message(FATAL_ERROR "Pre-built libCacheSim library not found. Please build the main project first: cd .. && cmake -G Ninja -B build && ninja -C build")
7777
endif()
7878

79-
python_add_library(_libcachesim MODULE
80-
src/pylibcachesim.cpp
79+
include_directories(src)
80+
81+
python_add_library(libcachesim_python MODULE
82+
src/export.cpp
83+
src/export_cache.cpp
84+
src/export_reader.cpp
85+
src/export_analyzer.cpp
86+
src/export_misc.cpp
87+
src/exception.cpp
8188
${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin/cli_reader_utils.c
89+
${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin/traceUtils/traceConvLCS.cpp
90+
${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin/traceUtils/traceConvOracleGeneral.cpp
91+
${MAIN_PROJECT_SOURCE_DIR}/libCacheSim/bin/traceUtils/utils.cpp
8292
WITH_SOABI
8393
)
8494

85-
set_target_properties(_libcachesim PROPERTIES
95+
set_target_properties(libcachesim_python PROPERTIES
8696
POSITION_INDEPENDENT_CODE ON
8797
INSTALL_RPATH_USE_LINK_PATH TRUE
8898
BUILD_WITH_INSTALL_RPATH TRUE
8999
INSTALL_RPATH "$ORIGIN"
90100
)
91101

92-
target_compile_definitions(_libcachesim PRIVATE VERSION_INFO=${PROJECT_VERSION})
102+
target_compile_definitions(libcachesim_python PRIVATE VERSION_INFO=${PROJECT_VERSION})
93103

94-
target_link_libraries(_libcachesim PRIVATE
104+
target_link_libraries(libcachesim_python PRIVATE
95105
${LIBCACHESIM_TARGET}
96106
pybind11::headers
97107
pybind11::module
@@ -102,8 +112,8 @@ target_link_libraries(_libcachesim PRIVATE
102112
# Add platform-specific link options and libraries
103113
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
104114
# GNU ld option, only available on Linux
105-
target_link_options(_libcachesim PRIVATE -Wl,--no-as-needed)
106-
target_link_libraries(_libcachesim PRIVATE dl)
115+
target_link_options(libcachesim_python PRIVATE -Wl,--no-as-needed)
116+
target_link_libraries(libcachesim_python PRIVATE dl)
107117
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
108118
# macOS doesn't need --no-as-needed
109119
# dl functions are part of the system library on macOS
@@ -112,21 +122,21 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
112122
# Find argp library on macOS
113123
find_library(ARGP_LIBRARY argp PATHS /opt/homebrew/lib /usr/local/lib)
114124
if(ARGP_LIBRARY)
115-
target_link_libraries(_libcachesim PRIVATE ${ARGP_LIBRARY})
125+
target_link_libraries(libcachesim_python PRIVATE ${ARGP_LIBRARY})
116126
endif()
117127

118128
# Find and link other dependencies that might be needed
119129
find_library(INTL_LIBRARY intl PATHS /opt/homebrew/lib /usr/local/lib)
120130
if(INTL_LIBRARY)
121-
target_link_libraries(_libcachesim PRIVATE ${INTL_LIBRARY})
131+
target_link_libraries(libcachesim_python PRIVATE ${INTL_LIBRARY})
122132
endif()
123133
else()
124134
# Other platforms - try to link dl if available
125135
find_library(DL_LIBRARY dl)
126136
if(DL_LIBRARY)
127-
target_link_libraries(_libcachesim PRIVATE ${DL_LIBRARY})
137+
target_link_libraries(libcachesim_python PRIVATE ${DL_LIBRARY})
128138
endif()
129139
endif()
130140

131141
# install to wheel directory
132-
install(TARGETS _libcachesim LIBRARY DESTINATION libcachesim)
142+
install(TARGETS libcachesim_python LIBRARY DESTINATION libcachesim)

libCacheSim-python/libcachesim/__init__.py

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,89 @@
22

33
from __future__ import annotations
44

5-
from ._libcachesim import (
5+
from .libcachesim_python import (
66
Cache,
7-
Reader,
8-
ReaderInitParam,
97
Request,
108
ReqOp,
119
TraceType,
10+
SamplerType,
1211
__doc__,
1312
__version__,
14-
open_trace,
15-
process_trace,
16-
process_trace_python_hook,
1713
)
18-
from .eviction import (
19-
ARC,
20-
Belady,
21-
BeladySize,
22-
Cacheus,
23-
Clock,
14+
15+
from .cache import (
16+
CacheBase,
17+
# Core algorithms
18+
LRU,
2419
FIFO,
25-
LeCaR,
2620
LFU,
27-
LFUDA,
28-
LRB,
29-
LRU,
30-
PythonHookCachePolicy,
31-
QDLP,
21+
ARC,
22+
Clock,
23+
Random,
24+
# Advanced algorithms
3225
S3FIFO,
3326
Sieve,
34-
SLRU,
35-
ThreeLCache,
36-
TinyLFU,
27+
LIRS,
3728
TwoQ,
29+
SLRU,
3830
WTinyLFU,
39-
)
40-
from .trace_generator import (
41-
create_zipf_requests,
42-
create_uniform_requests,
31+
LeCaR,
32+
LFUDA,
33+
ClockPro,
34+
Cacheus,
35+
# Optimal algorithms
36+
Belady,
37+
BeladySize,
38+
# Plugin cache
39+
PythonHookCachePolicy,
4340
)
4441

42+
from .trace_reader import TraceReader
43+
from .trace_analyzer import TraceAnalyzer
44+
from .synthetic_reader import SyntheticReader, create_zipf_requests, create_uniform_requests
45+
from .util import Util
46+
4547
__all__ = [
4648
# Core classes
4749
"Cache",
48-
"Reader",
4950
"Request",
50-
"ReaderInitParam",
51-
# Trace types and operations
52-
"TraceType",
5351
"ReqOp",
54-
# Cache policies
52+
"TraceType",
53+
"SamplerType",
54+
# Cache base class
55+
"CacheBase",
56+
# Core cache algorithms
5557
"LRU",
5658
"FIFO",
59+
"LFU",
5760
"ARC",
5861
"Clock",
59-
"LFU",
60-
"LFUDA",
61-
"SLRU",
62+
"Random",
63+
# Advanced cache algorithms
6264
"S3FIFO",
6365
"Sieve",
64-
"TinyLFU",
65-
"WTinyLFU",
66+
"LIRS",
6667
"TwoQ",
67-
"ThreeLCache",
68-
"Belady",
69-
"BeladySize",
70-
"LRB",
71-
"QDLP",
68+
"SLRU",
69+
"WTinyLFU",
7270
"LeCaR",
71+
"LFUDA",
72+
"ClockPro",
7373
"Cacheus",
74-
# Custom cache policy
74+
# Optimal algorithms
75+
"Belady",
76+
"BeladySize",
77+
# Plugin cache
7578
"PythonHookCachePolicy",
76-
# Functions
77-
"open_trace",
78-
"process_trace",
79-
"process_trace_python_hook",
79+
# Readers and analyzers
80+
"TraceReader",
81+
"TraceAnalyzer",
82+
"SyntheticReader",
83+
# Trace generators
8084
"create_zipf_requests",
8185
"create_uniform_requests",
86+
# Utilities
87+
"Util",
8288
# Metadata
8389
"__doc__",
8490
"__version__",

0 commit comments

Comments
 (0)