Skip to content

Commit 550241e

Browse files
KseniyaTikhomirovabader
authored andcommitted
[SYCL] Add libsycl, a SYCL RT library implementation project (llvm#144372)
This patch introduces libsycl, a SYCL runtime library implementation, as a top-level LLVM runtime project. SYCL spec: https://registry.khronos.org/SYCL/specs/sycl-2020/html/sycl-2020.html Commit contains the basic folder layout and CMake infrastructure to build a dummy SYCL library. This is part of the SYCL support upstreaming effort. The relevant RFCs can be found here: https://discourse.llvm.org/t/rfc-add-full-support-for-the-sycl-programming-model/74080 https://discourse.llvm.org/t/rfc-sycl-runtime-upstreaming/74479 Upcoming PRs: - UR offloading library fetch & build - partial implementation of sycl::platform: requires offloading layer, requires classes for backend loading & enumeration. --------- Signed-off-by: Tikhomirova, Kseniya <[email protected]> Co-authored-by: Alexey Bader <[email protected]>
1 parent 4a71ade commit 550241e

File tree

16 files changed

+816
-2
lines changed

16 files changed

+816
-2
lines changed

libsycl/.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BasedOnStyle: LLVM
2+
3+
# Preferred indentions of preprocessor statements.
4+
IndentPPDirectives: AfterHash

libsycl/.clang-tidy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Checks: >
2+
-*,
3+
clang-analyzer-*,
4+
clang-diagnostic-*,
5+
cppcoreguidelines-*,
6+
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
7+
-cppcoreguidelines-pro-bounds-constant-array-index,
8+
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
9+
-cppcoreguidelines-pro-type-member-init,
10+
-cppcoreguidelines-pro-type-union-access,
11+
google-*,
12+
-google-build-using-namespace,
13+
-google-explicit-constructor,
14+
-google-runtime-references,
15+
misc-*,
16+
-misc-macro-parentheses,
17+
-misc-unused-parameters

libsycl/CMakeLists.txt

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#===============================================================================
2+
# Setup Project
3+
#===============================================================================
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
set(LLVM_SUBPROJECT_TITLE "libsycl")
7+
8+
set(LIBSYCL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
9+
set(LIBSYCL_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
10+
11+
set(CMAKE_CXX_STANDARD 17)
12+
set(CMAKE_CXX_STANDARD_REQUIRED YES)
13+
set(CMAKE_CXX_EXTENSIONS OFF)
14+
15+
#===============================================================================
16+
# Limitations
17+
#===============================================================================
18+
19+
if (CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT MSVC)
20+
# Build with other compilers is not configured, not guaranteed and not tested.
21+
message(FATAL_ERROR
22+
"When compiling for Windows, libsycl requires a"
23+
" version of Microsoft Visual C++ or another compiler"
24+
" that uses the Visual C++ cl command-line syntax.")
25+
endif()
26+
27+
#===============================================================================
28+
# Setup CMake Options
29+
#===============================================================================
30+
31+
option(LIBSYCL_ENABLE_WERROR "Treat all warnings as errors in the libsycl project" OFF)
32+
option(LIBSYCL_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF)
33+
34+
#===============================================================================
35+
# Configure System
36+
#===============================================================================
37+
38+
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
39+
40+
set(LIBSYCL_SHARED_OUTPUT_NAME "sycl" CACHE STRING "Output name for the shared libsycl runtime library.")
41+
42+
if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
43+
set(LIBSYCL_TARGET_SUBDIR ${LLVM_DEFAULT_TARGET_TRIPLE})
44+
if(LIBSYCL_LIBDIR_SUBDIR)
45+
string(APPEND LIBSYCL_TARGET_SUBDIR /${LIBSYCL_LIBDIR_SUBDIR})
46+
endif()
47+
cmake_path(NORMAL_PATH LIBSYCL_TARGET_SUBDIR)
48+
set(LIBSYCL_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LIBSYCL_TARGET_SUBDIR})
49+
set(LIBSYCL_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LIBSYCL_TARGET_SUBDIR} CACHE STRING
50+
"Path where built libsycl libraries should be installed.")
51+
unset(LIBSYCL_TARGET_SUBDIR)
52+
else()
53+
if(LLVM_LIBRARY_OUTPUT_INTDIR)
54+
set(LIBSYCL_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
55+
else()
56+
set(LIBSYCL_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBSYCL_LIBDIR_SUFFIX})
57+
endif()
58+
set(LIBSYCL_INSTALL_LIBRARY_DIR lib${LIBSYCL_LIBDIR_SUFFIX} CACHE STRING
59+
"Path where built libsycl libraries should be installed.")
60+
endif()
61+
62+
set(LIBSYCL_INCLUDE_DIR include)
63+
set(LIBSYCL_BUILD_INCLUDE_DIR ${LLVM_BINARY_DIR}/${LIBSYCL_INCLUDE_DIR})
64+
set(LIBSYCL_SOURCE_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
65+
66+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})
67+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})
68+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${LIBSYCL_LIBRARY_DIR})
69+
70+
set(LIBSYCL_MAJOR_VERSION 0)
71+
set(LIBSYCL_MINOR_VERSION 1)
72+
set(LIBSYCL_PATCH_VERSION 0)
73+
set(LIBSYCL_VERSION_STRING "${LIBSYCL_MAJOR_VERSION}.${LIBSYCL_MINOR_VERSION}.${LIBSYCL_PATCH_VERSION}")
74+
set(LIBSYCL_ABI_NAMESPACE "__V${LIBSYCL_MAJOR_VERSION}" CACHE STRING
75+
"The inline ABI namespace used by libsycl. It defaults to __Vn where `n` is the current ABI version.")
76+
if (NOT LIBSYCL_ABI_NAMESPACE MATCHES "__V.*")
77+
message(FATAL_ERROR "LIBSYCL_ABI_NAMESPACE must be a reserved identifier, got '${LIBSYCL_ABI_NAMESPACE}'.")
78+
endif()
79+
80+
#===============================================================================
81+
# Setup build & install rules
82+
#===============================================================================
83+
84+
# Generate headers
85+
configure_file("${LIBSYCL_SOURCE_DIR}/src/version.hpp.in" "${LIBSYCL_BUILD_INCLUDE_DIR}/sycl/__impl/version.hpp")
86+
87+
# Install generated headers.
88+
install(FILES
89+
"${LIBSYCL_BUILD_INCLUDE_DIR}/sycl/__impl/version.hpp"
90+
DESTINATION "${LIBSYCL_INCLUDE_DIR}/sycl/__impl"
91+
COMPONENT sycl-headers)
92+
93+
# This is a workaround to detect changes (add or modify) in subtree which
94+
# are not detected by copy_directory command.
95+
file(GLOB_RECURSE HEADERS_IN_SYCL_DIR CONFIGURE_DEPENDS "${LIBSYCL_SOURCE_INCLUDE_DIR}/sycl/*")
96+
file(GLOB_RECURSE HEADERS_IN_CL_DIR CONFIGURE_DEPENDS "${LIBSYCL_SOURCE_INCLUDE_DIR}/CL/*")
97+
98+
string(REPLACE "${LIBSYCL_SOURCE_INCLUDE_DIR}" "${LIBSYCL_BUILD_INCLUDE_DIR}"
99+
OUT_HEADERS_IN_SYCL_DIR "${HEADERS_IN_SYCL_DIR}")
100+
string(REPLACE "${LIBSYCL_SOURCE_INCLUDE_DIR}/CL" "${LIBSYCL_BUILD_INCLUDE_DIR}/CL"
101+
OUT_HEADERS_IN_CL_DIR "${HEADERS_IN_CL_DIR}")
102+
103+
# Copy SYCL headers from sources to build directory
104+
add_custom_target(sycl-headers
105+
DEPENDS ${OUT_HEADERS_IN_SYCL_DIR}
106+
${OUT_HEADERS_IN_CL_DIR})
107+
108+
add_custom_command(
109+
OUTPUT ${OUT_HEADERS_IN_SYCL_DIR}
110+
${OUT_HEADERS_IN_CL_DIR}
111+
DEPENDS ${HEADERS_IN_SYCL_DIR}
112+
${HEADERS_IN_CL_DIR}
113+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBSYCL_SOURCE_INCLUDE_DIR}/sycl ${LIBSYCL_BUILD_INCLUDE_DIR}/sycl
114+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${LIBSYCL_SOURCE_INCLUDE_DIR}/CL ${LIBSYCL_BUILD_INCLUDE_DIR}/CL
115+
COMMENT "Copying SYCL headers...")
116+
117+
install(DIRECTORY "${LIBSYCL_SOURCE_INCLUDE_DIR}/sycl" DESTINATION ${LIBSYCL_INCLUDE_DIR} COMPONENT sycl-headers)
118+
install(DIRECTORY "${LIBSYCL_SOURCE_INCLUDE_DIR}/CL" DESTINATION ${LIBSYCL_INCLUDE_DIR} COMPONENT sycl-headers)
119+
120+
set(LIBSYCL_RT_LIBS ${LIBSYCL_SHARED_OUTPUT_NAME})
121+
122+
add_subdirectory(src)
123+
124+
add_custom_target(libsycl-runtime-libraries
125+
DEPENDS ${LIBSYCL_RT_LIBS}
126+
)

0 commit comments

Comments
 (0)