Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4184,6 +4184,7 @@ class OffloadingActionBuilder final {
// default too.
SmallVector<DeviceLibOptInfo, 5> 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"},
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ static llvm::SmallVector<StringRef, 10> SYCLDeviceLibList{
"complex",
"complex-fp64",
"fallback-cassert",
"fallback-cstring",
"fallback-cmath",
"fallback-cmath-fp64",
"fallback-complex",
Expand Down
Empty file.
Empty file.
5 changes: 4 additions & 1 deletion clang/test/Driver/sycl-device-lib-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/sycl-device-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"

/// ###########################################################################

Expand Down Expand Up @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions libdevice/cmake/modules/SYCLLibdevice.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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} -S -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}
Expand All @@ -95,6 +104,15 @@ 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
${compile_opts}
Expand Down Expand Up @@ -210,13 +228,15 @@ 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
${spv_binary_dir}/libsycl-fallback-cmath-fp64.spv
)
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}
Expand All @@ -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}
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions libdevice/crt_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 '?'.
Expand Down
15 changes: 15 additions & 0 deletions libdevice/fallback-cstring.cpp
Original file line number Diff line number Diff line change
@@ -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__
3 changes: 2 additions & 1 deletion libdevice/wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion llvm/tools/sycl-post-link/SYCLDeviceLibReqMask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, DeviceLibExt>;
Expand Down
2 changes: 2 additions & 0 deletions sycl/include/CL/sycl/builtins.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
7 changes: 6 additions & 1 deletion sycl/source/detail/program_manager/program_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,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);
Expand All @@ -650,6 +652,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);
Expand Down Expand Up @@ -815,7 +819,8 @@ static std::vector<RT::PiProgram> 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.
Expand Down
3 changes: 2 additions & 1 deletion sycl/source/detail/program_manager/program_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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
Expand Down