Skip to content

Commit 9daa5a7

Browse files
introduce usage of FETCHCONTENT_SOURCE_DIR_<name> for UR
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent 918ba92 commit 9daa5a7

File tree

1 file changed

+30
-122
lines changed

1 file changed

+30
-122
lines changed

libsycl/cmake/Modules/FetchUnifiedRuntime.cmake

Lines changed: 30 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,12 @@
88
#
99
#===============================================================================
1010

11-
# Options to override the default behaviour of the FetchContent to include UR
12-
# source code.
13-
set(LIBSYCL_UR_OVERRIDE_FETCH_CONTENT_REPO
14-
"" CACHE STRING "Override the Unified Runtime FetchContent repository")
15-
set(LIBSYCL_UR_OVERRIDE_FETCH_CONTENT_TAG
16-
"" CACHE STRING "Override the Unified Runtime FetchContent tag")
17-
18-
# Options to disable use of FetchContent to include Unified Runtime source code
19-
# to improve developer workflow.
20-
option(LIBSYCL_UR_USE_FETCH_CONTENT
21-
"Use FetchContent to acquire the Unified Runtime source code" ON)
22-
set(LIBSYCL_UR_SOURCE_DIR
23-
"" CACHE PATH "Path to root of Unified Runtime repository")
24-
2511
option(LIBSYCL_UR_BUILD_TESTS "Build tests for UR" OFF)
12+
2613
set(UR_BUILD_TESTS "${LIBSYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE)
2714
# UR tests require the examples to be built
2815
set(UR_BUILD_EXAMPLES "${LIBSYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE)
2916

30-
set(UR_EXTERNAL_DEPENDENCIES "sycl-headers" CACHE STRING
31-
"List of external CMake targets for executables/libraries to depend on" FORCE)
32-
3317
if("level_zero" IN_LIST LIBSYCL_ENABLE_BACKENDS)
3418
set(UR_BUILD_ADAPTER_L0 ON)
3519
endif()
@@ -57,118 +41,42 @@ else()
5741
append("-Wno-error" CMAKE_C_FLAGS)
5842
endif()
5943

60-
if(LIBSYCL_UR_USE_FETCH_CONTENT)
61-
include(FetchContent)
62-
63-
# The fetch_adapter_source function can be used to perform a separate content
64-
# fetch for a UR adapter (backend), this allows development of adapters to be decoupled
65-
# from each other.
66-
#
67-
# A separate content fetch will not be performed if:
68-
# * The adapter name is not present in the LIBSYCL_ENABLE_BACKENDS variable.
69-
# * The repo and tag provided match the values of the
70-
# UNIFIED_RUNTIME_REPO/UNIFIED_RUNTIME_TAG variables
71-
#
72-
# Args:
73-
# * name - Must be the directory name of the adapter
74-
# * repo - A valid Git URL of a Unified Runtime repo
75-
# * tag - A valid Git branch/tag/commit in the Unified Runtime repo
76-
function(fetch_adapter_source name repo tag)
77-
if(NOT ${name} IN_LIST LIBSYCL_ENABLE_BACKENDS)
78-
return()
79-
endif()
80-
if(repo STREQUAL UNIFIED_RUNTIME_REPO AND
81-
tag STREQUAL UNIFIED_RUNTIME_TAG)
82-
# If the adapter sources are taken from the main checkout, reset the
83-
# adapter specific source path.
84-
string(TOUPPER ${name} NAME)
85-
set(UR_ADAPTER_${NAME}_SOURCE_DIR ""
86-
CACHE PATH "Path to external '${name}' adapter source dir" FORCE)
87-
return()
88-
endif()
89-
message(STATUS
90-
"Will fetch Unified Runtime ${name} adapter from ${repo} at ${tag}")
91-
set(fetch-name ur-${name})
92-
FetchContent_Declare(${fetch-name}
93-
GIT_REPOSITORY ${repo} GIT_TAG ${tag})
94-
# We don't want to add this repo to the build, only fetch its source.
95-
FetchContent_Populate(${fetch-name})
96-
# Get the path to the source directory
97-
string(TOUPPER ${name} NAME)
98-
set(source_dir_var UR_ADAPTER_${NAME}_SOURCE_DIR)
99-
FetchContent_GetProperties(${fetch-name} SOURCE_DIR UR_ADAPTER_${NAME}_SOURCE_DIR)
100-
# Set the variable which informs UR where to get the adapter source from.
101-
set(UR_ADAPTER_${NAME}_SOURCE_DIR
102-
"${UR_ADAPTER_${NAME}_SOURCE_DIR}/source/adapters/${name}"
103-
CACHE PATH "Path to external '${name}' adapter source dir" FORCE)
104-
endfunction()
105-
106-
set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git")
107-
set(UNIFIED_RUNTIME_TAG 851ee6a2bb5f5c34c6e48a00e0b06255044e0f03)
108-
109-
set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "EXAMPLES")
110-
# Due to the use of dependentloadflag and no installer for UMF and hwloc we need
111-
# to link statically on windows
112-
if(WIN32)
113-
set(UMF_BUILD_SHARED_LIBRARY OFF CACHE INTERNAL "Build UMF shared library")
114-
set(UMF_LINK_HWLOC_STATICALLY ON CACHE INTERNAL "static HWLOC")
44+
if(NOT FETCHCONTENT_SOURCE_DIR_UNIFIED-RUNTIME)
45+
find_package(unified-runtime)
46+
if(unified-runtime_FOUND)
47+
message ("STATUS: unified-runtime is found")
48+
return()
11549
endif()
50+
endif()
11651

117-
fetch_adapter_source(level_zero
118-
${UNIFIED_RUNTIME_REPO}
119-
${UNIFIED_RUNTIME_TAG}
120-
)
121-
122-
fetch_adapter_source(opencl
123-
${UNIFIED_RUNTIME_REPO}
124-
${UNIFIED_RUNTIME_TAG}
125-
)
126-
127-
fetch_adapter_source(cuda
128-
${UNIFIED_RUNTIME_REPO}
129-
${UNIFIED_RUNTIME_TAG}
130-
)
52+
include(FetchContent)
13153

132-
fetch_adapter_source(hip
133-
${UNIFIED_RUNTIME_REPO}
134-
${UNIFIED_RUNTIME_TAG}
135-
)
54+
set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git")
55+
set(UNIFIED_RUNTIME_TAG 851ee6a2bb5f5c34c6e48a00e0b06255044e0f03)
13656

137-
if(LIBSYCL_UR_OVERRIDE_FETCH_CONTENT_REPO)
138-
set(UNIFIED_RUNTIME_REPO "${LIBSYCL_UR_OVERRIDE_FETCH_CONTENT_REPO}")
139-
endif()
140-
if(LIBSYCL_UR_OVERRIDE_FETCH_CONTENT_TAG)
141-
set(UNIFIED_RUNTIME_TAG "${LIBSYCL_UR_OVERRIDE_FETCH_CONTENT_TAG}")
142-
endif()
57+
FetchContent_Declare(unified-runtime
58+
GIT_REPOSITORY ${UNIFIED_RUNTIME_REPO}
59+
GIT_TAG ${UNIFIED_RUNTIME_TAG}
60+
)
14361

144-
message(STATUS "Will fetch Unified Runtime from ${UNIFIED_RUNTIME_REPO}")
145-
FetchContent_Declare(unified-runtime
146-
GIT_REPOSITORY ${UNIFIED_RUNTIME_REPO}
147-
GIT_TAG ${UNIFIED_RUNTIME_TAG}
148-
)
149-
150-
FetchContent_GetProperties(unified-runtime)
151-
FetchContent_MakeAvailable(unified-runtime)
152-
153-
set(UNIFIED_RUNTIME_SOURCE_DIR
154-
"${unified-runtime_SOURCE_DIR}" CACHE PATH
155-
"Path to Unified Runtime Headers" FORCE)
156-
elseif(LIBSYCL_UR_SOURCE_DIR)
157-
# LIBSYCL_UR_USE_FETCH_CONTENT is OFF and LIBSYCL_UR_SOURCE_DIR has been set,
158-
# use the external Unified Runtime source directory.
159-
set(UNIFIED_RUNTIME_SOURCE_DIR
160-
"${LIBSYCL_UR_SOURCE_DIR}" CACHE PATH
161-
"Path to Unified Runtime Headers" FORCE)
162-
add_subdirectory(
163-
${UNIFIED_RUNTIME_SOURCE_DIR}
164-
${CMAKE_CURRENT_BINARY_DIR}/unified-runtime)
62+
FetchContent_GetProperties(unified-runtime)
63+
if(FETCHCONTENT_SOURCE_DIR_UNIFIED-RUNTIME)
64+
message(STATUS "Using specified Unified Runtime repo location at ${FETCHCONTENT_SOURCE_DIR_UNIFIED-RUNTIME}")
16565
else()
166-
message(FATAL_ERROR
167-
"LIBSYCL_UR_USE_FETCH_CONTENT is disabled but no alternative Unified \
168-
Runtime source directory has been provided, either:
66+
message(STATUS "Cloning Unified Runtime from ${UNIFIED_RUNTIME_REPO}")
67+
endif()
68+
FetchContent_MakeAvailable(unified-runtime)
69+
70+
set(UNIFIED_RUNTIME_SOURCE_DIR
71+
"${unified-runtime_SOURCE_DIR}" CACHE PATH
72+
"Path to Unified Runtime Headers" FORCE)
16973

170-
* Set -DLIBSYCL_UR_SOURCE_DIR=/path/to/unified-runtime
171-
* Clone the UR repo in ${CMAKE_CURRENT_SOURCE_DIR}/unified-runtime")
74+
set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "EXAMPLES")
75+
# Due to the use of dependentloadflag and no installer for UMF and hwloc we need
76+
# to link statically on windows
77+
if(WIN32)
78+
set(UMF_BUILD_SHARED_LIBRARY OFF CACHE INTERNAL "Build UMF shared library")
79+
set(UMF_LINK_HWLOC_STATICALLY ON CACHE INTERNAL "static HWLOC")
17280
endif()
17381

17482
# Restore original flags

0 commit comments

Comments
 (0)