diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index e927ec4f140d9..ded096237477e 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4191,6 +4191,7 @@ class OffloadingActionBuilder final { // default too. SmallVector sycl_device_fallback_libs = { {"libsycl-fallback-cassert", "libc"}, + {"libsycl-fallback-cstring", "libc"}, {"libsycl-fallback-complex", "libm-fp32"}, {"libsycl-fallback-complex-fp64", "libm-fp64"}, {"libsycl-fallback-cmath", "libm-fp32"}, diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index 93711d3732ed1..793672dc41da8 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -133,6 +133,7 @@ static llvm::SmallVector SYCLDeviceLibList{ "complex", "complex-fp64", "fallback-cassert", + "fallback-cstring", "fallback-cmath", "fallback-cmath-fp64", "fallback-complex", diff --git a/clang/test/Driver/Inputs/SYCL-windows/lib/libsycl-fallback-cstring.obj b/clang/test/Driver/Inputs/SYCL-windows/lib/libsycl-fallback-cstring.obj new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/Inputs/SYCL/lib/libsycl-fallback-cstring.o b/clang/test/Driver/Inputs/SYCL/lib/libsycl-fallback-cstring.o new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/clang/test/Driver/sycl-device-lib-win.cpp b/clang/test/Driver/sycl-device-lib-win.cpp index 6ef0d435037cf..052ea61f13b49 100644 --- a/clang/test/Driver/sycl-device-lib-win.cpp +++ b/clang/test/Driver/sycl-device-lib-win.cpp @@ -21,6 +21,7 @@ // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath.obj" "-outputs={{.*}}libsycl-cmath-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath-fp64.obj" "-outputs={{.*}}libsycl-cmath-fp64-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cassert.obj" "-outputs={{.*}}libsycl-fallback-cassert-{{.*}}.o" "-unbundle" +// SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cstring.obj" "-outputs={{.*}}libsycl-fallback-cstring-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex.obj" "-outputs={{.*}}libsycl-fallback-complex-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex-fp64.obj" "-outputs={{.*}}libsycl-fallback-complex-fp64-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cmath.obj" "-outputs={{.*}}libsycl-fallback-cmath-{{.*}}.o" "-unbundle" @@ -44,6 +45,7 @@ // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath.obj" "-outputs={{.*}}libsycl-cmath-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath-fp64.obj" "-outputs={{.*}}libsycl-cmath-fp64-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cassert.obj" "-outputs={{.*}}libsycl-fallback-cassert-{{.*}}.o" "-unbundle" +// SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cstring.obj" "-outputs={{.*}}libsycl-fallback-cstring-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex.obj" "-outputs={{.*}}libsycl-fallback-complex-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex-fp64.obj" "-outputs={{.*}}libsycl-fallback-complex-fp64-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cmath.obj" "-outputs={{.*}}libsycl-fallback-cmath-{{.*}}.o" "-unbundle" @@ -69,7 +71,7 @@ // RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_UNBUNDLE_NO_LIBM // SYCL_DEVICE_LIB_UNBUNDLE_NO_LIBM: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-crt.obj" "-outputs={{.*}}libsycl-crt-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_NO_LIBM-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cassert.obj" "-outputs={{.*}}libsycl-fallback-cassert-{{.*}}.o" "-unbundle" - +// SYCL_DEVICE_LIB_UNBUNDLE_NO_LIBM-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cstring.obj" "-outputs={{.*}}libsycl-fallback-cstring-{{.*}}.o" "-unbundle" /// ########################################################################### /// test behavior of disabling all device libraries @@ -109,6 +111,7 @@ // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath.obj" "-outputs={{.*}}libsycl-cmath-{{.*}}.o" "-unbundle" // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath-fp64.obj" "-outputs={{.*}}libsycl-cmath-fp64-{{.*}}.o" "-unbundle" // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cassert.obj" "-outputs={{.*}}libsycl-fallback-cassert-{{.*}}.o" "-unbundle" +// SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cstring.obj" "-outputs={{.*}}libsycl-fallback-cstring-{{.*}}.o" "-unbundle" // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex.obj" "-outputs={{.*}}libsycl-fallback-complex-{{.*}}.o" "-unbundle" // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex-fp64.obj" "-outputs={{.*}}libsycl-fallback-complex-fp64-{{.*}}.o" "-unbundle" // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cmath.obj" "-outputs={{.*}}libsycl-fallback-cmath-{{.*}}.o" "-unbundle" diff --git a/clang/test/Driver/sycl-device-lib.cpp b/clang/test/Driver/sycl-device-lib.cpp index 5d66e337bd832..6a11ef58775bc 100644 --- a/clang/test/Driver/sycl-device-lib.cpp +++ b/clang/test/Driver/sycl-device-lib.cpp @@ -21,6 +21,7 @@ // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath.o" "-outputs={{.*}}libsycl-cmath-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath-fp64.o" "-outputs={{.*}}libsycl-cmath-fp64-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cassert.o" "-outputs={{.*}}libsycl-fallback-cassert-{{.*}}.o" "-unbundle" +// SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cstring.o" "-outputs={{.*}}libsycl-fallback-cstring-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex.o" "-outputs={{.*}}libsycl-fallback-complex-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex-fp64.o" "-outputs={{.*}}libsycl-fallback-complex-fp64-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_DEFAULT-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cmath.o" "-outputs={{.*}}libsycl-fallback-cmath-{{.*}}.o" "-unbundle" @@ -44,6 +45,7 @@ // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath.o" "-outputs={{.*}}libsycl-cmath-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath-fp64.o" "-outputs={{.*}}libsycl-cmath-fp64-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cassert.o" "-outputs={{.*}}libsycl-fallback-cassert-{{.*}}.o" "-unbundle" +// SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cstring.o" "-outputs={{.*}}libsycl-fallback-cstring-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex.o" "-outputs={{.*}}libsycl-fallback-complex-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex-fp64.o" "-outputs={{.*}}libsycl-fallback-complex-fp64-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_WITH_FP64-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cmath.o" "-outputs={{.*}}libsycl-fallback-cmath-{{.*}}.o" "-unbundle" @@ -69,6 +71,7 @@ // RUN: | FileCheck %s -check-prefix=SYCL_DEVICE_LIB_UNBUNDLE_NO_LIBM // SYCL_DEVICE_LIB_UNBUNDLE_NO_LIBM: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-crt.o" "-outputs={{.*}}libsycl-crt-{{.*}}.o" "-unbundle" // SYCL_DEVICE_LIB_UNBUNDLE_NO_LIBM-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cassert.o" "-outputs={{.*}}libsycl-fallback-cassert-{{.*}}.o" "-unbundle" +// SYCL_DEVICE_LIB_UNBUNDLE_NO_LIBM-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cstring.o" "-outputs={{.*}}libsycl-fallback-cstring-{{.*}}.o" "-unbundle" /// ########################################################################### @@ -109,6 +112,7 @@ // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath.o" "-outputs={{.*}}libsycl-cmath-{{.*}}.o" "-unbundle" // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-cmath-fp64.o" "-outputs={{.*}}libsycl-cmath-fp64-{{.*}}.o" "-unbundle" // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cassert.o" "-outputs={{.*}}libsycl-fallback-cassert-{{.*}}.o" "-unbundle" +// SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cstring.o" "-outputs={{.*}}libsycl-fallback-cstring-{{.*}}.o" "-unbundle" // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex.o" "-outputs={{.*}}libsycl-fallback-complex-{{.*}}.o" "-unbundle" // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-complex-fp64.o" "-outputs={{.*}}libsycl-fallback-complex-fp64-{{.*}}.o" "-unbundle" // SYCL_LLVM_LINK_DEVICE_LIB-NEXT: clang-offload-bundler{{.*}} "-type=o" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs={{.*}}libsycl-fallback-cmath.o" "-outputs={{.*}}libsycl-fallback-cmath-{{.*}}.o" "-unbundle" diff --git a/libdevice/cmake/modules/SYCLLibdevice.cmake b/libdevice/cmake/modules/SYCLLibdevice.cmake index dbb75e31104e0..d4166cece929f 100644 --- a/libdevice/cmake/modules/SYCLLibdevice.cmake +++ b/libdevice/cmake/modules/SYCLLibdevice.cmake @@ -78,7 +78,7 @@ add_custom_command(OUTPUT ${devicelib-obj-cmath-fp64} VERBATIM) add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-cassert.spv - COMMAND ${clang} -S -fsycl-device-only -fno-sycl-use-bitcode + COMMAND ${clang} -fsycl-device-only -fno-sycl-use-bitcode ${compile_opts} ${CMAKE_CURRENT_SOURCE_DIR}/fallback-cassert.cpp -o ${spv_binary_dir}/libsycl-fallback-cassert.spv @@ -86,6 +86,15 @@ add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-cassert.spv DEPENDS wrapper.h device.h clang spirv_vars.h llvm-spirv VERBATIM) +add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-cstring.spv + COMMAND ${clang} -fsycl-device-only -fno-sycl-use-bitcode + ${compile_opts} + ${CMAKE_CURRENT_SOURCE_DIR}/fallback-cstring.cpp + -o ${spv_binary_dir}/libsycl-fallback-cstring.spv + MAIN_DEPENDENCY fallback-cstring.cpp + DEPENDS wrapper.h device.h clang spirv_vars.h llvm-spirv + VERBATIM) + add_custom_command(OUTPUT ${obj_binary_dir}/libsycl-fallback-cassert.${lib-suffix} COMMAND ${clang} -fsycl -c ${compile_opts} ${sycl_targets_opt} @@ -95,8 +104,17 @@ add_custom_command(OUTPUT ${obj_binary_dir}/libsycl-fallback-cassert.${lib-suffi DEPENDS wrapper.h device.h clang spirv_vars.h clang-offload-bundler VERBATIM) +add_custom_command(OUTPUT ${obj_binary_dir}/libsycl-fallback-cstring.${lib-suffix} + COMMAND ${clang} -fsycl -c + ${compile_opts} ${sycl_targets_opt} + ${CMAKE_CURRENT_SOURCE_DIR}/fallback-cstring.cpp + -o ${obj_binary_dir}/libsycl-fallback-cstring.${lib-suffix} + MAIN_DEPENDENCY fallback-cstring.cpp + DEPENDS wrapper.h device.h clang spirv_vars.h clang-offload-bundler + VERBATIM) + add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-complex.spv - COMMAND ${clang} -S -fsycl-device-only -fno-sycl-use-bitcode + COMMAND ${clang} -fsycl-device-only -fno-sycl-use-bitcode ${compile_opts} ${CMAKE_CURRENT_SOURCE_DIR}/fallback-complex.cpp -o ${spv_binary_dir}/libsycl-fallback-complex.spv @@ -114,7 +132,7 @@ add_custom_command(OUTPUT ${obj_binary_dir}/libsycl-fallback-complex.${lib-suffi VERBATIM) add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-complex-fp64.spv - COMMAND ${clang} -S -fsycl-device-only -fno-sycl-use-bitcode + COMMAND ${clang} -fsycl-device-only -fno-sycl-use-bitcode ${compile_opts} ${CMAKE_CURRENT_SOURCE_DIR}/fallback-complex-fp64.cpp -o ${spv_binary_dir}/libsycl-fallback-complex-fp64.spv @@ -132,7 +150,7 @@ add_custom_command(OUTPUT ${obj_binary_dir}/libsycl-fallback-complex-fp64.${lib- VERBATIM) add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-cmath.spv - COMMAND ${clang} -S -fsycl-device-only -fno-sycl-use-bitcode + COMMAND ${clang} -fsycl-device-only -fno-sycl-use-bitcode ${compile_opts} ${CMAKE_CURRENT_SOURCE_DIR}/fallback-cmath.cpp -o ${spv_binary_dir}/libsycl-fallback-cmath.spv @@ -150,7 +168,7 @@ add_custom_command(OUTPUT ${obj_binary_dir}/libsycl-fallback-cmath.${lib-suffix} VERBATIM) add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-cmath-fp64.spv - COMMAND ${clang} -S -fsycl-device-only -fno-sycl-use-bitcode + COMMAND ${clang} -fsycl-device-only -fno-sycl-use-bitcode ${compile_opts} ${CMAKE_CURRENT_SOURCE_DIR}/fallback-cmath-fp64.cpp -o ${spv_binary_dir}/libsycl-fallback-cmath-fp64.spv @@ -210,6 +228,7 @@ add_custom_target(libsycldevice-obj DEPENDS ) add_custom_target(libsycldevice-spv DEPENDS ${spv_binary_dir}/libsycl-fallback-cassert.spv + ${spv_binary_dir}/libsycl-fallback-cstring.spv ${spv_binary_dir}/libsycl-fallback-complex.spv ${spv_binary_dir}/libsycl-fallback-complex-fp64.spv ${spv_binary_dir}/libsycl-fallback-cmath.spv @@ -217,6 +236,7 @@ add_custom_target(libsycldevice-spv DEPENDS ) add_custom_target(libsycldevice-fallback-obj DEPENDS ${obj_binary_dir}/libsycl-fallback-cassert.${lib-suffix} + ${obj_binary_dir}/libsycl-fallback-cstring.${lib-suffix} ${obj_binary_dir}/libsycl-fallback-complex.${lib-suffix} ${obj_binary_dir}/libsycl-fallback-complex-fp64.${lib-suffix} ${obj_binary_dir}/libsycl-fallback-cmath.${lib-suffix} @@ -239,6 +259,7 @@ set(install_dest_lib lib${LLVM_LIBDIR_SUFFIX}) install(FILES ${devicelib-obj-file} ${obj_binary_dir}/libsycl-fallback-cassert.${lib-suffix} + ${obj_binary_dir}/libsycl-fallback-cstring.${lib-suffix} ${devicelib-obj-complex} ${obj_binary_dir}/libsycl-fallback-complex.${lib-suffix} ${devicelib-obj-complex-fp64} @@ -252,6 +273,7 @@ install(FILES ${devicelib-obj-file} COMPONENT libsycldevice) install(FILES ${spv_binary_dir}/libsycl-fallback-cassert.spv + ${spv_binary_dir}/libsycl-fallback-cstring.spv ${spv_binary_dir}/libsycl-fallback-complex.spv ${spv_binary_dir}/libsycl-fallback-complex-fp64.spv ${spv_binary_dir}/libsycl-fallback-cmath.spv diff --git a/libdevice/crt_wrapper.cpp b/libdevice/crt_wrapper.cpp index b3d03e3409c7d..230d6dc2d9754 100644 --- a/libdevice/crt_wrapper.cpp +++ b/libdevice/crt_wrapper.cpp @@ -9,6 +9,10 @@ #include "wrapper.h" #ifdef __SPIR__ +DEVICE_EXTERN_C +void *memcpy(void *dest, const void *src, size_t n) { + return __devicelib_memcpy(dest, src, n); +} #if defined(_WIN32) // Truncates a wide (16 or 32 bit) string (wstr) into an ASCII string (str). // Any non-ASCII characters are replaced by question mark '?'. diff --git a/libdevice/fallback-cstring.cpp b/libdevice/fallback-cstring.cpp new file mode 100644 index 0000000000000..2c54b3f63fe83 --- /dev/null +++ b/libdevice/fallback-cstring.cpp @@ -0,0 +1,15 @@ +//==-- fallback-cstring.cpp - fallback implementation of C string functions--=// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "wrapper.h" + +#ifdef __SPIR__ +void *__devicelib_memcpy(void *dest, const void *src, size_t n) { + return __builtin_memcpy(dest, src, n); +} +#endif // __SPIR__ diff --git a/libdevice/wrapper.h b/libdevice/wrapper.h index 2116d1e55a226..cd143c08bc395 100644 --- a/libdevice/wrapper.h +++ b/libdevice/wrapper.h @@ -18,7 +18,8 @@ // We need the following header to ensure the definition of all spirv variables // required by the wrapper libraries. #include "spirv_vars.h" - +DEVICE_EXTERN_C +void *__devicelib_memcpy(void *dest, const void *src, size_t n); DEVICE_EXTERN_C void __devicelib_assert_fail(const char *expr, const char *file, int32_t line, const char *func, uint64_t gid0, uint64_t gid1, diff --git a/llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.cpp b/llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.cpp index ea182b36d6d4b..80f197ff8d022 100644 --- a/llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.cpp +++ b/llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.cpp @@ -158,6 +158,7 @@ SYCLDeviceLibFuncMap SDLMap = { {"__devicelib_csqrt", DeviceLibExt::cl_intel_devicelib_complex_fp64}, {"__devicelib_ctan", DeviceLibExt::cl_intel_devicelib_complex_fp64}, {"__devicelib_ctanh", DeviceLibExt::cl_intel_devicelib_complex_fp64}, + {"__devicelib_memcpy", DeviceLibExt::cl_intel_devicelib_cstring}, }; // Each fallback device library corresponds to one bit in "require mask" which @@ -169,6 +170,7 @@ SYCLDeviceLibFuncMap SDLMap = { // fallback-cmath-fp64: 0x4 // fallback-complex: 0x8 // fallback-complex-fp64: 0x10 +// fallback-cstring: 0x20 uint32_t getDeviceLibBits(const std::string &FuncName) { auto DeviceLibFuncIter = SDLMap.find(FuncName); return ((DeviceLibFuncIter == SDLMap.end()) diff --git a/llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.h b/llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.h index 065ca8cdf1aa3..9cd07905883f0 100644 --- a/llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.h +++ b/llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.h @@ -28,7 +28,8 @@ enum class DeviceLibExt : std::uint32_t { cl_intel_devicelib_math, cl_intel_devicelib_math_fp64, cl_intel_devicelib_complex, - cl_intel_devicelib_complex_fp64 + cl_intel_devicelib_complex_fp64, + cl_intel_devicelib_cstring, }; using SYCLDeviceLibFuncMap = std::unordered_map; diff --git a/sycl/include/CL/sycl/builtins.hpp b/sycl/include/CL/sycl/builtins.hpp index 28264d95606a9..4e075e1f97f98 100644 --- a/sycl/include/CL/sycl/builtins.hpp +++ b/sycl/include/CL/sycl/builtins.hpp @@ -1630,6 +1630,8 @@ extern SYCL_EXTERNAL double atanh(double x); extern SYCL_EXTERNAL double frexp(double x, int *exp); extern SYCL_EXTERNAL double ldexp(double x, int exp); extern SYCL_EXTERNAL double hypot(double x, double y); + +extern SYCL_EXTERNAL void *memcpy(void *dest, const void *src, size_t n); } #ifdef __GLIBC__ extern "C" { diff --git a/sycl/source/detail/program_manager/program_manager.cpp b/sycl/source/detail/program_manager/program_manager.cpp index e9017de73d3f6..e36a9ec2e3473 100644 --- a/sycl/source/detail/program_manager/program_manager.cpp +++ b/sycl/source/detail/program_manager/program_manager.cpp @@ -647,6 +647,8 @@ static const char *getDeviceLibFilename(DeviceLibExt Extension) { return "libsycl-fallback-complex.spv"; case DeviceLibExt::cl_intel_devicelib_complex_fp64: return "libsycl-fallback-complex-fp64.spv"; + case DeviceLibExt::cl_intel_devicelib_cstring: + return "libsycl-fallback-cstring.spv"; } throw compile_program_error("Unhandled (new?) device library extension", PI_INVALID_OPERATION); @@ -664,6 +666,8 @@ static const char *getDeviceLibExtensionStr(DeviceLibExt Extension) { return "cl_intel_devicelib_complex"; case DeviceLibExt::cl_intel_devicelib_complex_fp64: return "cl_intel_devicelib_complex_fp64"; + case DeviceLibExt::cl_intel_devicelib_cstring: + return "cl_intel_devicelib_cstring"; } throw compile_program_error("Unhandled (new?) device library extension", PI_INVALID_OPERATION); @@ -829,7 +833,8 @@ static std::vector getDeviceLibPrograms( {DeviceLibExt::cl_intel_devicelib_math, false}, {DeviceLibExt::cl_intel_devicelib_math_fp64, false}, {DeviceLibExt::cl_intel_devicelib_complex, false}, - {DeviceLibExt::cl_intel_devicelib_complex_fp64, false}}; + {DeviceLibExt::cl_intel_devicelib_complex_fp64, false}, + {DeviceLibExt::cl_intel_devicelib_cstring, false}}; // Disable all devicelib extensions requiring fp64 support if at least // one underlying device doesn't support cl_khr_fp64. diff --git a/sycl/source/detail/program_manager/program_manager.hpp b/sycl/source/detail/program_manager/program_manager.hpp index 0b278c4a7056b..a4f43746d476f 100644 --- a/sycl/source/detail/program_manager/program_manager.hpp +++ b/sycl/source/detail/program_manager/program_manager.hpp @@ -57,7 +57,8 @@ enum class DeviceLibExt : std::uint32_t { cl_intel_devicelib_math, cl_intel_devicelib_math_fp64, cl_intel_devicelib_complex, - cl_intel_devicelib_complex_fp64 + cl_intel_devicelib_complex_fp64, + cl_intel_devicelib_cstring }; // Provides single loading and building OpenCL programs with unique contexts