Skip to content

Commit e742c7d

Browse files
[SYCL] Add dependency on interface layer for offloading
The SYCL runtime is device-agnostic and uses Unified Runtime (GitHub - oneapi-src/unified-runtime) as an external dependency. This Unified Runtime serves as an interface layer between the SYCL runtime and device-specific backends. Unified Runtime has several adapters that bind to various backends. NOTE: UR is considered as temporal solution until llvm-project/offload is fully functional and is able to replace UR. Signed-off-by: Tikhomirova, Kseniya <[email protected]>
1 parent 8bab6c4 commit e742c7d

File tree

5 files changed

+207
-5
lines changed

5 files changed

+207
-5
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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: Compile
29+
env:
30+
CC: 'clang-21'
31+
CXX: 'clang++-21'
32+
run: |
33+
mkdir -p $GITHUB_WORKSPACE/build
34+
mkdir -p $GITHUB_WORKSPACE/install
35+
cmake -G Ninja -S $GITHUB_WORKSPACE/runtimes -B $GITHUB_WORKSPACE/build \
36+
-DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/install \
37+
-DLLVM_ENABLE_RUNTIMES="libsycl" \
38+
-DCMAKE_BUILD_TYPE=Release
39+
ninja -C $GITHUB_WORKSPACE/build install --verbose

libsycl/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
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
#===============================================================================
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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+
option(LIBSYCL_UR_BUILD_TESTS "Build tests for UR" OFF)
12+
13+
set(UR_BUILD_TESTS "${LIBSYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE)
14+
# UR tests require the examples to be built
15+
set(UR_BUILD_EXAMPLES "${LIBSYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE)
16+
17+
if("level_zero" IN_LIST LIBSYCL_ENABLE_BACKENDS)
18+
set(UR_BUILD_ADAPTER_L0 ON)
19+
endif()
20+
if("cuda" IN_LIST LIBSYCL_ENABLE_BACKENDS)
21+
set(UR_BUILD_ADAPTER_CUDA ON)
22+
endif()
23+
if("hip" IN_LIST LIBSYCL_ENABLE_BACKENDS)
24+
set(UR_BUILD_ADAPTER_HIP ON)
25+
endif()
26+
if("opencl" IN_LIST LIBSYCL_ENABLE_BACKENDS)
27+
set(UR_BUILD_ADAPTER_OPENCL ON)
28+
endif()
29+
30+
# Disable errors from warnings while building the UR.
31+
# And remember the original flags before doing that.
32+
set(CMAKE_CXX_FLAGS_BAK "${CMAKE_CXX_FLAGS}")
33+
if(WIN32)
34+
append("/WX-" CMAKE_CXX_FLAGS)
35+
append("/WX-" CMAKE_C_FLAGS)
36+
# Unified runtime build fails with /DUNICODE
37+
append("/UUNICODE" CMAKE_CXX_FLAGS)
38+
append("/UUNICODE" CMAKE_C_FLAGS)
39+
append("/EHsc" CMAKE_CXX_FLAGS)
40+
append("/EHsc" CMAKE_C_FLAGS)
41+
else()
42+
append("-Wno-error" CMAKE_CXX_FLAGS)
43+
append("-Wno-error" CMAKE_C_FLAGS)
44+
endif()
45+
46+
if(NOT FETCHCONTENT_SOURCE_DIR_UNIFIED-RUNTIME)
47+
find_package(unified-runtime)
48+
if(unified-runtime_FOUND)
49+
message (STATUS "Found system install of unified-runtime")
50+
return()
51+
endif()
52+
endif()
53+
54+
include(FetchContent)
55+
56+
set(UNIFIED_RUNTIME_REPO "https://github.com/oneapi-src/unified-runtime.git")
57+
set(UNIFIED_RUNTIME_TAG 8ee4da175c197d4dc5c9ec939e7e4d87d4edfa99)
58+
59+
FetchContent_Declare(unified-runtime
60+
GIT_REPOSITORY ${UNIFIED_RUNTIME_REPO}
61+
GIT_TAG ${UNIFIED_RUNTIME_TAG}
62+
)
63+
64+
FetchContent_GetProperties(unified-runtime)
65+
if(FETCHCONTENT_SOURCE_DIR_UNIFIED-RUNTIME)
66+
message(STATUS "Using specified Unified Runtime repo location at ${FETCHCONTENT_SOURCE_DIR_UNIFIED-RUNTIME}")
67+
else()
68+
message(STATUS "Cloning Unified Runtime from ${UNIFIED_RUNTIME_REPO}")
69+
endif()
70+
FetchContent_MakeAvailable(unified-runtime)
71+
72+
set(UNIFIED_RUNTIME_SOURCE_DIR
73+
"${unified-runtime_SOURCE_DIR}" CACHE PATH
74+
"Path to Unified Runtime Headers" FORCE)
75+
76+
set(UMF_BUILD_EXAMPLES OFF CACHE INTERNAL "UMF EXAMPLES")
77+
# Due to the use of dependentloadflag and no installer for UMF and hwloc we need
78+
# to link statically on windows
79+
if(WIN32)
80+
set(UMF_BUILD_SHARED_LIBRARY OFF CACHE INTERNAL "Build UMF shared library")
81+
set(UMF_LINK_HWLOC_STATICALLY ON CACHE INTERNAL "static HWLOC")
82+
endif()
83+
84+
# Restore original flags
85+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_BAK}")
86+
87+
message(STATUS
88+
"Using Unified Runtime source directory: ${UNIFIED_RUNTIME_SOURCE_DIR}")
89+
90+
set(UNIFIED_RUNTIME_INCLUDE_DIR "${UNIFIED_RUNTIME_SOURCE_DIR}/include")
91+
set(UNIFIED_RUNTIME_SRC_INCLUDE_DIR "${UNIFIED_RUNTIME_SOURCE_DIR}/source")
92+
set(UNIFIED_RUNTIME_COMMON_INCLUDE_DIR "${UNIFIED_RUNTIME_SOURCE_DIR}/source/common")
93+
94+
add_library(UnifiedRuntimeLoader ALIAS ur_loader)
95+
add_library(UnifiedRuntime-Headers INTERFACE)
96+
97+
target_include_directories(UnifiedRuntime-Headers
98+
INTERFACE
99+
"${UNIFIED_RUNTIME_INCLUDE_DIR}"
100+
)
101+
102+
add_custom_target(UnifiedRuntimeAdapters)
103+
104+
function(add_sycl_ur_adapter NAME)
105+
add_dependencies(UnifiedRuntimeAdapters ur_adapter_${NAME})
106+
endfunction()
107+
108+
if("level_zero" IN_LIST LIBSYCL_ENABLE_BACKENDS)
109+
add_sycl_ur_adapter(level_zero)
110+
endif()
111+
112+
if("cuda" IN_LIST LIBSYCL_ENABLE_BACKENDS)
113+
add_sycl_ur_adapter(cuda)
114+
endif()
115+
116+
if("hip" IN_LIST LIBSYCL_ENABLE_BACKENDS)
117+
add_sycl_ur_adapter(hip)
118+
endif()
119+
120+
if("opencl" IN_LIST LIBSYCL_ENABLE_BACKENDS)
121+
add_sycl_ur_adapter(opencl)
122+
endif()
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. SYCL RT utilizes its C API, loader library, and the adapter libraries
13+
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>`__.

libsycl/src/CMakeLists.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../runtimes/cmake/
22
include(WarningFlags)
33

44
function(add_sycl_rt_library LIB_TARGET_NAME LIB_OBJ_NAME LIB_OUTPUT_NAME)
5-
if (NOT LLVM_ENABLE_PIC)
6-
message( FATAL_ERROR "Position-Independent Code generation is required for libsycl shared library" )
7-
endif()
8-
95
cmake_parse_arguments(ARG "" "" "COMPILE_OPTIONS;SOURCES" ${ARGN})
106

117
add_library(${LIB_OBJ_NAME} OBJECT ${ARG_SOURCES})
@@ -22,6 +18,13 @@ function(add_sycl_rt_library LIB_TARGET_NAME LIB_OBJ_NAME LIB_OUTPUT_NAME)
2218
${LIBSYCL_BUILD_INCLUDE_DIR}
2319
)
2420

21+
# Object libraries are not linked, so these "libraries" are in fact include
22+
# directories
23+
target_link_libraries(${LIB_OBJ_NAME}
24+
PRIVATE
25+
UnifiedRuntime-Headers
26+
)
27+
2528
add_library(${LIB_TARGET_NAME} SHARED
2629
$<TARGET_OBJECTS:${LIB_OBJ_NAME}>)
2730

@@ -49,7 +52,7 @@ function(add_sycl_rt_library LIB_TARGET_NAME LIB_OBJ_NAME LIB_OUTPUT_NAME)
4952
target_compile_options(${LIB_OBJ_NAME} PUBLIC /EHsc)
5053
else()
5154
target_compile_options(${LIB_OBJ_NAME} PUBLIC
52-
-fvisibility=hidden -fvisibility-inlines-hidden)
55+
-fvisibility=hidden -fvisibility-inlines-hidden -fPIC)
5356

5457
if (UNIX AND NOT APPLE)
5558
set(linker_script "${CMAKE_CURRENT_SOURCE_DIR}/ld-version-script.txt")
@@ -65,6 +68,7 @@ function(add_sycl_rt_library LIB_TARGET_NAME LIB_OBJ_NAME LIB_OUTPUT_NAME)
6568
PRIVATE
6669
${CMAKE_DL_LIBS}
6770
${CMAKE_THREAD_LIBS_INIT}
71+
UnifiedRuntimeLoader
6872
)
6973

7074
set_target_properties(${LIB_TARGET_NAME} PROPERTIES

0 commit comments

Comments
 (0)