Skip to content

Commit 17bd3bd

Browse files
authored
Merge pull request #4 from SC-SGS/pip-support
2 parents e1df632 + a53699d commit 17bd3bd

5 files changed

Lines changed: 69 additions & 2 deletions

File tree

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ The `[optional_options]` can be one or multiple of:
7575
- `HWS_SAMPLING_INTERVAL=100ms` (default: `100ms`): set the sampling interval in milliseconds
7676
- `HWS_ENABLE_PYTHON_BINDINGS=ON|OFF` (default: `ON`): enable Python bindings
7777

78-
### Installing
78+
### Installing via CMake
7979

8080
The library supports the `install` target:
8181

@@ -95,6 +95,17 @@ export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:${PY
9595
**Note:** when using Intel GPUs, the `CMAKE_MODULE_PATH` should be updated to point to our `cmake` directory containing the
9696
`Findlevel_zero.cmake` file and `export ZES_ENABLE_SYSMAN=1` should be set.
9797

98+
### Installing via pip
99+
100+
The library is also available via pip:
101+
102+
```bash
103+
pip install hardware-sampling
104+
```
105+
106+
This pip install behaves **as if** no additional CMake options were provided.
107+
This means that only the hardware is supported for which the respective vendor libraries was available at the point of the `pip install hardware-sampling` invocation.
108+
98109
## Available samples
99110

100111
The sampling type `fixed` denotes samples that are gathered once per hardware samples like maximum clock frequencies or
@@ -307,7 +318,7 @@ plt.show()
307318
```
308319

309320
<p align="center">
310-
<img alt="example frequency plot" src=".figures/clock_frequency.png" width="75%">
321+
<img alt="example frequency plot" src="https://github.com/SC-SGS/hardware_sampling/raw/main/.figures/clock_frequency.png" width="75%">
311322
</p>
312323

313324
## License

bindings/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@ include(GNUInstallDirs)
6868
# install Python bindings
6969
install(TARGETS ${HWS_PYTHON_BINDINGS_LIBRARY_NAME}
7070
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" # all shared lib files
71+
)
72+
73+
# install the __init__.py file so Python recognizes the package when installed via pip
74+
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py"
75+
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
7176
)

bindings/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# import all bindings from the compiled hws module
2+
from .HardwareSampling import *
3+
# explicitly set the module level attributes
4+
__doc__ = HardwareSampling.__doc__
5+
__version__ = HardwareSampling.__version__

bindings/main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* See the LICENSE.md file in the project root for full license information.
66
*/
77

8+
#include "hws/version.hpp" // hws::version::version
9+
810
#include "pybind11/pybind11.h" // PYBIND11_MODULE, py::module_
911

1012
#include <string_view> // std::string_view
@@ -28,6 +30,7 @@ void init_version(py::module_ &);
2830

2931
PYBIND11_MODULE(HardwareSampling, m) {
3032
m.doc() = "Hardware Sampling for CPUs and GPUs";
33+
m.attr("__version__") = hws::version::version;
3134

3235
init_event(m);
3336
init_sample_category(m);

pyproject.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[build-system]
2+
requires = ["scikit-build-core"]
3+
build-backend = "scikit_build_core.build"
4+
# set the necessary CMake build options
5+
[tool.scikit-build]
6+
cmake.args = [
7+
"-DCMAKE_INSTALL_LIBDIR=HardwareSampling",
8+
"-DCMAKE_INSTALL_BINDIR=HardwareSampling",
9+
"-DCMAKE_INSTALL_INCLUDEDIR=HardwareSampling",
10+
"-DCMAKE_INSTALL_MANDIR=HardwareSampling",
11+
"-DCMAKE_INSTALL_DATAROOTDIR=HardwareSampling/cmake",
12+
"-DCMAKE_INSTALL_RPATH=$ORIGIN"
13+
]
14+
sdist.exclude = ["build*/", "dist/", "docs/html/", ".github", "examples", "install", ".clang*", ".clion*", ".gitignore"]
15+
# project specific metadata
16+
[project]
17+
name = "hardware_sampling"
18+
version = "1.1.0"
19+
description = "hws - Hardware Sampling for GPUs and CPUs (e.g., clock frequencies, memory consumption, temperatures, or energy draw)"
20+
readme = "README.md"
21+
license = { file = "LICENSE" }
22+
authors = [
23+
{ name = "Marcel Breyer" }
24+
]
25+
maintainers = [
26+
{ name = "University of Stuttgart IPVS - SC", email = "sc@ipvs.uni-stuttgart.de" }
27+
]
28+
requires-python = ">=3.8"
29+
classifiers = [
30+
"Development Status :: 5 - Production/Stable",
31+
"Environment :: GPU",
32+
"Intended Audience :: Science/Research",
33+
"License :: OSI Approved :: MIT License",
34+
"Natural Language :: English",
35+
"Operating System :: POSIX :: Linux",
36+
"Programming Language :: C++",
37+
"Programming Language :: Python :: 3"
38+
]
39+
# project specific URLs
40+
[project.urls]
41+
documentation = "https://sc-sgs.github.io/hardware_sampling/"
42+
repository = "https://github.com/SC-SGS/hardware_sampling.git"
43+
issues = "https://github.com/SC-SGS/hardware_sampling/issues"

0 commit comments

Comments
 (0)