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+
919include (CMakeFindDependencyMacro)
1020
1121# always try finding {fmt}
@@ -14,6 +24,143 @@ include(CMakeFindDependencyMacro)
1424list (APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_LIST_DIR} /../../../lib/cmake/fmt" )
1525find_dependency(fmt REQUIRED)
1626
17- # sanity checks
27+
28+ # load all targets
1829include ("${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
19166check_required_components("hws" )
0 commit comments