Skip to content

Commit 2f42570

Browse files
authored
[SYCL] Support building sycl runtime with libcxx in configure script (#2731)
Currently, we claim to support building sycl runtime with llvm libc++ as an experimental feature but building with libcxx will fail in latest sources. This patch includes: Adding support in configure script to build sycl runtime with llvm libc++. We need to manually construct the cmake commands previously. Fix some building failures: disabling xpti module when building sycl runtime with libcxx temporarily use libcxx to compile object files required by sycl runtime library during link time. Signed-off-by: gejin <[email protected]>
1 parent b37ac16 commit 2f42570

17 files changed

+46
-8
lines changed

buildbot/configure.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def do_configure(args):
1313
if not os.path.isdir(abs_obj_dir):
1414
os.makedirs(abs_obj_dir)
1515

16+
llvm_external_projects = 'sycl;llvm-spirv;opencl-aot;libdevice'
17+
if not args.use_libcxx:
18+
llvm_external_projects += ';xpti;xptifw'
19+
1620
llvm_dir = os.path.join(abs_src_dir, "llvm")
1721
sycl_dir = os.path.join(abs_src_dir, "sycl")
1822
spirv_dir = os.path.join(abs_src_dir, "llvm-spirv")
@@ -22,14 +26,15 @@ def do_configure(args):
2226
ocl_header_dir = os.path.join(abs_obj_dir, "OpenCL-Headers")
2327
icd_loader_lib = os.path.join(abs_obj_dir, "OpenCL-ICD-Loader", "build")
2428
llvm_targets_to_build = 'X86'
25-
llvm_enable_projects = 'clang;llvm-spirv;sycl;opencl-aot;xpti;xptifw;libdevice'
29+
llvm_enable_projects = 'clang;' + llvm_external_projects
2630
libclc_targets_to_build = ''
2731
sycl_build_pi_cuda = 'OFF'
2832
sycl_werror = 'ON'
2933
llvm_enable_assertions = 'ON'
3034
llvm_enable_doxygen = 'OFF'
3135
llvm_enable_sphinx = 'OFF'
3236
llvm_build_shared_libs = 'OFF'
37+
sycl_enable_xpti_tracing = 'OFF' if args.use_libcxx else 'ON'
3338

3439
icd_loader_lib = os.path.join(icd_loader_lib, "libOpenCL.so" if platform.system() == 'Linux' else "OpenCL.lib")
3540

@@ -64,7 +69,7 @@ def do_configure(args):
6469
"-DCMAKE_BUILD_TYPE={}".format(args.build_type),
6570
"-DLLVM_ENABLE_ASSERTIONS={}".format(llvm_enable_assertions),
6671
"-DLLVM_TARGETS_TO_BUILD={}".format(llvm_targets_to_build),
67-
"-DLLVM_EXTERNAL_PROJECTS=sycl;llvm-spirv;opencl-aot;xpti;xptifw;libdevice",
72+
"-DLLVM_EXTERNAL_PROJECTS={}".format(llvm_external_projects),
6873
"-DLLVM_EXTERNAL_SYCL_SOURCE_DIR={}".format(sycl_dir),
6974
"-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR={}".format(spirv_dir),
7075
"-DLLVM_EXTERNAL_XPTI_SOURCE_DIR={}".format(xpti_dir),
@@ -81,7 +86,7 @@ def do_configure(args):
8186
"-DLLVM_ENABLE_DOXYGEN={}".format(llvm_enable_doxygen),
8287
"-DLLVM_ENABLE_SPHINX={}".format(llvm_enable_sphinx),
8388
"-DBUILD_SHARED_LIBS={}".format(llvm_build_shared_libs),
84-
"-DSYCL_ENABLE_XPTI_TRACING=ON" # Explicitly turn on XPTI tracing
89+
"-DSYCL_ENABLE_XPTI_TRACING={}".format(sycl_enable_xpti_tracing)
8590
]
8691

8792
if args.system_ocl:
@@ -104,6 +109,15 @@ def do_configure(args):
104109
# Add path to root CMakeLists.txt
105110
cmake_cmd.append(llvm_dir)
106111

112+
if args.use_libcxx:
113+
if not (args.libcxx_include and args.libcxx_library):
114+
sys.exit("Please specify include and library path of libc++ when building sycl "
115+
"runtime with it")
116+
cmake_cmd.extend([
117+
"-DSYCL_USE_LIBCXX=ON",
118+
"-DSYCL_LIBCXX_INCLUDE_PATH={}".format(args.libcxx_include),
119+
"-DSYCL_LIBCXX_LIBRARY_PATH={}".format(args.libcxx_library)])
120+
107121
print("[Cmake Command]: {}".format(" ".join(cmake_cmd)))
108122

109123
try:
@@ -143,7 +157,9 @@ def main():
143157
parser.add_argument("--shared-libs", action='store_true', help="Build shared libraries")
144158
parser.add_argument("--cmake-opt", action='append', help="Additional CMake option not configured via script parameters")
145159
parser.add_argument("--cmake-gen", default="Ninja", help="CMake generator")
146-
160+
parser.add_argument("--use-libcxx", action="store_true", help="build sycl runtime with libcxx")
161+
parser.add_argument("--libcxx-include", metavar="LIBCXX_INCLUDE_PATH", help="libcxx include path")
162+
parser.add_argument("--libcxx-library", metavar="LIBCXX_LIBRARY_PATH", help="libcxx library path")
147163
args = parser.parse_args()
148164

149165
print("args:{}".format(args))

sycl/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,17 @@ function( add_common_options LIB_NAME)
227227
if (SYCL_USE_LIBCXX)
228228
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
229229
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
230-
target_compile_options(${LIB_NAME} PRIVATE -nostdinc++)
231230
if ((NOT (DEFINED SYCL_LIBCXX_INCLUDE_PATH)) OR (NOT (DEFINED SYCL_LIBCXX_LIBRARY_PATH)))
232231
message(FATAL_ERROR "When building with libc++ SYCL_LIBCXX_INCLUDE_PATHS and"
233232
"SYCL_LIBCXX_LIBRARY_PATH should be set")
234233
endif()
234+
target_link_libraries(${LIB_NAME} PRIVATE "-L${SYCL_LIBCXX_LIBRARY_PATH}" -Wl,-rpath,${SYCL_LIBCXX_LIBRARY_PATH} -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc)
235+
target_compile_options(${LIB_NAME} PRIVATE -nostdinc++)
235236
target_include_directories(${LIB_NAME} PRIVATE "${SYCL_LIBCXX_INCLUDE_PATH}")
236-
target_link_libraries(${LIB_NAME} PRIVATE "-L${SYCL_LIBCXX_LIBRARY_PATH}" -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc)
237+
if (ARGC EQUAL 2)
238+
target_compile_options(${ARGV1} PRIVATE -nostdinc++)
239+
target_include_directories(${ARGV1} PRIVATE "${SYCL_LIBCXX_INCLUDE_PATH}")
240+
endif()
237241
else()
238242
message(FATAL_ERROR "Build with libc++ is not yet supported for this compiler")
239243
endif()
@@ -243,7 +247,7 @@ function( add_common_options LIB_NAME)
243247
# More information https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899
244248
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
245249
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
246-
target_link_libraries(${LIB_NAME} PRIVATE gcc_s gcc)
250+
target_link_libraries(${ARGV0} PRIVATE gcc_s gcc)
247251
endif()
248252

249253
endif()

sycl/source/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function(add_sycl_rt_library LIB_NAME)
8484
PUBLIC
8585
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:USE_PI_CUDA>)
8686

87-
add_common_options(${LIB_NAME})
87+
add_common_options(${LIB_NAME} ${LIB_OBJ_NAME})
8888

8989
set_target_properties(${LIB_NAME} PROPERTIES
9090
VERSION ${SYCL_VERSION_STRING}

sycl/test/abi/layout_accessors_device.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clangxx -fsycl -fsycl-device-only -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s
22
// REQUIRES: linux
3+
// UNSUPPORTED: libcxx
34

45
// clang-format off
56

sycl/test/abi/layout_accessors_host.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s
22
// REQUIRES: linux
3+
// UNSUPPORTED: libcxx
34

45
// clang-format off
56

sycl/test/abi/layout_array.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s
22
// RUN: %clangxx -fsycl -fsycl-device-only -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s
33
// REQUIRES: linux
4+
// UNSUPPORTED: libcxx
45

56
// clang-format off
67

sycl/test/abi/layout_buffer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s
22
// REQUIRES: linux
3+
// UNSUPPORTED: libcxx
34

45
// clang-format off
56

sycl/test/abi/layout_handler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s
22
// REQUIRES: linux
3+
// UNSUPPORTED: libcxx
34

45
#include <CL/sycl/handler.hpp>
56
#include <CL/sycl/queue.hpp>

sycl/test/abi/layout_image.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s
22
// REQUIRES: linux
3+
// UNSUPPORTED: libcxx
34

45
// clang-format off
56

sycl/test/abi/layout_vec.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %clangxx -fsycl -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s
22
// RUN: %clangxx -fsycl -fsycl-device-only -c -fno-color-diagnostics -Xclang -fdump-record-layouts %s | FileCheck %s
33
// REQUIRES: linux
4+
// UNSUPPORTED: libcxx
45

56
// clang-format off
67

sycl/test/abi/pi_level_zero_symbol_check.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# RUN: env LLVM_BIN_PATH=%llvm_build_bin_dir python %sycl_tools_src_dir/abi_check.py --mode check_symbols --reference %s %sycl_libs_dir/libpi_level_zero.so
77
# REQUIRES: linux
8+
# UNSUPPORTED: libcxx
89

910
piContextCreate
1011
piContextGetInfo

sycl/test/abi/pi_opencl_symbol_check.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# RUN: env LLVM_BIN_PATH=%llvm_build_bin_dir python %sycl_tools_src_dir/abi_check.py --mode check_symbols --reference %s %sycl_libs_dir/libpi_opencl.so
77
# REQUIRES: linux
8+
# UNSUPPORTED: libcxx
89

910
piContextCreate
1011
piDeviceGetInfo

sycl/test/abi/sycl_symbols_linux.dump

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
# RUN: env LLVM_BIN_PATH=%llvm_build_bin_dir python %sycl_tools_src_dir/abi_check.py --mode check_symbols --reference %s %sycl_libs_dir/libsycl.so
77
# REQUIRES: linux
8+
# UNSUPPORTED: libcxx
89

910
_Z20__spirv_ocl_prefetchPKcm
1011
_Z21__spirv_MemoryBarrierN5__spv5ScopeEj

sycl/test/abi/symbol_size_alignment.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clangxx -fsycl %s -o %t
2+
// UNSUPPORTED: libcxx
23

34
// Changing symbol size or alignment is a breaking change. If it happens, refer
45
// to the ABI Policy Guide for further instructions on breaking ABI.

sycl/test/abi/user_mangling.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// RUN: %clangxx -fsycl -c -emit-llvm -S -o - %s | FileCheck %s --check-prefix CHK-HOST
33
// RUN: %clangxx -fsycl -fsycl-device-only -O0 -c -emit-llvm -S -o - %s | FileCheck %s --check-prefix CHK-DEVICE
44
// REQUIRES: linux
5+
// UNSUPPORTED: libcxx
56

67
#include <CL/sycl.hpp>
78

sycl/test/lit.cfg.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@
3939
llvm_config.with_system_environment(['PATH', 'OCL_ICD_FILENAMES', 'SYCL_DEVICE_ALLOWLIST', 'SYCL_CONFIG_FILE_NAME'])
4040

4141
# Configure LD_LIBRARY_PATH or corresponding os-specific alternatives
42+
# Add 'libcxx' feature to filter out all SYCL abi tests when SYCL runtime
43+
# is built with llvm libcxx. This feature is added for Linux only since MSVC
44+
# CL compiler doesn't support to use llvm libcxx instead of MSVC STL.
4245
if platform.system() == "Linux":
4346
config.available_features.add('linux')
47+
if config.sycl_use_libcxx == "ON":
48+
config.available_features.add('libcxx')
4449
llvm_config.with_system_environment('LD_LIBRARY_PATH')
4550
llvm_config.with_environment('LD_LIBRARY_PATH', config.sycl_libs_dir, append_path=True)
4651
llvm_config.with_system_environment('CFLAGS')

sycl/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ config.sycl_clang_extra_flags = "@SYCL_CLANG_EXTRA_FLAGS@"
2222
config.llvm_enable_projects = "@LLVM_ENABLE_PROJECTS@"
2323

2424
config.sycl_threads_lib = '@SYCL_THREADS_LIB@'
25+
config.sycl_use_libcxx = '@SYCL_USE_LIBCXX@'
2526

2627
import lit.llvm
2728
lit.llvm.initialize(lit_config, config)

0 commit comments

Comments
 (0)