Skip to content

Commit 0ab5446

Browse files
committed
Use scikit build
1 parent 9406e05 commit 0ab5446

23 files changed

Lines changed: 1835 additions & 5 deletions

.github/workflows/python.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Python
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- name: Set up Python
12+
uses: actions/setup-python@v4
13+
with:
14+
python-version: "3.10"
15+
16+
- name: Prepare
17+
run: bash scripts/install_dependency.sh
18+
19+
- name: Build main libCacheSim project
20+
run: |
21+
cmake -G Ninja -B build
22+
ninja -C build
23+
24+
- name: Install Python dependencies
25+
run: |
26+
pip install --upgrade pip
27+
pip install -r requirements.txt
28+
pip install pytest
29+
30+
- name: Build libCacheSim-python
31+
run: |
32+
cd libCacheSim-python
33+
pip install -e .
34+
35+
- name: Run tests
36+
run: |
37+
cd libCacheSim-python
38+
pytest tests/

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ else()
247247
message(STATUS "Building without test")
248248
endif()
249249

250+
# Export variables for scikit-build -> build/export_vars.cmake
251+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libCacheSim-python/export)
250252

251253
# libCacheSim unified library compilation and installation
252254
# Create a single library that combines all modular libraries

grep

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
-- The C compiler identification is GNU 11.4.0
2+
-- The CXX compiler identification is GNU 11.4.0
3+
-- Detecting C compiler ABI info
4+
-- Detecting C compiler ABI info - done
5+
-- Check for working C compiler: /usr/bin/cc - skipped
6+
-- Detecting C compile features
7+
-- Detecting C compile features - done
8+
-- Detecting CXX compiler ABI info
9+
-- Detecting CXX compiler ABI info - done
10+
-- Check for working CXX compiler: /usr/bin/c++ - skipped
11+
-- Detecting CXX compile features
12+
-- Detecting CXX compile features - done
13+
-- Version from /users/Haocheng/mylcs/version.txt: 0.3.1
14+
-- LOG_LEVEL is not set, use INFO as default for release build
15+
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
16+
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
17+
-- Found Threads: TRUE
18+
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2")
19+
-- Checking for one of the modules 'glib-2.0'
20+
-- Found GLib: /usr/lib/x86_64-linux-gnu/libglib-2.0.so (found version "2.72.4")
21+
-- Looking for argp_parse
22+
-- Looking for argp_parse - found
23+
-- Found argp: /usr/include
24+
-- Found ZSTD: /usr/local/lib/libzstd.so
25+
-- Found Zstd: /usr/local/lib/libzstd.so
26+
-- ZSTD_INCLUDE_DIR /usr/local/include, ZSTD_LIBRARIES /usr/local/lib/libzstd.so
27+
-- CMAKE_CXX_FLAGS_DEBUG -g
28+
-- CMAKE_CXX_FLAGS_RELWITHDEBINFO -O2 -g -DNDEBUG
29+
-- CMAKE_CXX_FLAGS_RELEASE -O3 -DNDEBUG
30+
-- SUPPORT TTL OFF, USE_HUGEPAGE ON
31+
-- LOGLEVEL default, ENABLE_GLCACHE OFF
32+
-- ENABLE_LRB OFF, ENABLE_3L_CACHE OFF
33+
-- OPT_SUPPORT_ZSTD_TRACE ON
34+
-- <<++=====------------------\/------------------=====++>>
35+
-- <<++ libCacheSim summary ++>>
36+
-- <<++=====------------------/\------------------=====++>>
37+
-- ================== dependency related ==================
38+
-- glib found? TRUE - LIBS=/usr/lib/x86_64-linux-gnu/libglib-2.0.so, header=/usr/include/glib-2.0;/usr/lib/x86_64-linux-gnu/glib-2.0/include
39+
-- tcmalloc found? TRUE - LIBS=/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so, header=
40+
-- ZSTD found? TRUE - LIBS=/usr/local/lib/libzstd.so, header=/usr/local/include
41+
-- ==================== CMake related =====================
42+
-- platform = Linux 5.15.0-138-generic
43+
-- CPU type = x86_64
44+
-- cmake source = /users/Haocheng/mylcs
45+
-- cmake compiler = /usr/bin/cc
46+
-- CMAKE_BUILD_TYPE = Release
47+
-- CFLAGS =
48+
-- dependency_libs = /usr/lib/x86_64-linux-gnu/libglib-2.0.so;/usr/local/lib/libzstd.so;/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so
49+
-- Installation path = /usr/local
50+
-- ========================================================
51+
-- ============= Status of optional features ==============
52+
-- ========================================================
53+
-- cache_sources_c = admission/bloomfilter.c;admission/prob.c;admission/size.c;admission/sizeProbabilistic.c;eviction/ARC.c;eviction/ARCv0.c;eviction/Belady.c;eviction/BeladySize.c;eviction/CAR.c;eviction/Cacheus.c;eviction/Clock.c;eviction/ClockPro.c;eviction/FIFO.c;eviction/Hyperbolic.c;eviction/LeCaR.c;eviction/LeCaRv0.c;eviction/LFU.c;eviction/LFUDA.c;eviction/LIRS.c;eviction/LRU.c;eviction/LRUProb.c;eviction/LRUv0.c;eviction/MRU.c;eviction/nop.c;eviction/QDLP.c;eviction/Random.c;eviction/RandomLRU.c;eviction/RandomTwo.c;eviction/S3FIFO.c;eviction/Sieve.c;eviction/Size.c;eviction/SLRU.c;eviction/SLRUv0.c;eviction/TwoQ.c;eviction/WTinyLFU.c;eviction/CR_LFU.c;eviction/SR_LRU.c;eviction/FIFO_Merge.c;eviction/FIFO_Reinsertion.c;eviction/S3FIFOv0.c;eviction/S3FIFOd.c;eviction/other/flashProb.c;eviction/other/S3LRU.c;prefetch/Mithril.c;prefetch/OBL.c;prefetch/PG.c;cache.c;plugin.c
54+
-- cache_sources_cpp = admission/adaptsize/adaptsize.cpp;admission/adaptsize/adaptsize_interface.cpp;eviction/cpp/LFU.cpp;eviction/cpp/GDSF.cpp;eviction/LHD/lhd.cpp;eviction/LHD/LHD_Interface.cpp
55+
-- Building with test
56+
-- Exported variables to /users/Haocheng/mylcs/build/export_vars.cmake
57+
-- Configuring done (0.8s)
58+
-- Generating done (0.1s)
59+
-- Build files have been written to: /users/Haocheng/mylcs/build
60+
~/mylcs/libCacheSim-python ~/mylcs
61+
Using pip 22.0.2 from /usr/lib/python3/dist-packages/pip (python 3.10)
62+
Defaulting to user installation because normal site-packages is not writeable
63+
Created temporary directory: /tmp/pip-ephem-wheel-cache-b2vd6qte
64+
Created temporary directory: /tmp/pip-req-tracker-g5ne9qc8
65+
Initialized build tracking at /tmp/pip-req-tracker-g5ne9qc8
66+
Created build tracker: /tmp/pip-req-tracker-g5ne9qc8
67+
Entered build tracker: /tmp/pip-req-tracker-g5ne9qc8
68+
Created temporary directory: /tmp/pip-install-m8gstwzc
69+
Obtaining file:///users/Haocheng/mylcs/libCacheSim-python
70+
Added file:///users/Haocheng/mylcs/libCacheSim-python to build tracker '/tmp/pip-req-tracker-g5ne9qc8'
71+
Created temporary directory: /tmp/pip-build-env-55hvaxmg
72+
Created temporary directory: /tmp/pip-standalone-pip-2s9ixk7n
73+
Installing build dependencies: started
74+
Installing build dependencies: finished with status 'canceled'
75+
Exception information:
76+
Traceback (most recent call last):
77+
File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 165, in exc_logging_wrapper
78+
status = run_func(*args)
79+
File "/usr/lib/python3/dist-packages/pip/_internal/cli/req_command.py", line 205, in wrapper
80+
return func(self, options, args)
81+
File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 339, in run
82+
requirement_set = resolver.resolve(
83+
File "/usr/lib/python3/dist-packages/pip/_internal/resolution/resolvelib/resolver.py", line 75, in resolve
84+
collected = self.factory.collect_root_requirements(root_reqs)
85+
File "/usr/lib/python3/dist-packages/pip/_internal/resolution/resolvelib/factory.py", line 506, in collect_root_requirements
86+
req = self._make_requirement_from_install_req(
87+
File "/usr/lib/python3/dist-packages/pip/_internal/resolution/resolvelib/factory.py", line 468, in _make_requirement_from_install_req
88+
cand = self._make_candidate_from_link(
89+
File "/usr/lib/python3/dist-packages/pip/_internal/resolution/resolvelib/factory.py", line 188, in _make_candidate_from_link
90+
self._editable_candidate_cache[link] = EditableCandidate(
91+
File "/usr/lib/python3/dist-packages/pip/_internal/resolution/resolvelib/candidates.py", line 313, in __init__
92+
super().__init__(
93+
File "/usr/lib/python3/dist-packages/pip/_internal/resolution/resolvelib/candidates.py", line 158, in __init__
94+
self.dist = self._prepare()
95+
File "/usr/lib/python3/dist-packages/pip/_internal/resolution/resolvelib/candidates.py", line 227, in _prepare
96+
dist = self._prepare_distribution()
97+
File "/usr/lib/python3/dist-packages/pip/_internal/resolution/resolvelib/candidates.py", line 323, in _prepare_distribution
98+
return self._factory.preparer.prepare_editable_requirement(self._ireq)
99+
File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 609, in prepare_editable_requirement
100+
dist = _get_prepared_distribution(
101+
File "/usr/lib/python3/dist-packages/pip/_internal/operations/prepare.py", line 58, in _get_prepared_distribution
102+
abstract_dist.prepare_distribution_metadata(finder, build_isolation)
103+
File "/usr/lib/python3/dist-packages/pip/_internal/distributions/sdist.py", line 35, in prepare_distribution_metadata
104+
self._prepare_build_backend(finder)
105+
File "/usr/lib/python3/dist-packages/pip/_internal/distributions/sdist.py", line 56, in _prepare_build_backend
106+
self.req.build_env.install_requirements(
107+
File "/usr/lib/python3/dist-packages/pip/_internal/build_env.py", line 202, in install_requirements
108+
self._install_requirements(
109+
File "/usr/lib/python3/dist-packages/pip/_internal/build_env.py", line 260, in _install_requirements
110+
call_subprocess(
111+
File "/usr/lib/python3/dist-packages/pip/_internal/utils/subprocess.py", line 166, in call_subprocess
112+
line: str = proc.stdout.readline()
113+
KeyboardInterrupt
114+
Removed file:///users/Haocheng/mylcs/libCacheSim-python from build tracker '/tmp/pip-req-tracker-g5ne9qc8'
115+
Removed build tracker: '/tmp/pip-req-tracker-g5ne9qc8'
116+
~/mylcs

libCacheSim-python/.gitignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Automatically generated by `hgimportsvn`
2+
.svn
3+
.hgsvn
4+
5+
# Ignore local virtualenvs
6+
lib/
7+
bin/
8+
include/
9+
.Python/
10+
11+
# These lines are suggested according to the svn:ignore property
12+
# Feel free to enable them by uncommenting them
13+
*.pyc
14+
*.pyo
15+
*.swp
16+
*.class
17+
*.orig
18+
*~
19+
.hypothesis/
20+
21+
# autogenerated
22+
src/_pytest/_version.py
23+
# setuptools
24+
.eggs/
25+
26+
doc/*/_build
27+
doc/*/.doctrees
28+
build/
29+
dist/
30+
*.egg-info
31+
htmlcov/
32+
issue/
33+
env/
34+
.env/
35+
.venv/
36+
/pythonenv*/
37+
3rdparty/
38+
.tox
39+
.cache
40+
.pytest_cache
41+
.mypy_cache
42+
.coverage
43+
.coverage.*
44+
coverage.xml
45+
.ropeproject
46+
.idea
47+
.hypothesis
48+
.pydevproject
49+
.project
50+
.settings
51+
.vscode
52+
__pycache__/
53+
.python-version
54+
55+
# generated by pip
56+
pip-wheel-metadata/
57+
58+
# pytest debug logs generated via --debug
59+
pytestdebug.log

libCacheSim-python/CMakeLists.txt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
cmake_minimum_required(VERSION 3.15...3.27)
2+
3+
# Include exported variables from cache
4+
set(PARENT_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../build")
5+
set(EXPORT_FILE "${PARENT_BUILD_DIR}/export_vars.cmake")
6+
7+
if(EXISTS "${EXPORT_FILE}")
8+
include("${EXPORT_FILE}")
9+
message(STATUS "Loaded variables from export_vars.cmake")
10+
else()
11+
message(FATAL_ERROR "export_vars.cmake not found at ${EXPORT_FILE}. Please build the main project first (e.g. cd .. && cmake -G Ninja -B build)")
12+
endif()
13+
14+
# Force enable -fPIC
15+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
16+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
17+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
18+
19+
project(libCacheSim-python VERSION "${LIBCACHESIM_VERSION}")
20+
21+
if(LOG_LEVEL_LOWER STREQUAL "default")
22+
if(CMAKE_BUILD_TYPE_LOWER MATCHES "debug")
23+
add_compile_definitions(LOGLEVEL=6)
24+
else()
25+
add_compile_definitions(LOGLEVEL=7)
26+
endif()
27+
elseif(LOG_LEVEL_LOWER STREQUAL "verbose")
28+
add_compile_definitions(LOGLEVEL=5)
29+
elseif(LOG_LEVEL_LOWER STREQUAL "debug")
30+
add_compile_definitions(LOGLEVEL=6)
31+
elseif(LOG_LEVEL_LOWER STREQUAL "info")
32+
add_compile_definitions(LOGLEVEL=7)
33+
elseif(LOG_LEVEL_LOWER STREQUAL "warn")
34+
add_compile_definitions(LOGLEVEL=8)
35+
elseif(LOG_LEVEL_LOWER STREQUAL "error")
36+
add_compile_definitions(LOGLEVEL=9)
37+
else()
38+
add_compile_definitions(LOGLEVEL=7)
39+
endif()
40+
41+
# Find python and pybind11
42+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
43+
find_package(pybind11 CONFIG REQUIRED)
44+
45+
# Include directories for dependencies
46+
include_directories(${GLib_INCLUDE_DIRS})
47+
include_directories(${GLib_CONFIG_INCLUDE_DIR})
48+
include_directories(${XGBOOST_INCLUDE_DIR})
49+
include_directories(${LIGHTGBM_PATH})
50+
include_directories(${ZSTD_INCLUDE_DIR})
51+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libCacheSim/bin)
52+
53+
# Find the main libCacheSim library
54+
set(MAIN_PROJECT_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../build")
55+
set(MAIN_PROJECT_LIB_PATH "${MAIN_PROJECT_BUILD_DIR}/liblibCacheSim.a")
56+
57+
if(EXISTS "${MAIN_PROJECT_LIB_PATH}")
58+
message(STATUS "Found pre-built libCacheSim library at ${MAIN_PROJECT_LIB_PATH}")
59+
60+
# Import the main library as an imported target
61+
add_library(libCacheSim_main STATIC IMPORTED)
62+
set_target_properties(libCacheSim_main PROPERTIES
63+
IMPORTED_LOCATION "${MAIN_PROJECT_LIB_PATH}"
64+
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/../libCacheSim/include;${CMAKE_CURRENT_SOURCE_DIR}/../libCacheSim/utils/include;${CMAKE_CURRENT_SOURCE_DIR}/../libCacheSim"
65+
)
66+
67+
# Link dependencies that the main library needs
68+
target_link_libraries(libCacheSim_main INTERFACE ${dependency_libs})
69+
set(LIBCACHESIM_TARGET libCacheSim_main)
70+
71+
else()
72+
message(FATAL_ERROR "Pre-built libCacheSim library not found. Please build the main project first: cd .. && cmake -G Ninja -B build && ninja -C build")
73+
endif()
74+
75+
python_add_library(_libcachesim MODULE
76+
src/pylibcachesim.cpp
77+
${CMAKE_CURRENT_SOURCE_DIR}/../libCacheSim/bin/cli_reader_utils.c
78+
WITH_SOABI
79+
)
80+
81+
set_target_properties(_libcachesim PROPERTIES
82+
POSITION_INDEPENDENT_CODE ON
83+
INSTALL_RPATH_USE_LINK_PATH TRUE
84+
BUILD_WITH_INSTALL_RPATH TRUE
85+
INSTALL_RPATH "$ORIGIN"
86+
)
87+
88+
target_compile_definitions(_libcachesim PRIVATE VERSION_INFO=${PROJECT_VERSION})
89+
90+
target_link_libraries(_libcachesim PRIVATE
91+
${LIBCACHESIM_TARGET}
92+
pybind11::headers
93+
pybind11::module
94+
-Wl,--no-as-needed -ldl
95+
)
96+
97+
# install to wheel directory
98+
install(TARGETS _libcachesim LIBRARY DESTINATION libcachesim)

libCacheSim-python/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# libCacheSim Python Binding
2+
3+
Python bindings for libCacheSim, a high-performance cache simulator.
4+
5+
## Installation
6+
7+
```bash
8+
pip install .
9+
```
10+
11+
## Development
12+
13+
```bash
14+
pip install -e .
15+
```
16+
17+
Test
18+
19+
```
20+
python -m pytest .
21+
```
22+
23+
## Usage
24+
25+
```python
26+
import libcachesim as cachesim
27+
28+
# Create a cache with FIFO eviction policy
29+
cache = cachesim.FIFO(cache_size=1024*1024)
30+
31+
# Create a request
32+
req = cachesim.Request()
33+
req.obj_id = 1
34+
req.obj_size = 100
35+
36+
# Check if object is in cache
37+
hit = cache.get(req)
38+
print(f"Cache hit: {hit}")
39+
```
40+
41+
## Features
42+
43+
- [x] Support for multiple eviction policies (FIFO, LRU, ARC, Clock, etc.)
44+
- [ ] trace analysis tools
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Helper functions are removed since we don't export source files anymore
2+
3+
set(EXPORT_FILE "${CMAKE_BINARY_DIR}/export_vars.cmake")
4+
file(WRITE "${EXPORT_FILE}" "")
5+
6+
# ==============================================================================
7+
# Export project metadata
8+
# ==============================================================================
9+
file(APPEND "${EXPORT_FILE}" "set(LIBCACHESIM_VERSION \"${${PROJECT_NAME}_VERSION}\")\n")
10+
11+
# ==============================================================================
12+
# Export essential include directory variables
13+
# ==============================================================================
14+
foreach(var IN ITEMS GLib_INCLUDE_DIRS GLib_CONFIG_INCLUDE_DIR XGBOOST_INCLUDE_DIR LIGHTGBM_PATH ZSTD_INCLUDE_DIR)
15+
file(APPEND "${EXPORT_FILE}" "set(${var} \"${${var}}\")\n")
16+
endforeach()
17+
18+
# ==============================================================================
19+
# Export dependency library variables
20+
# ==============================================================================
21+
file(APPEND "${EXPORT_FILE}" "set(dependency_libs \"${dependency_libs}\")\n")
22+
23+
# ==============================================================================
24+
# Export essential build option variables
25+
# ==============================================================================
26+
file(APPEND "${EXPORT_FILE}" "set(LOG_LEVEL_LOWER \"${LOG_LEVEL_LOWER}\")\n")
27+
28+
message(STATUS "Exported essential variables to ${EXPORT_FILE}")

0 commit comments

Comments
 (0)