@@ -62,8 +62,8 @@ target_compile_definitions(${HWS_LIBRARY_NAME} PUBLIC HWS_SAMPLING_INTERVAL=${HW
6262
6363# install fmt as dependency
6464include (FetchContent )
65- set (HWS_fmt_VERSION 11.0.2 )
66- find_package (fmt 11.0.2 QUIET )
65+ set (HWS_fmt_VERSION 11.1.4 )
66+ find_package (fmt 11.1.4 QUIET )
6767if (fmt_FOUND)
6868 message (STATUS "Found package fmt." )
6969else ()
@@ -102,97 +102,10 @@ configure_file(
102102####################################################################################################################
103103## CPU measurements ##
104104####################################################################################################################
105- ## check whether lscpu could be found -> used for the CPU targets as well as for ALL host measurements
106- ## -> checked even if no CPU targets where provided
107- ## LINUX only
108- find_program (HWS_LSCPU_FOUND lscpu )
109- if (HWS_LSCPU_FOUND)
110- message (STATUS "Enable sampling of CPU information using lscpu." )
111- target_compile_definitions (${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_LSCPU_ENABLED )
112- endif ()
113-
114- ## check whether free could be found -> used for the CPU targets as well as for ALL host measurements
115- ## -> checked even if no CPU targets where provided
116- ## LINUX only
117- find_program (HWS_FREE_FOUND free )
118- if (HWS_FREE_FOUND)
119- message (STATUS "Enable sampling of CPU information using free." )
120- target_compile_definitions (${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_FREE_ENABLED )
121- endif ()
122-
123- ## check whether turbostat could be found -> used for the CPU targets as well as for ALL host measurements
124- ## -> checked even if no CPU targets where provided
125- find_program (HWS_TURBOSTAT_FOUND turbostat )
126- if (HWS_TURBOSTAT_FOUND)
127- ## check if the turbostat command works as intended
128- execute_process (COMMAND turbostat -n 1 -S -q
129- RESULT_VARIABLE HWS_TURBOSTAT_WITHOUT_ROOT
130- OUTPUT_QUIET
131- ERROR_QUIET )
132- if (NOT HWS_TURBOSTAT_WITHOUT_ROOT EQUAL 0)
133- message (STATUS "Can't use turbostat without root permissions! Try using with sudo..." )
134- execute_process (COMMAND sudo -n turbostat -n 1 -i 0.001 -S -q
135- RESULT_VARIABLE HWS_TURBOSTAT_ROOT_PASSWORD_REQUIRED
136- OUTPUT_QUIET
137- ERROR_QUIET )
138- if (NOT HWS_TURBOSTAT_ROOT_PASSWORD_REQUIRED EQUAL 0)
139- message (STATUS "Can't use turbostat with root if a sudo password is required! Please add turbostat to the sudoer group." )
140- message (STATUS "Disabling turbostat support!" )
141- else ()
142- execute_process (COMMAND sudo turbostat -n 1 -i 0.001 -S -q
143- RESULT_VARIABLE HWS_TURBOSTAT_WITH_ROOT
144- OUTPUT_QUIET
145- ERROR_QUIET )
146- if (NOT HWS_TURBOSTAT_WITH_ROOT EQUAL 0)
147- message (STATUS "Can't use turbostat with root even if no sudo password is required!" )
148- message (STATUS "Disabling turbostat support!" )
149- else ()
150- message (STATUS "Enable sampling of CPU information using turbostat." )
151-
152- set (HWS_TURBOSTAT_EXECUTION_TYPE "root" )
153- # add compile definitions
154- target_compile_definitions (${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_TURBOSTAT_ENABLED )
155- target_compile_definitions (${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_TURBOSTAT_ROOT )
156- endif ()
157- endif ()
158- else ()
159- set (HWS_TURBOSTAT_EXECUTION_TYPE "without_root" )
160- # add compile definitions
161- target_compile_definitions (${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_TURBOSTAT_ENABLED )
162- endif ()
163- endif ()
164-
165- ## check if the CPU hardware tracker can be used
166- if (HWS_LSCPU_FOUND OR HWS_FREE_FOUND OR HWS_TURBOSTAT_EXECUTION_TYPE)
167- ## try finding subprocess.h
168- set (HWS_subprocess_VERSION b6e1611d430e3019c423d2af26bb162e7ed5c3ae)
169- find_package (subprocess QUIET )
170- if (subprocess_FOUND)
171- message (STATUS "Found package subprocess.h." )
172- target_include_directories (${HWS_LIBRARY_NAME} PRIVATE ${subprocess_INCLUDE_DIR} )
173- else ()
174- include (FetchContent )
175- message (STATUS "Couldn't find package subprocess.h. Building version ${HWS_subprocess_VERSION} from source." )
176- # fetch subprocess library subprocess.h
177- FetchContent_Declare (subprocess
178- GIT_REPOSITORY https://github.com/sheredom/subprocess.h.git
179- GIT_TAG ${HWS_subprocess_VERSION}
180- QUIET
181- )
182- FetchContent_MakeAvailable (subprocess)
183- target_include_directories (${HWS_LIBRARY_NAME} PRIVATE $<BUILD_INTERFACE :${subprocess_SOURCE_DIR} >)
184- endif ()
185-
186- # add source file to source file list
187- target_sources (${HWS_LIBRARY_NAME} PRIVATE
188- $<BUILD_INTERFACE :
189- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /cpu /hardware_sampler .cpp ;
190- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /cpu /cpu_samples .cpp ;
191- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /cpu /utility .cpp ;
192- >)
193-
194- # add compile definitions
195- target_compile_definitions (${HWS_LIBRARY_NAME} PUBLIC HWS_FOR_CPUS_ENABLED )
105+ set (HWS_ENABLE_CPU_SAMPLING AUTO CACHE STRING "Enable sampling of CPUs." )
106+ set_property (CACHE HWS_ENABLE_CPU_SAMPLING PROPERTY STRINGS AUTO ON OFF )
107+ if (HWS_ENABLE_CPU_SAMPLING MATCHES "AUTO" OR HWS_ENABLE_CPU_SAMPLING)
108+ add_subdirectory (src/hws/cpu )
196109else ()
197110 message (STATUS "Hardware sampling for CPUs disabled!" )
198111endif ()
@@ -201,23 +114,10 @@ endif ()
201114####################################################################################################################
202115## NVIDIA GPU sampling via NVML ##
203116####################################################################################################################
204- # find libraries necessary for NVML and link against them
205- find_package (CUDAToolkit QUIET )
206- if (CUDAToolkit_FOUND)
207- target_link_libraries (${HWS_LIBRARY_NAME} PRIVATE CUDA::nvml CUDA::cudart )
208-
209- message (STATUS "Enable sampling of NVIDIA GPU information using NVML." )
210-
211- # add source file to source file list
212- target_sources (${HWS_LIBRARY_NAME} PRIVATE
213- $<BUILD_INTERFACE :
214- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /gpu_nvidia /hardware_sampler .cpp ;
215- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /gpu_nvidia /nvml_samples .cpp ;
216- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /gpu_nvidia /utility .cpp
217- >)
218-
219- # add compile definition
220- target_compile_definitions (${HWS_LIBRARY_NAME} PUBLIC HWS_FOR_NVIDIA_GPUS_ENABLED )
117+ set (HWS_ENABLE_GPU_NVIDIA_SAMPLING AUTO CACHE STRING "Enable sampling of NVIDIA GPUs." )
118+ set_property (CACHE HWS_ENABLE_GPU_NVIDIA_SAMPLING PROPERTY STRINGS AUTO ON OFF )
119+ if (HWS_ENABLE_GPU_NVIDIA_SAMPLING MATCHES "AUTO" OR HWS_ENABLE_GPU_NVIDIA_SAMPLING)
120+ add_subdirectory (src/hws/gpu_nvidia )
221121else ()
222122 message (STATUS "Hardware sampling for NVIDIA GPUs disabled!" )
223123endif ()
@@ -226,25 +126,10 @@ endif ()
226126####################################################################################################################
227127## AMD GPU sampling via ROCm SMI lib ##
228128####################################################################################################################
229- ## try finding ROCm SMI
230- find_package (rocm_smi QUIET )
231- if (rocm_smi_FOUND)
232- find_package (HIP REQUIRED )
233- target_link_libraries (${HWS_LIBRARY_NAME} PRIVATE -lrocm_smi64 hip::host )
234- target_include_directories (${HWS_LIBRARY_NAME} PRIVATE ${ROCM_SMI_INCLUDE_DIR} )
235-
236- message (STATUS "Enable sampling of AMD GPU information using ROCm SMI." )
237-
238- # add source file to source file list
239- target_sources (${HWS_LIBRARY_NAME} PRIVATE
240- $<BUILD_INTERFACE :
241- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /gpu_amd /hardware_sampler .cpp ;
242- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /gpu_amd /rocm_smi_samples .cpp ;
243- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /gpu_amd /utility .cpp
244- >)
245-
246- # add compile definition
247- target_compile_definitions (${HWS_LIBRARY_NAME} PUBLIC HWS_FOR_AMD_GPUS_ENABLED )
129+ set (HWS_ENABLE_GPU_AMD_SAMPLING AUTO CACHE STRING "Enable sampling of AMD GPUs." )
130+ set_property (CACHE HWS_ENABLE_GPU_AMD_SAMPLING PROPERTY STRINGS AUTO ON OFF )
131+ if (HWS_ENABLE_GPU_AMD_SAMPLING MATCHES "AUTO" OR HWS_ENABLE_GPU_AMD_SAMPLING)
132+ add_subdirectory (src/hws/gpu_amd )
248133else ()
249134 message (STATUS "Hardware sampling for AMD GPUs disabled!" )
250135endif ()
@@ -253,26 +138,10 @@ endif ()
253138####################################################################################################################
254139## Intel GPU sampling via Level Zero ##
255140####################################################################################################################
256- # set the CMAKE_MODULE_PATH to the cmake directory
257- list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR} /cmake" )
258-
259- # try finding Level Zero
260- find_package (level_zero QUIET )
261- if (level_zero_FOUND)
262- target_link_libraries (${HWS_LIBRARY_NAME} PRIVATE level_zero )
263-
264- message (STATUS "Enable sampling of Intel GPU information using Level Zero." )
265-
266- # add source file to source file list
267- target_sources (${HWS_LIBRARY_NAME} PRIVATE
268- $<BUILD_INTERFACE :
269- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /gpu_intel /hardware_sampler .cpp ;
270- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /gpu_intel /level_zero_samples .cpp ;
271- ${CMAKE_CURRENT_SOURCE_DIR} /src /hws /gpu_intel /utility .cpp
272- >)
273-
274- # add compile definition
275- target_compile_definitions (${HWS_LIBRARY_NAME} PUBLIC HWS_FOR_INTEL_GPUS_ENABLED )
141+ set (HWS_ENABLE_GPU_INTEL_SAMPLING AUTO CACHE STRING "Enable sampling of Intel GPUs." )
142+ set_property (CACHE HWS_ENABLE_GPU_INTEL_SAMPLING PROPERTY STRINGS AUTO ON OFF )
143+ if (HWS_ENABLE_GPU_INTEL_SAMPLING MATCHES "AUTO" OR HWS_ENABLE_GPU_INTEL_SAMPLING)
144+ add_subdirectory (src/hws/gpu_intel )
276145else ()
277146 message (STATUS "Hardware sampling for Intel GPUs disabled!" )
278147endif ()
0 commit comments