Skip to content

Commit a53699d

Browse files
committed
Merge branch 'main' into pip-support
# Conflicts: # CITATION.cff # bindings/CMakeLists.txt
2 parents f32af8b + e1df632 commit a53699d

6 files changed

Lines changed: 161 additions & 10 deletions

File tree

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ authors:
2626
repository-code: 'https://github.com/SC-SGS/hardware_sampling'
2727
license: MIT
2828
version: v1.1.0
29-
date-released: '2024-10-09'
29+
date-released: '2025-04-29'

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ add_library(${HWS_LIBRARY_NAME} SHARED ${HWS_SOURCES})
2525
add_library(hws::hws ALIAS ${HWS_LIBRARY_NAME})
2626

2727
# set install target
28-
set(HWS_TARGETS_TO_INSTALL ${HWS_LIBRARY_NAME})
28+
set(HWS_TARGETS_TO_INSTALL )
2929

3030
# use C++17
3131
target_compile_features(${HWS_LIBRARY_NAME} PUBLIC cxx_std_17)
@@ -170,7 +170,7 @@ endif ()
170170
########################################################################################################################
171171
include(GNUInstallDirs)
172172
## install all necessary library targets
173-
install(TARGETS ${HWS_TARGETS_TO_INSTALL}
173+
install(TARGETS ${HWS_LIBRARY_NAME}
174174
EXPORT hws_Targets
175175
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" # all files that are neither executables, shared lib or headers
176176
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" # all shared lib files
@@ -208,5 +208,6 @@ install(EXPORT hws_Targets
208208
install(FILES
209209
"${PROJECT_BINARY_DIR}/hwsConfig.cmake"
210210
"${PROJECT_BINARY_DIR}/hwsConfigVersion.cmake"
211+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findlevel_zero.cmake"
211212
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/hws/cmake
212213
)

bindings/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,19 @@ endif ()
5858
# create pybind11 module
5959
set(HWS_PYTHON_BINDINGS_LIBRARY_NAME HardwareSampling)
6060
pybind11_add_module(${HWS_PYTHON_BINDINGS_LIBRARY_NAME} ${HWS_PYTHON_BINDINGS_SOURCES})
61-
list(APPEND HWS_TARGETS_TO_INSTALL "${HWS_PYTHON_BINDINGS_LIBRARY_NAME}")
62-
set(HWS_TARGETS_TO_INSTALL "${HWS_TARGETS_TO_INSTALL}" PARENT_SCOPE)
6361

6462
# add necessary compile options
6563
target_include_directories(${HWS_PYTHON_BINDINGS_LIBRARY_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/..)
6664
target_link_libraries(${HWS_PYTHON_BINDINGS_LIBRARY_NAME} PRIVATE ${HWS_LIBRARY_NAME})
6765
target_compile_definitions(${HWS_PYTHON_BINDINGS_LIBRARY_NAME} PRIVATE PYBIND11_DETAILED_ERROR_MESSAGES)
6866

69-
# install the __init__.py file so Python recognizes the package when installed via pip
7067
include(GNUInstallDirs)
68+
# install Python bindings
69+
install(TARGETS ${HWS_PYTHON_BINDINGS_LIBRARY_NAME}
70+
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
7174
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/__init__.py"
7275
DESTINATION "${CMAKE_INSTALL_LIBDIR}"
7376
)

cmake/hwsConfig.cmake.in

Lines changed: 148 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66

77
@PACKAGE_INIT@
88

9+
# helper functions to check whether a CMake string contains a substring
10+
function(string_contains STR SUBSTRING RESULT_VAR)
11+
string(FIND "${STR}" "${SUBSTRING}" _index)
12+
if(_index EQUAL -1)
13+
set(${RESULT_VAR} OFF PARENT_SCOPE)
14+
else()
15+
set(${RESULT_VAR} ON PARENT_SCOPE)
16+
endif()
17+
endfunction()
18+
919
include(CMakeFindDependencyMacro)
1020

1121
# always try finding {fmt}
@@ -14,6 +24,143 @@ include(CMakeFindDependencyMacro)
1424
list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR}/../../../lib/cmake/fmt")
1525
find_dependency(fmt REQUIRED)
1626

17-
# sanity checks
27+
28+
# load all targets
1829
include("${CMAKE_CURRENT_LIST_DIR}/hwsTargets.cmake")
30+
31+
# assume hws can be found
32+
set(hws_FOUND ON)
33+
34+
# get all compile definitions
35+
get_target_property(HWS_COMPILE_DEFINITIONS hws::hws INTERFACE_COMPILE_DEFINITIONS)
36+
37+
# check whether CPUs are supported
38+
string_contains("${HWS_COMPILE_DEFINITIONS}" "HWS_FOR_CPUS_ENABLED" HWS_HAS_CPU_SUPPORT)
39+
if (HWS_HAS_CPU_SUPPORT)
40+
# check if hws was build with lscpu -> check if lscpu can be found
41+
if (@HWS_LSCPU_FOUND@)
42+
find_program(HWS_HAS_LSCPU_SUPPORT lscpu)
43+
if (NOT HWS_HAS_LSCPU_SUPPORT)
44+
set(hws_FOUND OFF)
45+
set(hws_NOT_FOUND_MESSAGE "Couldn't find necessary program \"lscpu\".")
46+
return()
47+
elseif (NOT hws_FIND_QUIETLY)
48+
message(STATUS "Found \"lscpu\" program.")
49+
endif ()
50+
endif ()
51+
52+
# check if hws was build with free -> check if free can be found
53+
if (@HWS_FREE_FOUND@)
54+
find_program(HWS_HAS_FREE_SUPPORT free)
55+
if (NOT HWS_HAS_FREE_SUPPORT)
56+
set(hws_FOUND OFF)
57+
set(hws_NOT_FOUND_MESSAGE "Couldn't find necessary program \"free\".")
58+
return()
59+
elseif (NOT hws_FIND_QUIETLY)
60+
message(STATUS "Found \"free\" program.")
61+
endif ()
62+
endif ()
63+
64+
# check if hws was build with free -> check if free can be found
65+
if (@HWS_TURBOSTAT_FOUND@)
66+
find_program(HWS_HAS_TURBOSTAT_SUPPORT turbostat)
67+
if (NOT HWS_HAS_TURBOSTAT_SUPPORT)
68+
set(hws_FOUND OFF)
69+
set(hws_NOT_FOUND_MESSAGE "Couldn't find necessary program \"turbostat\".")
70+
return()
71+
else ()
72+
# check required privileges when using turbostat
73+
if (@HWS_TURBOSTAT_EXECUTION_TYPE@ MATCHES "without_root")
74+
# check if turbostat can be executed without root privileges
75+
execute_process(COMMAND turbostat -n 1 -S -q
76+
RESULT_VARIABLE HWS_HAS_TURBOSTAT_SUPPORT_WITHOUT_ROOT
77+
OUTPUT_QUIET
78+
ERROR_QUIET)
79+
if (NOT HWS_HAS_TURBOSTAT_SUPPORT_WITHOUT_ROOT EQUAL 0)
80+
set(hws_FOUND OFF)
81+
set(hws_NOT_FOUND_MESSAGE "turbostat must be configured to run without root privileges.")
82+
return()
83+
endif ()
84+
elseif (@HWS_TURBOSTAT_EXECUTION_TYPE@ MATCHES "root")
85+
# check if turbostat can be executed with root privileges and without a password
86+
execute_process(COMMAND sudo -n turbostat -n 1 -i 0.001 -S -q
87+
RESULT_VARIABLE HWS_HAS_TURBOSTAT_SUPPORT_ROOT_REQUIRED
88+
OUTPUT_QUIET
89+
ERROR_QUIET)
90+
if (HWS_HAS_TURBOSTAT_SUPPORT_ROOT_REQUIRED EQUAL 0)
91+
execute_process(COMMAND sudo turbostat -n 1 -i 0.001 -S -q
92+
RESULT_VARIABLE HWS_HAS_TURBOSTAT_SUPPORT_WITH_ROOT
93+
OUTPUT_QUIET
94+
ERROR_QUIET)
95+
if (NOT HWS_HAS_TURBOSTAT_SUPPORT_WITH_ROOT EQUAL 0)
96+
set(hws_FOUND OFF)
97+
set(hws_NOT_FOUND_MESSAGE "turbostat must be configured to run with root privileges and without the need for a password.")
98+
return()
99+
endif ()
100+
else ()
101+
set(hws_FOUND OFF)
102+
set(hws_NOT_FOUND_MESSAGE "Invalid turbostat configuration.")
103+
return()
104+
endif ()
105+
else ()
106+
endif ()
107+
endif ()
108+
endif ()
109+
110+
if (NOT hws_FIND_QUIETLY)
111+
message(STATUS "Enabled support for CPUs via hws.")
112+
endif ()
113+
endif ()
114+
115+
# check whether NVIDIA GPUs are supported
116+
string_contains("${HWS_COMPILE_DEFINITIONS}" "HWS_FOR_NVIDIA_GPUS_ENABLED" HWS_HAS_GPU_NVIDIA_SUPPORT)
117+
if (HWS_HAS_GPU_NVIDIA_SUPPORT)
118+
find_dependency(CUDAToolkit)
119+
if (NOT hws_FIND_QUIETLY)
120+
message(STATUS "Enabled support for NVIDIA GPUs via hws.")
121+
endif ()
122+
endif ()
123+
124+
# check whether AMD GPUs are supported
125+
string_contains("${HWS_COMPILE_DEFINITIONS}" "HWS_FOR_AMD_GPUS_ENABLED" HWS_HAS_GPU_AMD_SUPPORT)
126+
if (HWS_HAS_GPU_AMD_SUPPORT)
127+
find_dependency(rocm_smi)
128+
find_dependency(HIP)
129+
if (NOT hws_FIND_QUIETLY)
130+
message(STATUS "Enabled support for AMD GPUs via hws.")
131+
endif ()
132+
endif ()
133+
134+
# check whether Intel GPUs are supported
135+
string_contains("${HWS_COMPILE_DEFINITIONS}" "HWS_FOR_INTEL_GPUS_ENABLED" HWS_HAS_GPU_INTEL_SUPPORT)
136+
if (HWS_HAS_GPU_INTEL_SUPPORT)
137+
# add Findlevel_zero.cmake to module path
138+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
139+
find_dependency(level_zero)
140+
if (NOT hws_FIND_QUIETLY)
141+
message(STATUS "Enabled support for Intel GPUs via hws.")
142+
endif ()
143+
endif ()
144+
145+
146+
# check possible provided version
147+
include(FindPackageHandleStandardArgs)
148+
find_package_handle_standard_args(hws
149+
REQUIRED_VARS hws_FOUND
150+
VERSION_VAR hws_VERSION
151+
)
152+
153+
# add additional output if hws could be found
154+
if (NOT hws_FIND_QUIETLY AND hws_FOUND)
155+
# output the available PLSSVM target platforms
156+
message(STATUS "The sampling interval is @HWS_SAMPLING_INTERVAL@ms.")
157+
# output the hws build type
158+
message(STATUS "The hws library was built in @CMAKE_BUILD_TYPE@ mode.")
159+
# output if error checks are enabled
160+
if (@HWS_ENABLE_ERROR_CHECKS@)
161+
message(STATUS "The hws library was built with error checks enabled.")
162+
endif ()
163+
endif()
164+
165+
# sanity checks
19166
check_required_components("hws")

src/hws/gpu_amd/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ if (NOT rocm_smi_FOUND)
1616
endif ()
1717
return()
1818
endif ()
19-
message(STATUS "Enable sampling of AMD GPU information using ROCm SMI.")
19+
message(STATUS "Enable sampling of AMD GPU information using ROCm SMI (${rocm_smi_VERSION}).")
2020

2121
# must also find HIP
2222
find_package(HIP REQUIRED)
2323

2424
# link against necessary libraries
25-
target_link_libraries(${HWS_LIBRARY_NAME} PRIVATE -lrocm_smi64 hip::host)
25+
target_link_libraries(${HWS_LIBRARY_NAME} PRIVATE rocm_smi64 hip::host)
2626
target_include_directories(${HWS_LIBRARY_NAME} PRIVATE ${ROCM_SMI_INCLUDE_DIR})
2727

2828
# add source file to source file list

src/hws/gpu_nvidia/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if (NOT CUDAToolkit_FOUND)
1616
endif ()
1717
return()
1818
endif ()
19-
message(STATUS "Enable sampling of NVIDIA GPU information using NVML.")
19+
message(STATUS "Enable sampling of NVIDIA GPU information using NVML (${CUDAToolkit_VERSION}).")
2020

2121
# link against necessary libraries
2222
target_link_libraries(${HWS_LIBRARY_NAME} PRIVATE CUDA::nvml CUDA::cudart)

0 commit comments

Comments
 (0)