Skip to content

Commit a0eb6cb

Browse files
committed
fix linking with ze_loader and cuda
1 parent d2934a0 commit a0eb6cb

File tree

10 files changed

+240
-217
lines changed

10 files changed

+240
-217
lines changed

CMakeLists.txt

+81-59
Original file line numberDiff line numberDiff line change
@@ -390,60 +390,94 @@ if(hwloc_targ_SOURCE_DIR)
390390
endif()
391391
endif()
392392

393-
# Fetch L0 loader only if needed i.e.: if building L0 provider is ON and L0
394-
# headers are not provided by the user (via setting UMF_LEVEL_ZERO_INCLUDE_DIR).
395-
if(UMF_BUILD_LEVEL_ZERO_PROVIDER AND (NOT UMF_LEVEL_ZERO_INCLUDE_DIR))
396-
set(LEVEL_ZERO_LOADER_REPO "https://github.com/oneapi-src/level-zero.git")
397-
set(LEVEL_ZERO_LOADER_TAG v1.21.9)
398-
399-
message(
400-
STATUS
401-
"Fetching L0 loader (${LEVEL_ZERO_LOADER_TAG}) from ${LEVEL_ZERO_LOADER_REPO} ..."
402-
)
393+
if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
394+
if(UMF_BUILD_GPU_TESTS OR UMF_BUILD_GPU_EXAMPLES)
395+
# Level Zero loader library is required to build Level Zero GPU tests
396+
# and examples
397+
find_package(ZE_LOADER REQUIRED ze_loader)
398+
else()
399+
find_package(ZE_LOADER COMPONENTS ze_loader)
400+
endif()
403401

404-
FetchContent_Declare(
405-
level-zero-loader
406-
GIT_REPOSITORY ${LEVEL_ZERO_LOADER_REPO}
407-
GIT_TAG ${LEVEL_ZERO_LOADER_TAG}
408-
EXCLUDE_FROM_ALL)
409-
# Only populate the repo - we don't need to build it
410-
FetchContent_Populate(level-zero-loader)
411-
412-
set(LEVEL_ZERO_INCLUDE_DIRS
413-
${level-zero-loader_SOURCE_DIR}/include
414-
CACHE PATH "Path to Level Zero headers")
415-
message(STATUS "LEVEL_ZERO_INCLUDE_DIRS = ${LEVEL_ZERO_INCLUDE_DIRS}")
416-
elseif(UMF_BUILD_LEVEL_ZERO_PROVIDER)
417-
# Only header is needed to build UMF
418-
set(LEVEL_ZERO_INCLUDE_DIRS ${UMF_LEVEL_ZERO_INCLUDE_DIR})
402+
# If the Level Zero headers are not provided by the user and not found in
403+
# the system, we will fetch them from the repo
404+
if(UMF_LEVEL_ZERO_INCLUDE_DIR)
405+
set(LEVEL_ZERO_INCLUDE_DIRS ${UMF_LEVEL_ZERO_INCLUDE_DIR})
406+
elseif(ZE_LOADER_INCLUDE_DIR)
407+
set(LEVEL_ZERO_INCLUDE_DIRS ${ZE_LOADER_INCLUDE_DIR})
408+
else()
409+
set(LEVEL_ZERO_LOADER_REPO
410+
"https://github.com/oneapi-src/level-zero.git")
411+
set(LEVEL_ZERO_LOADER_TAG v1.21.9)
412+
413+
message(STATUS "Fetching Level Zero loader (${LEVEL_ZERO_LOADER_TAG}) "
414+
"from ${LEVEL_ZERO_LOADER_REPO} ...")
415+
FetchContent_Declare(
416+
level-zero-loader
417+
GIT_REPOSITORY ${LEVEL_ZERO_LOADER_REPO}
418+
GIT_TAG ${LEVEL_ZERO_LOADER_TAG}
419+
EXCLUDE_FROM_ALL)
420+
# Only populate the repo - we don't need to build it
421+
FetchContent_Populate(level-zero-loader)
422+
423+
set(LEVEL_ZERO_INCLUDE_DIRS
424+
${level-zero-loader_SOURCE_DIR}/include
425+
CACHE PATH "Path to Level Zero headers")
426+
endif()
419427
message(STATUS "LEVEL_ZERO_INCLUDE_DIRS = ${LEVEL_ZERO_INCLUDE_DIRS}")
428+
429+
if(ZE_LOADER_LIBRARIES)
430+
set(UMF_LEVEL_ZERO_ENABLED TRUE)
431+
else()
432+
message(
433+
STATUS
434+
"Disabling tests and examples that use the Level Zero Provider "
435+
"because the Level Zero libraries they require were not found.")
436+
endif()
420437
endif()
421438

422-
# Fetch CUDA only if needed i.e.: if building CUDA provider is ON and CUDA
423-
# headers are not provided by the user (via setting UMF_CUDA_INCLUDE_DIR).
424-
if(UMF_BUILD_CUDA_PROVIDER AND (NOT UMF_CUDA_INCLUDE_DIR))
425-
set(CUDA_REPO
426-
"https://gitlab.com/nvidia/headers/cuda-individual/cudart.git")
427-
set(CUDA_TAG cuda-12.5.1)
439+
if(UMF_BUILD_CUDA_PROVIDER)
440+
if(UMF_BUILD_GPU_TESTS OR UMF_BUILD_GPU_EXAMPLES)
441+
# CUDA library is required to build CUDA GPU tests and examples
442+
find_package(CUDA REQUIRED cuda)
443+
else()
444+
find_package(CUDA COMPONENTS cuda)
445+
endif()
428446

429-
message(STATUS "Fetching CUDA (${CUDA_TAG}) from ${CUDA_REPO} ...")
447+
# If the CUDA headers are not provided by the user and not found in the
448+
# system, we will fetch them from the repo
449+
if(UMF_CUDA_INCLUDE_DIR)
450+
set(CUDA_INCLUDE_DIRS ${UMF_CUDA_INCLUDE_DIR})
451+
elseif(CUDA_INCLUDE_DIR)
452+
set(CUDA_INCLUDE_DIRS ${CUDA_INCLUDE_DIR})
453+
else()
454+
set(CUDA_REPO
455+
"https://gitlab.com/nvidia/headers/cuda-individual/cudart.git")
456+
set(CUDA_TAG cuda-12.5.1)
430457

431-
FetchContent_Declare(
432-
cuda-headers
433-
GIT_REPOSITORY ${CUDA_REPO}
434-
GIT_TAG ${CUDA_TAG}
435-
EXCLUDE_FROM_ALL)
436-
# Only populate the repo - we don't need to build it
437-
FetchContent_Populate(cuda-headers)
438-
439-
set(CUDA_INCLUDE_DIRS
440-
${cuda-headers_SOURCE_DIR}
441-
CACHE PATH "Path to CUDA headers")
442-
message(STATUS "CUDA_INCLUDE_DIRS = ${CUDA_INCLUDE_DIRS}")
443-
elseif(UMF_BUILD_CUDA_PROVIDER)
444-
# Only header is needed to build UMF
445-
set(CUDA_INCLUDE_DIRS ${UMF_CUDA_INCLUDE_DIR})
458+
message(
459+
STATUS "Fetching CUDA (${CUDA_TAG}) headers from ${CUDA_REPO} ...")
460+
FetchContent_Declare(
461+
cuda-headers
462+
GIT_REPOSITORY ${CUDA_REPO}
463+
GIT_TAG ${CUDA_TAG}
464+
EXCLUDE_FROM_ALL)
465+
# Only populate the repo - we don't need to build it
466+
FetchContent_Populate(cuda-headers)
467+
468+
set(CUDA_INCLUDE_DIRS
469+
${cuda-headers_SOURCE_DIR}
470+
CACHE PATH "Path to CUDA headers")
471+
endif()
446472
message(STATUS "CUDA_INCLUDE_DIRS = ${CUDA_INCLUDE_DIRS}")
473+
474+
if(CUDA_LIBRARIES)
475+
set(UMF_CUDA_ENABLED TRUE)
476+
else()
477+
message(
478+
STATUS "Disabling tests and examples that use the CUDA Provider "
479+
"because the CUDA libraries they require were not found.")
480+
endif()
447481
endif()
448482

449483
# Build the umfd target in a separate directory with Debug configuration
@@ -711,18 +745,6 @@ else()
711745
)
712746
endif()
713747

714-
if((UMF_BUILD_GPU_TESTS OR UMF_BUILD_GPU_EXAMPLES) AND UMF_BUILD_CUDA_PROVIDER)
715-
find_package(CUDA REQUIRED cuda)
716-
if(CUDA_LIBRARIES)
717-
set(UMF_CUDA_ENABLED TRUE)
718-
else()
719-
message(
720-
STATUS "Disabling tests and examples that use the CUDA provider "
721-
"because the CUDA libraries they require were not found.")
722-
endif()
723-
# TODO do the same for ze_loader
724-
endif()
725-
726748
add_subdirectory(src)
727749

728750
if(UMF_BUILD_TESTS)

benchmark/CMakeLists.txt

+11-21
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ function(add_umf_benchmark)
6060
LIBS ${BENCH_LIBS})
6161

6262
target_include_directories(
63-
${BENCH_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include
64-
${UMF_CMAKE_SOURCE_DIR}/src/utils)
63+
${BENCH_NAME}
64+
PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include
65+
${UMF_CMAKE_SOURCE_DIR}/src/utils
66+
${UMF_CMAKE_SOURCE_DIR}/test/common)
6567

6668
target_link_directories(${BENCH_NAME} PRIVATE ${ARG_LIBDIRS})
6769

@@ -87,16 +89,6 @@ function(add_umf_benchmark)
8789
set_property(TEST ${BENCH_NAME} PROPERTY ENVIRONMENT_MODIFICATION
8890
"${DLL_PATH_LIST}")
8991
endif()
90-
if(LINUX)
91-
# prepend LD_LIBRARY_PATH with ${CMAKE_BINARY_DIR}/lib it is required
92-
# because ${CMAKE_BINARY_DIR}/lib contains libze_loader.so and tests
93-
# should use it instead of system one.
94-
set_property(
95-
TEST ${BENCH_NAME}
96-
PROPERTY ENVIRONMENT_MODIFICATION
97-
"LD_LIBRARY_PATH=path_list_prepend:${CMAKE_BINARY_DIR}/lib"
98-
)
99-
endif()
10092

10193
if(UMF_POOL_JEMALLOC_ENABLED)
10294
target_compile_definitions(${BENCH_NAME}
@@ -106,19 +98,16 @@ function(add_umf_benchmark)
10698
target_compile_definitions(${BENCH_NAME}
10799
PRIVATE UMF_POOL_SCALABLE_ENABLED=1)
108100
endif()
109-
if(UMF_BUILD_LEVEL_ZERO_PROVIDER)
101+
if(UMF_LEVEL_ZERO_ENABLED)
110102
target_compile_definitions(${BENCH_NAME}
111103
PRIVATE UMF_PROVIDER_LEVEL_ZERO_ENABLED=1)
112-
target_include_directories(
113-
${BENCH_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/test/common
114-
${LEVEL_ZERO_INCLUDE_DIRS})
104+
target_include_directories(${BENCH_NAME}
105+
PRIVATE ${LEVEL_ZERO_INCLUDE_DIRS})
115106
endif()
116-
if(UMF_BUILD_CUDA_PROVIDER)
107+
if(UMF_CUDA_ENABLED)
117108
target_compile_definitions(${BENCH_NAME}
118109
PRIVATE UMF_BUILD_CUDA_PROVIDER=1)
119-
target_include_directories(
120-
${BENCH_NAME} PRIVATE ${UMF_CMAKE_SOURCE_DIR}/test/common
121-
${CUDA_INCLUDE_DIRS})
110+
target_include_directories(${BENCH_NAME} PRIVATE ${CUDA_INCLUDE_DIRS})
122111
endif()
123112
if(UMF_BUILD_GPU_TESTS)
124113
target_compile_definitions(${BENCH_NAME} PRIVATE UMF_BUILD_GPU_TESTS=1)
@@ -131,8 +120,9 @@ set(LIB_DIRS ${LIBHWLOC_LIBRARY_DIRS})
131120
if(LINUX)
132121
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} m)
133122
endif()
134-
if(UMF_BUILD_GPU_TESTS AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
123+
if(UMF_BUILD_GPU_TESTS AND UMF_LEVEL_ZERO_ENABLED)
135124
set(SRCS_OPTIONAL ${SRCS_OPTIONAL} ../src/utils/utils_level_zero.cpp)
125+
set(LIB_DIRS ${LIB_DIRS} ${ZE_LOADER_LIBRARY_DIRS})
136126
set(LIBS_OPTIONAL ${LIBS_OPTIONAL} ze_loader)
137127
# TODO add CUDA
138128
endif()

cmake/FindCUDA.cmake

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2024 Intel Corporation
1+
# Copyright (C) 2024-2025 Intel Corporation
22
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
33
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
44

@@ -7,6 +7,10 @@ message(STATUS "Checking for module 'cuda' using find_library()")
77
find_library(CUDA_LIBRARY NAMES libcuda cuda)
88
set(CUDA_LIBRARIES ${CUDA_LIBRARY})
99

10+
find_file(CUDA_HEADER NAMES "cuda.h")
11+
get_filename_component(CUDA_INCLUDE_DIR ${CUDA_HEADER} DIRECTORY)
12+
set(CUDA_INCLUDE_DIRS ${CUDA_INCLUDE_DIR})
13+
1014
get_filename_component(CUDA_LIB_DIR ${CUDA_LIBRARIES} DIRECTORY)
1115
set(CUDA_LIBRARY_DIRS ${CUDA_LIB_DIR})
1216

cmake/FindZE_LOADER.cmake

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (C) 2025 Intel Corporation
2+
# Under the Apache License v2.0 with LLVM Exceptions. See LICENSE.TXT.
3+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
message(STATUS "Checking for module 'ze_loader' using find_library()")
6+
7+
find_library(ZE_LOADER_LIBRARY NAMES libze_loader ze_loader)
8+
set(ZE_LOADER_LIBRARIES ${ZE_LOADER_LIBRARY})
9+
10+
find_file(ZE_LOADER_HEADER NAMES "ze_api.h" "level_zero/ze_api.h")
11+
get_filename_component(ZE_LOADER_INCLUDE_DIR ${ZE_LOADER_HEADER} DIRECTORY)
12+
set(ZE_LOADER_INCLUDE_DIRS ${ZE_LOADER_INCLUDE_DIR})
13+
14+
get_filename_component(ZE_LOADER_LIB_DIR ${ZE_LOADER_LIBRARIES} DIRECTORY)
15+
set(ZE_LOADER_LIBRARY_DIRS ${ZE_LOADER_LIB_DIR})
16+
17+
if(WINDOWS)
18+
find_file(ZE_LOADER_DLL NAMES "ze_loader.dll")
19+
get_filename_component(ZE_LOADER_DLL_DIR ${ZE_LOADER_DLL} DIRECTORY)
20+
set(ZE_LOADER_DLL_DIRS ${ZE_LOADER_DLL_DIR})
21+
endif()
22+
23+
if(ZE_LOADER_LIBRARY)
24+
message(STATUS " Found ZE_LOADER using find_library()")
25+
message(STATUS " ZE_LOADER_LIBRARIES = ${ZE_LOADER_LIBRARIES}")
26+
message(STATUS " ZE_LOADER_INCLUDE_DIRS = ${ZE_LOADER_INCLUDE_DIRS}")
27+
message(STATUS " ZE_LOADER_LIBRARY_DIRS = ${ZE_LOADER_LIBRARY_DIRS}")
28+
if(WINDOWS)
29+
message(STATUS " ZE_LOADER_DLL_DIRS = ${ZE_LOADER_DLL_DIRS}")
30+
endif()
31+
else()
32+
set(MSG_NOT_FOUND "ZE_LOADER NOT found (set CMAKE_PREFIX_PATH to point the "
33+
"location)")
34+
if(ZE_LOADER_FIND_REQUIRED)
35+
message(FATAL_ERROR ${MSG_NOT_FOUND})
36+
else()
37+
message(WARNING ${MSG_NOT_FOUND})
38+
endif()
39+
endif()

examples/CMakeLists.txt

+7-27
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if(UMF_POOL_SCALABLE_ENABLED)
4141
endif()
4242
endif()
4343

44-
if(UMF_BUILD_GPU_EXAMPLES AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
44+
if(UMF_BUILD_GPU_EXAMPLES AND UMF_LEVEL_ZERO_ENABLED)
4545
set(EXAMPLE_NAME umf_example_level_zero_shared_memory)
4646

4747
add_umf_executable(
@@ -56,7 +56,8 @@ if(UMF_BUILD_GPU_EXAMPLES AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
5656
${UMF_CMAKE_SOURCE_DIR}/include
5757
${UMF_CMAKE_SOURCE_DIR}/examples/common)
5858

59-
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
59+
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS}
60+
${ZE_LOADER_LIBRARY_DIRS})
6061

6162
add_test(
6263
NAME ${EXAMPLE_NAME}
@@ -70,25 +71,13 @@ if(UMF_BUILD_GPU_EXAMPLES AND UMF_BUILD_LEVEL_ZERO_PROVIDER)
7071
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION
7172
"${DLL_PATH_LIST}")
7273
endif()
73-
if(LINUX)
74-
# prepend LD_LIBRARY_PATH with ${CMAKE_BINARY_DIR}/lib it is required
75-
# because ${CMAKE_BINARY_DIR}/lib contains libze_loader.so and tests
76-
# should use it instead of system one.
77-
set_property(
78-
TEST ${EXAMPLE_NAME}
79-
PROPERTY ENVIRONMENT_MODIFICATION
80-
"LD_LIBRARY_PATH=path_list_prepend:${CMAKE_BINARY_DIR}/lib"
81-
)
82-
endif()
8374
else()
8475
message(STATUS "GPU Level Zero shared memory example requires "
8576
"UMF_BUILD_GPU_EXAMPLES and UMF_BUILD_LEVEL_ZERO_PROVIDER "
8677
"to be turned ON - skipping")
8778
endif()
8879

89-
if(UMF_BUILD_GPU_EXAMPLES
90-
AND UMF_BUILD_CUDA_PROVIDER
91-
AND UMF_CUDA_ENABLED)
80+
if(UMF_BUILD_GPU_EXAMPLES AND UMF_CUDA_ENABLED)
9281
set(EXAMPLE_NAME umf_example_cuda_shared_memory)
9382

9483
add_umf_executable(
@@ -127,7 +116,7 @@ endif()
127116
# TODO: it looks like there is some problem with IPC implementation in Level
128117
# Zero on windows
129118
if(UMF_BUILD_GPU_EXAMPLES
130-
AND UMF_BUILD_LEVEL_ZERO_PROVIDER
119+
AND UMF_LEVEL_ZERO_ENABLED
131120
AND LINUX)
132121
set(EXAMPLE_NAME umf_example_ipc_level_zero)
133122

@@ -143,7 +132,8 @@ if(UMF_BUILD_GPU_EXAMPLES
143132
${UMF_CMAKE_SOURCE_DIR}/include
144133
${UMF_CMAKE_SOURCE_DIR}/examples/common)
145134

146-
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
135+
target_link_directories(${EXAMPLE_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS}
136+
${ZE_LOADER_LIBRARY_DIRS})
147137

148138
add_test(
149139
NAME ${EXAMPLE_NAME}
@@ -157,16 +147,6 @@ if(UMF_BUILD_GPU_EXAMPLES
157147
set_property(TEST ${EXAMPLE_NAME} PROPERTY ENVIRONMENT_MODIFICATION
158148
"${DLL_PATH_LIST}")
159149
endif()
160-
if(LINUX)
161-
# prepend LD_LIBRARY_PATH with ${CMAKE_BINARY_DIR}/lib it is required
162-
# because ${CMAKE_BINARY_DIR}/lib contains libze_loader.so and tests
163-
# should use it instead of system one.
164-
set_property(
165-
TEST ${EXAMPLE_NAME}
166-
PROPERTY ENVIRONMENT_MODIFICATION
167-
"LD_LIBRARY_PATH=path_list_prepend:${CMAKE_BINARY_DIR}/lib"
168-
)
169-
endif()
170150
else()
171151
message(
172152
STATUS

0 commit comments

Comments
 (0)