Skip to content

Commit 6c9f294

Browse files
committed
[SYCL][UR] Fix build with libc++
Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 2e736fb commit 6c9f294

File tree

12 files changed

+30
-81
lines changed

12 files changed

+30
-81
lines changed

buildbot/configure.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,9 @@ def do_configure(args, passthrough_args):
251251
cmake_cmd.append(llvm_dir)
252252

253253
if args.use_libcxx:
254-
if not (args.libcxx_include and args.libcxx_library):
255-
sys.exit(
256-
"Please specify include and library path of libc++ when building sycl "
257-
"runtime with it"
258-
)
259254
cmake_cmd.extend(
260255
[
261-
"-DSYCL_USE_LIBCXX=ON",
262-
"-DSYCL_LIBCXX_INCLUDE_PATH={}".format(args.libcxx_include),
263-
"-DSYCL_LIBCXX_LIBRARY_PATH={}".format(args.libcxx_library),
256+
"-DLLVM_ENABLE_LIBCXX=ON",
264257
]
265258
)
266259

@@ -387,10 +380,14 @@ def main():
387380
"--use-libcxx", action="store_true", help="build sycl runtime with libcxx"
388381
)
389382
parser.add_argument(
390-
"--libcxx-include", metavar="LIBCXX_INCLUDE_PATH", help="libcxx include path"
383+
"--libcxx-include",
384+
metavar="LIBCXX_INCLUDE_PATH",
385+
help="libcxx include path (deprecated)",
391386
)
392387
parser.add_argument(
393-
"--libcxx-library", metavar="LIBCXX_LIBRARY_PATH", help="libcxx library path"
388+
"--libcxx-library",
389+
metavar="LIBCXX_LIBRARY_PATH",
390+
help="libcxx library path (deprecated)",
394391
)
395392
parser.add_argument(
396393
"--use-lld", action="store_true", help="Use LLD linker for build"

libdevice/cmake/modules/SYCLLibdevice.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ set(compile_opts
5555

5656
set(SYCL_LIBDEVICE_GCC_TOOLCHAIN "" CACHE PATH "Path to GCC installation")
5757

58+
set(SYCL_LIBDEVICE_CXX_FLAGS "" CACHE STRING "C++ compiler flags for SYCL libdevice")
5859
if (NOT SYCL_LIBDEVICE_GCC_TOOLCHAIN STREQUAL "")
5960
list(APPEND compile_opts "--gcc-install-dir=${SYCL_LIBDEVICE_GCC_TOOLCHAIN}")
6061
endif()
62+
if(NOT SYCL_LIBDEVICE_CXX_FLAGS STREQUAL "")
63+
separate_arguments(SYCL_LIBDEVICE_CXX_FLAGS NATIVE_COMMAND ${SYCL_LIBDEVICE_CXX_FLAGS})
64+
list(APPEND compile_opts ${SYCL_LIBDEVICE_CXX_FLAGS})
65+
endif()
66+
if(LLVM_LIBCXX_USED)
67+
list(APPEND compile_opts "-stdlib=libc++")
68+
endif()
6169

6270
if (WIN32)
6371
list(APPEND compile_opts -D_ALLOW_RUNTIME_LIBRARY_MISMATCH)
@@ -644,6 +652,10 @@ if (NOT SYCL_LIBDEVICE_GCC_TOOLCHAIN STREQUAL "")
644652
list(APPEND imf_host_cxx_flags "--gcc-install-dir=${SYCL_LIBDEVICE_GCC_TOOLCHAIN}")
645653
endif()
646654

655+
if(LLVM_LIBCXX_USED)
656+
list(APPEND imf_host_cxx_flags "-stdlib=libc++")
657+
endif()
658+
647659
macro(mangle_name str output)
648660
string(STRIP "${str}" strippedStr)
649661
string(REGEX REPLACE "^/" "" strippedStr "${strippedStr}")

sycl/CMakeLists.txt

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -303,37 +303,18 @@ endif()
303303

304304
# This function allows building multiple libraries with the same options.
305305
# Currently used by add_sycl_library and add_sycl_rt_library.
306-
# Currently handles linking with libcxx support and gcc workaround
306+
# Currently handles a gcc workaround
307307
function( add_common_options LIB_NAME)
308-
if (SYCL_USE_LIBCXX)
309-
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
310-
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
311-
if ((NOT (DEFINED SYCL_LIBCXX_INCLUDE_PATH)) OR (NOT (DEFINED SYCL_LIBCXX_LIBRARY_PATH)))
312-
message(FATAL_ERROR "When building with libc++ SYCL_LIBCXX_INCLUDE_PATHS and"
313-
"SYCL_LIBCXX_LIBRARY_PATH should be set")
314-
endif()
315-
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)
316-
target_compile_options(${LIB_NAME} PRIVATE -nostdinc++)
317-
target_include_directories(${LIB_NAME} PRIVATE "${SYCL_LIBCXX_INCLUDE_PATH}")
318-
if (ARGC EQUAL 2)
319-
target_compile_options(${ARGV1} PRIVATE -nostdinc++)
320-
target_include_directories(${ARGV1} PRIVATE "${SYCL_LIBCXX_INCLUDE_PATH}")
321-
endif()
322-
else()
323-
message(FATAL_ERROR "Build with libc++ is not yet supported for this compiler")
324-
endif()
325-
else()
326308
# Workaround for bug in GCC version 5 and higher.
327309
# More information https://bugs.launchpad.net/ubuntu/+source/gcc-5/+bug/1568899
328310
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
329311
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 5.0)
330312
target_link_libraries(${ARGV0} PRIVATE gcc_s gcc)
331313
endif()
332-
endif()
333314
endfunction(add_common_options)
334315

335316
if (LLVM_ENABLE_ASSERTIONS AND NOT SYCL_DISABLE_STL_ASSERTIONS AND NOT WIN32)
336-
if(SYCL_USE_LIBCXX)
317+
if(LLVM_LIBCXX_USED)
337318
add_definitions(-D_LIBCPP_DEBUG=1)
338319
set(SYCL_CLANG_EXTRA_FLAGS "${SYCL_CLANG_EXTRA_FLAGS} -D_LIBCPP_DEBUG=1")
339320
else()

sycl/cmake/modules/AddSYCLExecutable.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ macro(add_sycl_executable ARG_TARGET_NAME)
2020
endforeach()
2121

2222
if (LLVM_ENABLE_ASSERTIONS AND NOT SYCL_DISABLE_STL_ASSERTIONS)
23-
if(SYCL_USE_LIBCXX)
23+
if(LLVM_ENABLE_LIBCXX)
2424
set(_SYCL_EXTRA_FLAGS -D_LIBCPP_DEBUG=1)
2525
else()
2626
set(_SYCL_EXTRA_FLAGS -D_GLIBCXX_ASSERTIONS=1)

sycl/doc/GetStartedGuide.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,24 @@ needed at the moment.
150150
### Build DPC++ toolchain with libc++ library
151151

152152
There is experimental support for building and linking DPC++ runtime with libc++
153-
library instead of libstdc++. To enable it the following CMake options should be
153+
library instead of libstdc++. To enable it the following CMake option should be
154154
used.
155155

156156
**Linux**:
157157

158158
```sh
159-
-DSYCL_USE_LIBCXX=ON \
160-
-DSYCL_LIBCXX_INCLUDE_PATH=<path to libc++ headers> \
161-
-DSYCL_LIBCXX_LIBRARY_PATH=<path to libc++ and libc++abi libraries>
159+
-DLLVM_ENABLE_LIBCXX=ON
162160
```
163161

164162
You can also use configure script to enable:
165163

166164
```sh
167-
python %DPCPP_HOME%\llvm\buildbot\configure.py --use-libcxx \
168-
--libcxx-include <path to libc++ headers> \
169-
--libcxx-library <path to libc++ and libc++ abi libraries>
165+
python %DPCPP_HOME%\llvm\buildbot\configure.py --use-libcxx
170166
python %DPCPP_HOME%\llvm\buildbot\compile.py
171167
```
172168

169+
Note that base LLVM must have also been built with libc++.
170+
173171
### Build DPC++ toolchain with support for NVIDIA CUDA
174172

175173
To enable support for CUDA devices, follow the instructions for the Linux or

sycl/source/builtins/common_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ BUILTIN_COMMON(ONE_ARG, radians,
3434

3535
BUILTIN_COMMON(ONE_ARG, sign, [](auto x) -> decltype(x) {
3636
using T = decltype(x);
37-
if (std::isnan(x))
37+
if (std::isnan(sycl::detail::cast_if_host_half(x)))
3838
return T(0.0);
3939
if (x > 0)
4040
return T(1.0);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ config.test_include_path = "@TEST_INCLUDE_PATH@"
2626
config.llvm_enable_projects = "@LLVM_ENABLE_PROJECTS@"
2727

2828
config.sycl_threads_lib = '@SYCL_THREADS_LIB@'
29-
config.sycl_use_libcxx = '@SYCL_USE_LIBCXX@'
29+
config.sycl_use_libcxx = '@LLVM_LIBCXX_USEDX@'
3030
config.extra_environment = lit_config.params.get("extra_environment", "@LIT_EXTRA_ENVIRONMENT@")
3131
config.cuda = '@SYCL_BUILD_BACKEND_CUDA@'
3232
config.hip = '@SYCL_BUILD_BACKEND_HIP@'

unified-runtime/source/loader/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -211,21 +211,10 @@ if(UR_ENABLE_SANITIZER)
211211
# In in-tree build, if LLVM is built with libc++, we also need to build
212212
# symbolizer.cpp with libc++ abi and link libc++ in.
213213
if(NOT UR_STANDALONE_BUILD AND LLVM_LIBCXX_USED)
214-
execute_process(
215-
COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libc++.a
216-
OUTPUT_VARIABLE LIBCXX_PATH
217-
OUTPUT_STRIP_TRAILING_WHITESPACE)
218-
execute_process(
219-
COMMAND ${CMAKE_CXX_COMPILER} --print-file-name=libc++abi.a
220-
OUTPUT_VARIABLE LIBCXX_ABI_PATH
221-
OUTPUT_STRIP_TRAILING_WHITESPACE)
222214
set_property(SOURCE
223215
${symbolizer_sources}
224216
APPEND_STRING PROPERTY COMPILE_FLAGS
225217
" -stdlib=libc++ ")
226-
if(NOT EXISTS ${LIBCXX_PATH} OR NOT EXISTS ${LIBCXX_ABI_PATH})
227-
message(FATAL_ERROR "libc++ is required but can't find the libraries")
228-
endif()
229218
# Link with gcc_s fisrt to avoid some symbols resolve to libc++/libc++abi/libunwind's one
230219
target_link_libraries(ur_loader PRIVATE gcc_s ${LIBCXX_PATH} ${LIBCXX_ABI_PATH})
231220
endif()

unified-runtime/source/loader/layers/sanitizer/msan/msan_libdevice.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#pragma once
1515

1616
#include "sanitizer_common/sanitizer_libdevice.hpp"
17+
#include <cstddef>
1718

1819
#if !defined(__SPIR__) && !defined(__SPIRV__)
1920
namespace ur_sanitizer_layer {

xpti/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,6 @@ if (MSVC)
5757
set(CMAKE_CXX_FLAGS_DEBUG "")
5858
endif()
5959

60-
if (SYCL_USE_LIBCXX)
61-
if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR
62-
(CMAKE_CXX_COMPILER_ID STREQUAL "Clang"))
63-
if ((NOT (DEFINED SYCL_LIBCXX_INCLUDE_PATH)) OR (NOT (DEFINED SYCL_LIBCXX_LIBRARY_PATH)))
64-
message(FATAL_ERROR "When building with libc++ SYCL_LIBCXX_INCLUDE_PATHS and"
65-
"SYCL_LIBCXX_LIBRARY_PATH should be set")
66-
endif()
67-
set(CMAKE_CXX_FLAGS "-nostdinc++ -I ${SYCL_LIBCXX_INCLUDE_PATH} ${CMAKE_CXX_FLAGS}")
68-
else()
69-
message(FATAL_ERROR "Build with libc++ is not yet supported for this compiler")
70-
endif()
71-
endif()
7260
set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/lib/${CMAKE_BUILD_TYPE})
7361
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
7462
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})

0 commit comments

Comments
 (0)