Skip to content

Commit cbd4127

Browse files
Add UR dependency
Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent e502190 commit cbd4127

File tree

8 files changed

+369
-6
lines changed

8 files changed

+369
-6
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This file defines pre-commit CI for libsycl++.
2+
name: Build libsycl
3+
on:
4+
pull_request:
5+
paths:
6+
- 'libsycl/**'
7+
- '.github/workflows/libsycl-build-and-test.yaml'
8+
9+
permissions:
10+
contents: read # Default everything to read-only
11+
12+
concurrency:
13+
# Cancel a currently running workflow from the same PR
14+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
15+
cancel-in-progress: true
16+
17+
jobs:
18+
build_ubuntu2204:
19+
# sergey-semenov repo is set is for test purposes
20+
if: github.repository_owner == 'sergey-semenov'
21+
# github runner
22+
runs-on: ubuntu-22.04
23+
# reuse libcxx container for now
24+
container: ghcr.io/llvm/libcxx-linux-builder:2b57ebb50b6d418e70382e655feaa619b558e254
25+
continue-on-error: false
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Register cleanup after job is finished
29+
uses: ./libsycl/utils/ci/actions/cleanup
30+
- name: Compile
31+
env:
32+
CC: 'clang-21'
33+
CXX: 'clang++-21'
34+
run: |
35+
mkdir -p $GITHUB_WORKSPACE/build
36+
mkdir -p $GITHUB_WORKSPACE/install
37+
cmake -G Ninja -S $GITHUB_WORKSPACE/llvm -B $GITHUB_WORKSPACE/build \
38+
-DLLVM_ENABLE_PROJECTS="clang" \
39+
-DLLVM_INSTALL_UTILS=ON \
40+
-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install \
41+
-DLLVM_ENABLE_RUNTIMES="libsycl" \
42+
-DCMAKE_BUILD_TYPE=Release
43+
ninja -C $GITHUB_WORKSPACE/build install --verbose

libsycl/CMakeLists.txt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ endif()
3131
option(LIBSYCL_ENABLE_WERROR "Treat all warnings as errors in the libsycl project" OFF)
3232
option(LIBSYCL_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
3333

34+
# If LIBSYCL_ENABLE_BACKENDS is undefined, we default to enabling OpenCL and Level
35+
# Zero backends.
36+
if (NOT DEFINED LIBSYCL_ENABLE_BACKENDS)
37+
set(LIBSYCL_ENABLE_BACKENDS "opencl;level_zero" CACHE STRING "Backends enabled for SYCL")
38+
endif()
39+
3440
#===============================================================================
3541
# Configure System
3642
#===============================================================================
@@ -77,6 +83,14 @@ if (NOT LIBSYCL_ABI_NAMESPACE MATCHES "__V.*")
7783
message(FATAL_ERROR "LIBSYCL_ABI_NAMESPACE must be a reserved identifier, got '${LIBSYCL_ABI_NAMESPACE}'.")
7884
endif()
7985

86+
#===============================================================================
87+
# Dependencies
88+
#===============================================================================
89+
90+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
91+
# Download & build dependency for kernel offloading
92+
include(FetchUnifiedRuntime)
93+
8094
#===============================================================================
8195
# Setup build & install rules
8296
#===============================================================================
@@ -97,17 +111,36 @@ file(GLOB_RECURSE HEADERS_IN_SYCL_DIR CONFIGURE_DEPENDS "${LIBSYCL_SOURCE_INCLUD
97111
string(REPLACE "${LIBSYCL_SOURCE_INCLUDE_DIR}" "${LIBSYCL_BUILD_INCLUDE_DIR}"
98112
OUT_HEADERS_IN_SYCL_DIR "${HEADERS_IN_SYCL_DIR}")
99113

114+
set(OUT_UR_HEADERS
115+
${LIBSYCL_BUILD_INCLUDE_DIR}/ur_api.h
116+
${LIBSYCL_BUILD_INCLUDE_DIR}/ur_api_funcs.def
117+
${LIBSYCL_BUILD_INCLUDE_DIR}/ur_print.hpp)
118+
set(UR_HEADERS_TO_COPY
119+
${UNIFIED_RUNTIME_INCLUDE_DIR}/ur_api.h
120+
${UNIFIED_RUNTIME_INCLUDE_DIR}/ur_api_funcs.def
121+
${UNIFIED_RUNTIME_INCLUDE_DIR}/ur_print.hpp)
122+
100123
# Copy SYCL headers from sources to build directory
101124
add_custom_target(sycl-headers
102-
DEPENDS ${OUT_HEADERS_IN_SYCL_DIR})
125+
DEPENDS ${OUT_HEADERS_IN_SYCL_DIR}
126+
${OUT_UR_HEADERS})
103127

104128
add_custom_command(
105129
OUTPUT ${OUT_HEADERS_IN_SYCL_DIR}
130+
${OUT_UR_HEADERS}
106131
DEPENDS ${HEADERS_IN_SYCL_DIR}
132+
${UR_HEADERS_TO_COPY}
107133
COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBSYCL_SOURCE_INCLUDE_DIR}/sycl ${LIBSYCL_BUILD_INCLUDE_DIR}/sycl
134+
COMMAND ${CMAKE_COMMAND} -E copy ${UR_HEADERS_TO_COPY} ${LIBSYCL_BUILD_INCLUDE_DIR}
108135
COMMENT "Copying SYCL headers...")
109136

110137
install(DIRECTORY "${LIBSYCL_SOURCE_INCLUDE_DIR}/sycl" DESTINATION ${LIBSYCL_INCLUDE_DIR} COMPONENT sycl-headers)
138+
install(FILES "${UNIFIED_RUNTIME_INCLUDE_DIR}/ur_api.h" DESTINATION ${LIBSYCL_INCLUDE_DIR}
139+
COMPONENT sycl-headers)
140+
install(FILES "${UNIFIED_RUNTIME_INCLUDE_DIR}/ur_api_funcs.def" DESTINATION ${LIBSYCL_INCLUDE_DIR}
141+
COMPONENT sycl-headers)
142+
install(FILES "${UNIFIED_RUNTIME_INCLUDE_DIR}/ur_print.hpp" DESTINATION ${LIBSYCL_INCLUDE_DIR}
143+
COMPONENT sycl-headers)
111144

112145
set(LIBSYCL_RT_LIBS ${LIBSYCL_SHARED_OUTPUT_NAME})
113146

Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
#===============================================================================
2+
# Fetches Unified Runtime used by SYCL language runtime to abstract SYCL open
3+
# standard and vendor heterogeneous offload interfaces.
4+
#
5+
# This will in time be replaced by the new LLVM Offload interface.
6+
#
7+
# Unified Runtime is Apache 2.0 license with LLVM exceptions.
8+
#
9+
#===============================================================================
10+
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+
25+
option(LIBSYCL_UR_BUILD_TESTS "Build tests for UR" OFF)
26+
set(UR_BUILD_TESTS "${LIBSYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE)
27+
# UR tests require the examples to be built
28+
set(UR_BUILD_EXAMPLES "${LIBSYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE)
29+
30+
set(UR_EXTERNAL_DEPENDENCIES "sycl-headers" CACHE STRING
31+
"List of external CMake targets for executables/libraries to depend on" FORCE)
32+
33+
if("level_zero" IN_LIST LIBSYCL_ENABLE_BACKENDS)
34+
set(UR_BUILD_ADAPTER_L0 ON)
35+
endif()
36+
if("cuda" IN_LIST LIBSYCL_ENABLE_BACKENDS)
37+
set(UR_BUILD_ADAPTER_CUDA ON)
38+
endif()
39+
if("hip" IN_LIST LIBSYCL_ENABLE_BACKENDS)
40+
set(UR_BUILD_ADAPTER_HIP ON)
41+
endif()
42+
if("opencl" IN_LIST LIBSYCL_ENABLE_BACKENDS)
43+
set(UR_BUILD_ADAPTER_OPENCL ON)
44+
endif()
45+
46+
# Disable errors from warnings while building the UR.
47+
# And remember origin flags before doing that.
48+
set(CMAKE_CXX_FLAGS_BAK "${CMAKE_CXX_FLAGS}")
49+
if(WIN32)
50+
append("/WX-" CMAKE_CXX_FLAGS)
51+
append("/WX-" CMAKE_C_FLAGS)
52+
# Unified runtime build fails with /DUNICODE
53+
append("/UUNICODE" CMAKE_CXX_FLAGS)
54+
append("/UUNICODE" CMAKE_C_FLAGS)
55+
else()
56+
append("-Wno-error" CMAKE_CXX_FLAGS)
57+
append("-Wno-error" CMAKE_C_FLAGS)
58+
endif()
59+
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")
115+
endif()
116+
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+
)
131+
132+
fetch_adapter_source(hip
133+
${UNIFIED_RUNTIME_REPO}
134+
${UNIFIED_RUNTIME_TAG}
135+
)
136+
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()
143+
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)
165+
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:
169+
170+
* Set -DLIBSYCL_UR_SOURCE_DIR=/path/to/unified-runtime
171+
* Clone the UR repo in ${CMAKE_CURRENT_SOURCE_DIR}/unified-runtime")
172+
endif()
173+
174+
# Restore original flags
175+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BAK}")
176+
177+
message(STATUS
178+
"Using Unified Runtime source directory: ${UNIFIED_RUNTIME_SOURCE_DIR}")
179+
180+
set(UNIFIED_RUNTIME_INCLUDE_DIR "${UNIFIED_RUNTIME_SOURCE_DIR}/include")
181+
set(UNIFIED_RUNTIME_SRC_INCLUDE_DIR "${UNIFIED_RUNTIME_SOURCE_DIR}/source")
182+
set(UNIFIED_RUNTIME_COMMON_INCLUDE_DIR "${UNIFIED_RUNTIME_SOURCE_DIR}/source/common")
183+
184+
add_library(UnifiedRuntimeLoader ALIAS ur_loader)
185+
add_library(UnifiedRuntimeCommon ALIAS ur_common)
186+
add_library(UnifiedMemoryFramework ALIAS ur_umf)
187+
188+
add_library(UnifiedRuntime-Headers INTERFACE)
189+
190+
target_include_directories(UnifiedRuntime-Headers
191+
INTERFACE
192+
"${UNIFIED_RUNTIME_INCLUDE_DIR}"
193+
)
194+
195+
find_package(Threads REQUIRED)
196+
197+
if(TARGET UnifiedRuntimeLoader)
198+
# Install the UR loader.
199+
install(TARGETS ur_loader
200+
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT unified-runtime-loader
201+
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT unified-runtime-loader
202+
RUNTIME DESTINATION "bin" COMPONENT unified-runtime-loader
203+
)
204+
endif()
205+
206+
add_custom_target(UnifiedRuntimeAdapters)
207+
208+
function(add_sycl_ur_adapter NAME)
209+
add_dependencies(UnifiedRuntimeAdapters ur_adapter_${NAME})
210+
211+
install(TARGETS ur_adapter_${NAME}
212+
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT ur_adapter_${NAME}
213+
RUNTIME DESTINATION "bin" COMPONENT ur_adapter_${NAME})
214+
215+
set(manifest_file
216+
${CMAKE_CURRENT_BINARY_DIR}/install_manifest_ur_adapter_${NAME}.txt)
217+
add_custom_command(OUTPUT ${manifest_file}
218+
COMMAND "${CMAKE_COMMAND}"
219+
"-DCMAKE_INSTALL_COMPONENT=ur_adapter_${NAME}"
220+
-P "${CMAKE_BINARY_DIR}/cmake_install.cmake"
221+
COMMENT "Deploying component ur_adapter_${NAME}"
222+
USES_TERMINAL
223+
)
224+
add_custom_target(install-sycl-ur-adapter-${NAME}
225+
DEPENDS ${manifest_file} ur_adapter_${NAME}
226+
)
227+
endfunction()
228+
229+
if("level_zero" IN_LIST LIBSYCL_ENABLE_BACKENDS)
230+
add_sycl_ur_adapter(level_zero)
231+
endif()
232+
233+
if("cuda" IN_LIST LIBSYCL_ENABLE_BACKENDS)
234+
add_sycl_ur_adapter(cuda)
235+
endif()
236+
237+
if("hip" IN_LIST LIBSYCL_ENABLE_BACKENDS)
238+
add_sycl_ur_adapter(hip)
239+
endif()
240+
241+
if("opencl" IN_LIST LIBSYCL_ENABLE_BACKENDS)
242+
add_sycl_ur_adapter(opencl)
243+
endif()
244+
245+
install(TARGETS umf
246+
LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT unified-memory-framework
247+
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}" COMPONENT unified-memory-framework
248+
RUNTIME DESTINATION "bin" COMPONENT unified-memory-framework)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=====================
2+
Unified Runtime
3+
=====================
4+
5+
.. contents::
6+
:local:
7+
8+
.. _unified runtime:
9+
10+
The Unified Runtime (UR) project serves as an interface layer between the SYCL
11+
runtime and the device-specific runtime layers which control execution on
12+
devices. The parts of it primarily utilized by SYCL RT are its C API, loader
13+
library, and the adapter libraries that implement the API for various backends.
14+
15+
The SYCL runtime accesses the UR API via the Adapter object. Each Adapter
16+
object owns a ur_adapter_handle_t, which represents a UR backend (e.g. OpenCL,
17+
Level Zero, etc).
18+
19+
For detailed information about the UR project including
20+
the API specification see the `Unified Runtime Documentation
21+
<https://oneapi-src.github.io/unified-runtime/core/INTRO.html>`__. You
22+
can find the Unified Runtime repo `here
23+
<https://github.com/oneapi-src/unified-runtime>`__.

0 commit comments

Comments
 (0)