From 95cab5d1878b7a3a331a8ffd424eeaad11c5022a Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Mon, 10 Feb 2025 18:13:56 +0100 Subject: [PATCH 1/3] Add support for installation via pip. --- README.md | 15 ++++++++++++-- bindings/CMakeLists.txt | 6 ++++++ bindings/__init__.py | 5 +++++ bindings/main.cpp | 3 +++ pyproject.toml | 43 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 bindings/__init__.py create mode 100644 pyproject.toml diff --git a/README.md b/README.md index f4abb34..ac5db7a 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ The `[optional_options]` can be one or multiple of: - `HWS_SAMPLING_INTERVAL=100ms` (default: `100ms`): set the sampling interval in milliseconds - `HWS_ENABLE_PYTHON_BINDINGS=ON|OFF` (default: `ON`): enable Python bindings -### Installing +### Installing via CMake The library supports the `install` target: @@ -75,6 +75,17 @@ export PYTHONPATH=${CMAKE_INSTALL_PREFIX}/lib:${CMAKE_INSTALL_PREFIX}/lib64:${PY **Note:** when using Intel GPUs, the `CMAKE_MODULE_PATH` should be updated to point to our `cmake` directory containing the `Findlevel_zero.cmake` file and `export ZES_ENABLE_SYSMAN=1` should be set. +### Installing via pip + +The library is also available via pip: + +```bash +pip install hardware-sampling +``` + +This pip install behaves **as if** no additional CMake options were provided. +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. + ## Available samples The sampling type `fixed` denotes samples that are gathered once per hardware samples like maximum clock frequencies or @@ -287,7 +298,7 @@ plt.show() ```

- example frequency plot + example frequency plot

## License diff --git a/bindings/CMakeLists.txt b/bindings/CMakeLists.txt index f2ef8d8..bdac8dc 100644 --- a/bindings/CMakeLists.txt +++ b/bindings/CMakeLists.txt @@ -65,3 +65,9 @@ set(HWS_TARGETS_TO_INSTALL "${HWS_TARGETS_TO_INSTALL}" PARENT_SCOPE) target_include_directories(${HWS_PYTHON_BINDINGS_LIBRARY_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/..) target_link_libraries(${HWS_PYTHON_BINDINGS_LIBRARY_NAME} PRIVATE ${HWS_LIBRARY_NAME}) target_compile_definitions(${HWS_PYTHON_BINDINGS_LIBRARY_NAME} PRIVATE PYBIND11_DETAILED_ERROR_MESSAGES) + +# install the __init__.py file so Python recognizes the package when installed via pip +include(GNUInstallDirs) +install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py" + DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) \ No newline at end of file diff --git a/bindings/__init__.py b/bindings/__init__.py new file mode 100644 index 0000000..f4badd4 --- /dev/null +++ b/bindings/__init__.py @@ -0,0 +1,5 @@ +# import all bindings from the compiled hws module +from .HardwareSampling import * +# explicitly set the module level attributes +__doc__ = HardwareSampling.__doc__ +__version__ = HardwareSampling.__version__ \ No newline at end of file diff --git a/bindings/main.cpp b/bindings/main.cpp index f3dca3f..3f062e7 100644 --- a/bindings/main.cpp +++ b/bindings/main.cpp @@ -5,6 +5,8 @@ * See the LICENSE.md file in the project root for full license information. */ +#include "hws/version.hpp" // hws::version::version + #include "pybind11/pybind11.h" // PYBIND11_MODULE, py::module_ #include // std::string_view @@ -28,6 +30,7 @@ void init_version(py::module_ &); PYBIND11_MODULE(HardwareSampling, m) { m.doc() = "Hardware Sampling for CPUs and GPUs"; + m.attr("__version__") = hws::version::version; init_event(m); init_sample_category(m); diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..09b2cce --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,43 @@ +[build-system] +requires = ["scikit-build-core"] +build-backend = "scikit_build_core.build" +# set the necessary CMake build options +[tool.scikit-build] +cmake.args = [ + "-DCMAKE_INSTALL_LIBDIR=HardwareSampling", + "-DCMAKE_INSTALL_BINDIR=HardwareSampling", + "-DCMAKE_INSTALL_INCLUDEDIR=HardwareSampling", + "-DCMAKE_INSTALL_MANDIR=HardwareSampling", + "-DCMAKE_INSTALL_DATAROOTDIR=HardwareSampling/cmake", + "-DCMAKE_INSTALL_RPATH=$ORIGIN" +] +sdist.exclude = ["build*/", "dist/", "docs/html/", ".github", "examples", "install", ".clang*", ".clion*", ".gitignore"] +# project specific metadata +[project] +name = "hardware_sampling" +version = "1.0.1" +description = "hws - Hardware Sampling for GPUs and CPUs (e.g., clock frequencies, memory consumption, temperatures, or energy draw)" +readme = "README.md" +license = { file = "LICENSE" } +authors = [ + { name = "Marcel Breyer" } +] +maintainers = [ + { name = "University of Stuttgart IPVS - SC", email = "sc@ipvs.uni-stuttgart.de" } +] +requires-python = ">=3.8" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Environment :: GPU", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Operating System :: POSIX :: Linux", + "Programming Language :: C++", + "Programming Language :: Python :: 3" +] +# project specific URLs +[project.urls] +documentation = "https://sc-sgs.github.io/hardware_sampling/" +repository = "https://github.com/SC-SGS/hardware_sampling.git" +issues = "https://github.com/SC-SGS/hardware_sampling/issues" \ No newline at end of file From f770bc76cc8fe0ff316943d998b4006159000013 Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Tue, 11 Feb 2025 16:01:37 +0100 Subject: [PATCH 2/3] Add citation file. --- CITATION.cff | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 CITATION.cff diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 0000000..319cb6b --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,29 @@ +# This CITATION.cff file was generated with cffinit. +# Visit https://bit.ly/cffinit to generate yours today! + +cff-version: 1.2.0 +title: hws - Hardware Sampling for GPUs and CPUs +message: >- + If you use this software, please cite it using the + metadata from this file. +type: software +authors: + - given-names: Marcel + family-names: Breyer + email: Marcel.Breyer@ipvs.uni-stuttgart.de + affiliation: University of Stuttgart + orcid: 'https://orcid.org/0000-0003-3574-0650' + - given-names: Alexander + family-names: Van Craen + email: Alexander.Van-Craen@ipvs.uni-stuttgart.de + affiliation: University of Stuttgart + orcid: 'https://orcid.org/0000-0002-3336-7226' + - given-names: Dirk + family-names: Pflüger + email: Dirk.Pflueger@ipvs.uni-stuttgart.de + orcid: 'https://orcid.org/0000-0002-4360-0212' + affiliation: University of Stuttgart +repository-code: 'https://github.com/SC-SGS/hardware_sampling' +license: MIT +version: v1.0.3 +date-released: '2024-10-09' From f32af8b1f4e89549385249bc2bd945fceb43fd3a Mon Sep 17 00:00:00 2001 From: Marcel Breyer Date: Wed, 23 Apr 2025 10:44:47 +0200 Subject: [PATCH 3/3] Update library version. --- CITATION.cff | 2 +- CMakeLists.txt | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index 319cb6b..62d264a 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -25,5 +25,5 @@ authors: affiliation: University of Stuttgart repository-code: 'https://github.com/SC-SGS/hardware_sampling' license: MIT -version: v1.0.3 +version: v1.1.0 date-released: '2024-10-09' diff --git a/CMakeLists.txt b/CMakeLists.txt index 78f83c8..bb121f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ cmake_minimum_required(VERSION 3.22) project("hws - Hardware Sampling for GPUs and CPUs" - VERSION 1.0.1 + VERSION 1.1.0 LANGUAGES CXX DESCRIPTION "Hardware sampling (e.g., clock frequencies, memory consumption, temperatures, or energy draw) for CPUs and GPUS.") diff --git a/pyproject.toml b/pyproject.toml index 09b2cce..489641a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ sdist.exclude = ["build*/", "dist/", "docs/html/", ".github", "examples", "insta # project specific metadata [project] name = "hardware_sampling" -version = "1.0.1" +version = "1.1.0" description = "hws - Hardware Sampling for GPUs and CPUs (e.g., clock frequencies, memory consumption, temperatures, or energy draw)" readme = "README.md" license = { file = "LICENSE" }