Skip to content

Commit e67c4e1

Browse files
Merge pull request #667 from lukaszstolarczuk/fixes-around-hwloc
Minor fixes around hwloc in CMake and CI
2 parents 6d0ec0c + 2a04237 commit e67c4e1

File tree

3 files changed

+116
-103
lines changed

3 files changed

+116
-103
lines changed

.github/workflows/basic.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,58 +32,74 @@ jobs:
3232
shared_library: 'OFF'
3333
level_zero_provider: 'ON'
3434
install_tbb: 'ON'
35+
disable_hwloc: 'OFF'
36+
link_hwloc_statically: 'OFF'
3537
- os: 'ubuntu-22.04'
3638
build_type: Release
3739
compiler: {c: clang, cxx: clang++}
3840
shared_library: 'OFF'
3941
level_zero_provider: 'ON'
4042
install_tbb: 'ON'
43+
disable_hwloc: 'OFF'
44+
link_hwloc_statically: 'OFF'
4145
- os: 'ubuntu-22.04'
4246
build_type: Release
4347
compiler: {c: gcc, cxx: g++}
4448
shared_library: 'ON'
4549
level_zero_provider: 'ON'
4650
install_tbb: 'ON'
51+
disable_hwloc: 'OFF'
52+
link_hwloc_statically: 'OFF'
4753
- os: 'ubuntu-24.04'
4854
build_type: Debug
4955
compiler: {c: gcc, cxx: g++}
5056
shared_library: 'ON'
5157
level_zero_provider: 'ON'
5258
install_tbb: 'ON'
59+
disable_hwloc: 'OFF'
60+
link_hwloc_statically: 'OFF'
5361
# test level_zero_provider='OFF'
5462
- os: 'ubuntu-22.04'
5563
build_type: Release
5664
compiler: {c: gcc, cxx: g++}
5765
shared_library: 'OFF'
5866
level_zero_provider: 'OFF'
5967
install_tbb: 'ON'
68+
disable_hwloc: 'OFF'
69+
link_hwloc_statically: 'OFF'
6070
# test icx compiler
6171
- os: 'ubuntu-22.04'
6272
build_type: Release
6373
compiler: {c: icx, cxx: icpx}
6474
shared_library: 'ON'
6575
level_zero_provider: 'ON'
66-
install_tbb: 'ON'
76+
install_tbb: 'ON'
77+
disable_hwloc: 'OFF'
78+
link_hwloc_statically: 'OFF'
6779
# test without installing TBB
6880
- os: 'ubuntu-22.04'
6981
build_type: Release
7082
compiler: {c: gcc, cxx: g++}
7183
shared_library: 'ON'
7284
level_zero_provider: 'ON'
7385
install_tbb: 'OFF'
86+
disable_hwloc: 'OFF'
87+
link_hwloc_statically: 'OFF'
7488
- os: 'ubuntu-22.04'
7589
build_type: Debug
7690
compiler: {c: gcc, cxx: g++}
7791
shared_library: 'ON'
7892
level_zero_provider: 'ON'
7993
install_tbb: 'ON'
8094
disable_hwloc: 'ON'
95+
link_hwloc_statically: 'OFF'
8196
- os: 'ubuntu-22.04'
8297
build_type: Release
8398
compiler: {c: gcc, cxx: g++}
8499
shared_library: 'ON'
85100
level_zero_provider: 'ON'
86101
install_tbb: 'ON'
102+
disable_hwloc: 'OFF'
87103
link_hwloc_statically: 'ON'
88104
runs-on: ${{matrix.os}}
89105

CMakeLists.txt

Lines changed: 98 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ option(UMF_BUILD_EXAMPLES "Build UMF examples" ON)
4848
option(UMF_BUILD_FUZZTESTS "Build UMF fuzz tests" OFF)
4949
option(UMF_BUILD_GPU_EXAMPLES "Build UMF GPU examples" OFF)
5050
option(UMF_DEVELOPER_MODE "Enable additional developer checks" OFF)
51+
option(
52+
UMF_DISABLE_HWLOC
53+
"Disable hwloc and UMF features requiring it (OS provider, memtargets, topology discovery)"
54+
OFF)
5155
option(
5256
UMF_LINK_HWLOC_STATICALLY
5357
"Link UMF with HWLOC library statically (supported for Linux, MacOS and Release build on Windows)"
@@ -63,10 +67,6 @@ option(UMF_USE_TSAN "Enable ThreadSanitizer checks" OFF)
6367
option(UMF_USE_MSAN "Enable MemorySanitizer checks" OFF)
6468
option(UMF_USE_VALGRIND "Enable Valgrind instrumentation" OFF)
6569
option(UMF_USE_GCOV "Enable gcov support" OFF)
66-
option(
67-
UMF_DISABLE_HWLOC
68-
"Disable features that requires hwloc (OS provider, memory targets, topology discovery)"
69-
OFF)
7070

7171
# set UMF_PROXY_LIB_BASED_ON_POOL to one of: SCALABLE or JEMALLOC
7272
set(KNOWN_PROXY_LIB_POOLS SCALABLE JEMALLOC)
@@ -100,16 +100,19 @@ else()
100100
message(FATAL_ERROR "Unknown OS type")
101101
endif()
102102

103-
if(NOT DEFINED UMF_HWLOC_REPO)
104-
set(UMF_HWLOC_REPO "https://github.com/open-mpi/hwloc.git")
105-
endif()
103+
if(UMF_DISABLE_HWLOC)
104+
message(STATUS "hwloc is disabled, hence OS provider, memtargets, "
105+
"topology discovery, examples won't be available!")
106+
else()
107+
if(NOT DEFINED UMF_HWLOC_REPO)
108+
set(UMF_HWLOC_REPO "https://github.com/open-mpi/hwloc.git")
109+
endif()
106110

107-
if(NOT DEFINED UMF_HWLOC_TAG)
108-
set(UMF_HWLOC_TAG hwloc-2.10.0)
109-
endif()
111+
if(NOT DEFINED UMF_HWLOC_TAG)
112+
set(UMF_HWLOC_TAG hwloc-2.10.0)
113+
endif()
110114

111-
if(NOT UMF_LINK_HWLOC_STATICALLY)
112-
if(NOT UMF_DISABLE_HWLOC)
115+
if(NOT UMF_LINK_HWLOC_STATICALLY)
113116
pkg_check_modules(LIBHWLOC hwloc>=2.3.0)
114117
if(NOT LIBHWLOC_FOUND)
115118
find_package(LIBHWLOC 2.3.0 REQUIRED hwloc)
@@ -119,86 +122,83 @@ if(NOT UMF_LINK_HWLOC_STATICALLY)
119122
set(DLL_PATH_LIST
120123
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
121124
)
122-
endif()
123-
# add PATH to DLL on Windows
124-
set(DLL_PATH_LIST
125-
"${DLL_PATH_LIST};PATH=path_list_append:${LIBHWLOC_LIBRARY_DIRS}/../bin"
126-
)
127-
elseif(WINDOWS AND NOT UMF_DISABLE_HWLOC)
128-
include(FetchContent)
129-
set(HWLOC_ENABLE_TESTING OFF)
130-
set(HWLOC_SKIP_LSTOPO ON)
131-
set(HWLOC_SKIP_TOOLS ON)
132-
133-
message(STATUS "Will fetch hwloc from ${UMF_HWLOC_REPO}")
134-
135-
FetchContent_Declare(
136-
hwloc_targ
137-
GIT_REPOSITORY ${UMF_HWLOC_REPO}
138-
GIT_TAG ${UMF_HWLOC_TAG}
139-
SOURCE_SUBDIR contrib/windows-cmake/ FIND_PACKAGE_ARGS)
140-
141-
FetchContent_GetProperties(hwloc_targ)
142-
if(NOT hwloc_targ_POPULATED)
143-
FetchContent_MakeAvailable(hwloc_targ)
144-
endif()
125+
elseif(WINDOWS)
126+
include(FetchContent)
127+
set(HWLOC_ENABLE_TESTING OFF)
128+
set(HWLOC_SKIP_LSTOPO ON)
129+
set(HWLOC_SKIP_TOOLS ON)
130+
131+
message(
132+
STATUS
133+
"Will fetch hwloc from ${UMF_HWLOC_REPO} (tag: ${UMF_HWLOC_TAG})"
134+
)
145135

146-
set(LIBHWLOC_INCLUDE_DIRS
147-
${hwloc_targ_SOURCE_DIR}/include;${hwloc_targ_BINARY_DIR}/include)
148-
set(LIBHWLOC_LIBRARY_DIRS
149-
${hwloc_targ_BINARY_DIR}/Release;${hwloc_targ_BINARY_DIR}/Debug)
136+
FetchContent_Declare(
137+
hwloc_targ
138+
GIT_REPOSITORY ${UMF_HWLOC_REPO}
139+
GIT_TAG ${UMF_HWLOC_TAG}
140+
SOURCE_SUBDIR contrib/windows-cmake/ FIND_PACKAGE_ARGS)
150141

151-
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
152-
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
153-
message(STATUS " LIBHWLOC_LIBRARY_DIRS = ${LIBHWLOC_LIBRARY_DIRS}")
154-
elseif(NOT UMF_DISABLE_HWLOC)
155-
include(FetchContent)
156-
message(STATUS "Will fetch hwloc from ${UMF_HWLOC_REPO}")
157-
158-
FetchContent_Declare(
159-
hwloc_targ
160-
GIT_REPOSITORY ${UMF_HWLOC_REPO}
161-
GIT_TAG ${UMF_HWLOC_TAG})
162-
163-
FetchContent_GetProperties(hwloc_targ)
164-
if(NOT hwloc_targ_POPULATED)
165-
FetchContent_MakeAvailable(hwloc_targ)
166-
endif()
142+
FetchContent_GetProperties(hwloc_targ)
143+
if(NOT hwloc_targ_POPULATED)
144+
FetchContent_MakeAvailable(hwloc_targ)
145+
endif()
167146

168-
add_custom_command(
169-
COMMAND ./autogen.sh
170-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
171-
OUTPUT ${hwloc_targ_SOURCE_DIR}/configure)
172-
add_custom_command(
173-
COMMAND
174-
./configure --prefix=${hwloc_targ_BINARY_DIR} --enable-static=yes
175-
--enable-shared=no --disable-libxml2 --disable-levelzero
176-
--disable-opencl --disable-cuda --disable-nvml CFLAGS=-fPIC
177-
CXXFLAGS=-fPIC
178-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
179-
OUTPUT ${hwloc_targ_SOURCE_DIR}/Makefile
180-
DEPENDS ${hwloc_targ_SOURCE_DIR}/configure)
181-
add_custom_command(
182-
COMMAND make
183-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
184-
OUTPUT ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la
185-
DEPENDS ${hwloc_targ_SOURCE_DIR}/Makefile)
186-
add_custom_command(
187-
COMMAND make install
188-
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
189-
OUTPUT ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a
190-
DEPENDS ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la)
191-
192-
add_custom_target(hwloc_prod
193-
DEPENDS ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
194-
add_library(hwloc INTERFACE)
195-
target_link_libraries(hwloc
196-
INTERFACE ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
197-
add_dependencies(hwloc hwloc_prod)
198-
199-
set(LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR}/lib)
200-
set(LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR}/include)
201-
set(LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
147+
set(LIBHWLOC_INCLUDE_DIRS
148+
${hwloc_targ_SOURCE_DIR}/include;${hwloc_targ_BINARY_DIR}/include)
149+
set(LIBHWLOC_LIBRARY_DIRS
150+
${hwloc_targ_BINARY_DIR}/Release;${hwloc_targ_BINARY_DIR}/Debug)
151+
else()
152+
include(FetchContent)
153+
message(
154+
STATUS
155+
"Will fetch hwloc from ${UMF_HWLOC_REPO} (tag: ${UMF_HWLOC_TAG})"
156+
)
157+
158+
FetchContent_Declare(
159+
hwloc_targ
160+
GIT_REPOSITORY ${UMF_HWLOC_REPO}
161+
GIT_TAG ${UMF_HWLOC_TAG})
162+
163+
FetchContent_GetProperties(hwloc_targ)
164+
if(NOT hwloc_targ_POPULATED)
165+
FetchContent_MakeAvailable(hwloc_targ)
166+
endif()
167+
168+
add_custom_command(
169+
COMMAND ./autogen.sh
170+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
171+
OUTPUT ${hwloc_targ_SOURCE_DIR}/configure)
172+
add_custom_command(
173+
COMMAND
174+
./configure --prefix=${hwloc_targ_BINARY_DIR}
175+
--enable-static=yes --enable-shared=no --disable-libxml2
176+
--disable-levelzero CFLAGS=-fPIC CXXFLAGS=-fPIC
177+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
178+
OUTPUT ${hwloc_targ_SOURCE_DIR}/Makefile
179+
DEPENDS ${hwloc_targ_SOURCE_DIR}/configure)
180+
add_custom_command(
181+
COMMAND make
182+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
183+
OUTPUT ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la
184+
DEPENDS ${hwloc_targ_SOURCE_DIR}/Makefile)
185+
add_custom_command(
186+
COMMAND make install
187+
WORKING_DIRECTORY ${hwloc_targ_SOURCE_DIR}
188+
OUTPUT ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a
189+
DEPENDS ${hwloc_targ_SOURCE_DIR}/lib/libhwloc.la)
190+
191+
add_custom_target(hwloc_prod
192+
DEPENDS ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
193+
add_library(hwloc INTERFACE)
194+
target_link_libraries(hwloc
195+
INTERFACE ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
196+
add_dependencies(hwloc hwloc_prod)
197+
198+
set(LIBHWLOC_LIBRARY_DIRS ${hwloc_targ_BINARY_DIR}/lib)
199+
set(LIBHWLOC_INCLUDE_DIRS ${hwloc_targ_BINARY_DIR}/include)
200+
set(LIBHWLOC_LIBRARIES ${hwloc_targ_BINARY_DIR}/lib/libhwloc.a)
201+
endif()
202202

203203
message(STATUS " LIBHWLOC_LIBRARIES = ${LIBHWLOC_LIBRARIES}")
204204
message(STATUS " LIBHWLOC_INCLUDE_DIRS = ${LIBHWLOC_INCLUDE_DIRS}")
@@ -289,8 +289,7 @@ if(UMF_BUILD_FUZZTESTS
289289
add_link_options("-fsanitize=fuzzer-no-link")
290290
endif()
291291

292-
# A header only library to specify include directories in transitive
293-
# dependencies.
292+
# A header-only lib to specify include directories in transitive dependencies
294293
add_library(umf_headers INTERFACE)
295294

296295
# Alias target to support FetchContent.
@@ -343,7 +342,6 @@ if(UMF_BUILD_LIBUMF_POOL_JEMALLOC)
343342
)
344343
endif()
345344

346-
# set UMF_PROXY_LIB_ENABLED
347345
if(WINDOWS)
348346
# TODO: enable the proxy library in the Debug build on Windows
349347
#
@@ -362,6 +360,7 @@ if(WINDOWS)
362360
)
363361
endif()
364362
endif()
363+
# set UMF_PROXY_LIB_ENABLED
365364
if(UMF_PROXY_LIB_BASED_ON_POOL STREQUAL SCALABLE)
366365
if(UMF_POOL_SCALABLE_ENABLED)
367366
set(UMF_PROXY_LIB_ENABLED ON)
@@ -391,10 +390,12 @@ else()
391390
)
392391
endif()
393392

393+
# set optional symbols for map/def files
394+
#
395+
# TODO: ref. #649
394396
set(UMF_OPTIONAL_SYMBOLS_LINUX "")
395397
set(UMF_OPTIONAL_SYMBOLS_WINDOWS "")
396398

397-
# Conditional configuration for Level Zero provider
398399
if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
399400
add_optional_symbol(umfLevelZeroMemoryProviderOps)
400401
endif()
@@ -413,12 +414,8 @@ if(UMF_BUILD_BENCHMARKS)
413414
add_subdirectory(benchmark)
414415
endif()
415416

416-
if(UMF_BUILD_EXAMPLES)
417-
if(NOT UMF_DISABLE_HWLOC)
418-
add_subdirectory(examples)
419-
else()
420-
message(WARNING "Examples cannot be build - hwloc disabled")
421-
endif()
417+
if(UMF_BUILD_EXAMPLES AND NOT UMF_DISABLE_HWLOC)
418+
add_subdirectory(examples)
422419
endif()
423420

424421
if(UMF_FORMAT_CODE_STYLE)
@@ -551,12 +548,12 @@ if(UMF_FORMAT_CODE_STYLE)
551548

552549
add_custom_target(
553550
black-format-check
554-
COMMAND ${BLACK} --check --verbose ${CMAKE_SOURCE_DIR}
551+
COMMAND ${BLACK} --check --verbose ${UMF_CMAKE_SOURCE_DIR}
555552
COMMENT "Check Python files formatting using black formatter")
556553

557554
add_custom_target(
558555
black-format-apply
559-
COMMAND ${BLACK} ${CMAKE_SOURCE_DIR}
556+
COMMAND ${BLACK} ${UMF_CMAKE_SOURCE_DIR}
560557
COMMENT "Format Python files using black formatter")
561558
endif()
562559

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ else()
128128
message(STATUS "UMF_OPTIONAL_SYMBOLS: ${UMF_OPTIONAL_SYMBOLS_LINUX}")
129129
endif()
130130

131-
# Configure the DEF file based on whether Level Zero provider is built
131+
# Configure map/def files with optional symbols
132132
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libumf.def.in"
133133
"${CMAKE_CURRENT_BINARY_DIR}/libumf.def" @ONLY)
134134

0 commit comments

Comments
 (0)