From 9203c16391298a67e4d6c9890867bdcb8cf814ee Mon Sep 17 00:00:00 2001 From: gejin Date: Thu, 26 Nov 2020 15:37:21 +0800 Subject: [PATCH 1/8] Use mlink-builtin-bitcode to link sycl devicelibs Signed-off-by: gejin --- clang/lib/Driver/Driver.cpp | 107 +-------------------------- clang/lib/Driver/ToolChains/SYCL.cpp | 89 +++++++++++++++++++++- clang/lib/Driver/ToolChains/SYCL.h | 2 + 3 files changed, 92 insertions(+), 106 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 3064568a00940..19fbb577760ee 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5,6 +5,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// +#include #include "clang/Driver/Driver.h" #include "InputInfo.h" #include "ToolChains/AIX.h" @@ -3772,16 +3773,6 @@ class OffloadingActionBuilder final { for (auto SDA : SYCLDeviceActions) SYCLLinkBinaryList.push_back(SDA); if (WrapDeviceOnlyBinary) { - // If used without -fintelfpga, -fsycl-link is used to wrap device - // objects for future host link. Device libraries should be linked - // by default to resolve any undefined reference. - if (!Args.hasArg(options::OPT_fintelfpga)) { - const auto *TC = ToolChains.front(); - addSYCLDeviceLibs(TC, SYCLLinkBinaryList, true, - C.getDefaultToolChain() - .getTriple() - .isWindowsMSVCEnvironment()); - } // -fsycl-link behavior does the following to the unbundled device // binaries: // 1) Link them together using llvm-link @@ -3948,92 +3939,6 @@ class OffloadingActionBuilder final { SYCLDeviceActions.clear(); } - void addSYCLDeviceLibs(const ToolChain *TC, ActionList &DeviceLinkObjects, - bool isSpirvAOT, bool isMSVCEnv) { - enum SYCLDeviceLibType { - sycl_devicelib_wrapper, - sycl_devicelib_fallback - }; - struct DeviceLibOptInfo { - StringRef devicelib_name; - StringRef devicelib_option; - }; - - bool NoDeviceLibs = false; - // Currently, libc, libm-fp32 will be linked in by default. In order - // to use libm-fp64, -fsycl-device-lib=libm-fp64/all should be used. - llvm::StringMap devicelib_link_info = { - {"libc", true}, {"libm-fp32", true}, {"libm-fp64", false}}; - if (Arg *A = Args.getLastArg(options::OPT_fsycl_device_lib_EQ, - options::OPT_fno_sycl_device_lib_EQ)) { - if (A->getValues().size() == 0) - C.getDriver().Diag(diag::warn_drv_empty_joined_argument) - << A->getAsString(Args); - else { - if (A->getOption().matches(options::OPT_fno_sycl_device_lib_EQ)) - NoDeviceLibs = true; - - for (StringRef Val : A->getValues()) { - if (Val == "all") { - for (auto &K : devicelib_link_info.keys()) - devicelib_link_info[K] = true && !NoDeviceLibs; - break; - } - auto LinkInfoIter = devicelib_link_info.find(Val); - if (LinkInfoIter == devicelib_link_info.end()) { - C.getDriver().Diag(diag::err_drv_unsupported_option_argument) - << A->getOption().getName() << Val; - } - devicelib_link_info[Val] = true && !NoDeviceLibs; - } - } - } - - SmallString<128> LibLoc(TC->getDriver().Dir); - llvm::sys::path::append(LibLoc, "/../lib"); - StringRef LibSuffix = isMSVCEnv ? ".obj" : ".o"; - SmallVector sycl_device_wrapper_libs = { - {"libsycl-crt", "libc"}, - {"libsycl-complex", "libm-fp32"}, - {"libsycl-complex-fp64", "libm-fp64"}, - {"libsycl-cmath", "libm-fp32"}, - {"libsycl-cmath-fp64", "libm-fp64"}}; - // For AOT compilation, we need to link sycl_device_fallback_libs as - // default too. - SmallVector sycl_device_fallback_libs = { - {"libsycl-fallback-cassert", "libc"}, - {"libsycl-fallback-complex", "libm-fp32"}, - {"libsycl-fallback-complex-fp64", "libm-fp64"}, - {"libsycl-fallback-cmath", "libm-fp32"}, - {"libsycl-fallback-cmath-fp64", "libm-fp64"}}; - auto addInputs = [&](SYCLDeviceLibType t) { - auto sycl_libs = (t == sycl_devicelib_wrapper) - ? sycl_device_wrapper_libs - : sycl_device_fallback_libs; - for (const DeviceLibOptInfo &Lib : sycl_libs) { - if (!devicelib_link_info[Lib.devicelib_option]) - continue; - SmallString<128> LibName(LibLoc); - llvm::sys::path::append(LibName, Lib.devicelib_name); - llvm::sys::path::replace_extension(LibName, LibSuffix); - if (llvm::sys::fs::exists(LibName)) { - Arg *InputArg = MakeInputArg(Args, C.getDriver().getOpts(), - Args.MakeArgString(LibName)); - auto *SYCLDeviceLibsInputAction = - C.MakeAction(*InputArg, types::TY_Object); - auto *SYCLDeviceLibsUnbundleAction = - C.MakeAction( - SYCLDeviceLibsInputAction); - addDeviceDepences(SYCLDeviceLibsUnbundleAction); - DeviceLinkObjects.push_back(SYCLDeviceLibsUnbundleAction); - } - } - }; - addInputs(sycl_devicelib_wrapper); - if (isSpirvAOT) - addInputs(sycl_devicelib_fallback); - } - void appendLinkDependences(OffloadAction::DeviceDependences &DA) override { assert(ToolChains.size() == DeviceLinkerInputs.size() && "Toolchains and linker inputs sizes do not match."); @@ -4125,15 +4030,7 @@ class OffloadingActionBuilder final { else LinkObjects.push_back(Input); } - // FIXME: Link all wrapper and fallback device libraries as default, - // When spv online link is supported by all backends, the fallback - // device libraries are only needed when current toolchain is using - // AOT compilation. - if (!isNVPTX) { - addSYCLDeviceLibs( - *TC, LinkObjects, true, - C.getDefaultToolChain().getTriple().isWindowsMSVCEnvironment()); - } + // The linkage actions subgraph leading to the offload wrapper. // [cond] Means incoming/outgoing dependence is created only when cond // is true. A function of: diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index efe54a0445f23..a74f7c87aab44 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -5,7 +5,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// - +#include #include "SYCL.h" #include "CommonArgs.h" #include "InputInfo.h" @@ -417,10 +417,97 @@ SYCLToolChain::SYCLToolChain(const Driver &D, const llvm::Triple &Triple, getProgramPaths().push_back(getDriver().Dir); } +static bool doLLVMBCEmit(llvm::opt::ArgStringList &CC1Args) { + for (auto StrArg : CC1Args) + if (std::string(StrArg) == "-emit-llvm-bc") + return true; + return false; +} + +void SYCLToolChain::AddSYCLDeviceLibs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CC1Args) const { + enum SYCLDeviceLibType { sycl_devicelib_wrapper, sycl_devicelib_fallback }; + struct DeviceLibOptInfo { + StringRef devicelib_name; + StringRef devicelib_option; + }; + + bool NoDeviceLibs = false; + // Currently, libc, libm-fp32 will be linked in by default. In order + // to use libm-fp64, -fsycl-device-lib=libm-fp64/all should be used. + llvm::StringMap devicelib_link_info = { + {"libc", true}, {"libm-fp32", true}, {"libm-fp64", false}}; + if (Arg *A = Args.getLastArg(options::OPT_fsycl_device_lib_EQ, + options::OPT_fno_sycl_device_lib_EQ)) { + if (A->getValues().size() == 0) + getDriver().Diag(diag::warn_drv_empty_joined_argument) + << A->getAsString(Args); + else { + if (A->getOption().matches(options::OPT_fno_sycl_device_lib_EQ)) + NoDeviceLibs = true; + + for (StringRef Val : A->getValues()) { + if (Val == "all") { + for (auto &K : devicelib_link_info.keys()) + devicelib_link_info[K] = true && !NoDeviceLibs; + break; + } + auto LinkInfoIter = devicelib_link_info.find(Val); + if (LinkInfoIter == devicelib_link_info.end()) { + getDriver().Diag(diag::err_drv_unsupported_option_argument) + << A->getOption().getName() << Val; + } + devicelib_link_info[Val] = true && !NoDeviceLibs; + } + } + } + bool isSpirvAOT = true; + SmallString<128> LibLoc(getDriver().Dir); + llvm::sys::path::append(LibLoc, "/../lib"); + SmallVector sycl_device_wrapper_libs = { + {"libsycl-crt", "libc"}, + {"libsycl-complex", "libm-fp32"}, + {"libsycl-complex-fp64", "libm-fp64"}, + {"libsycl-cmath", "libm-fp32"}, + {"libsycl-cmath-fp64", "libm-fp64"}}; + // For AOT compilation, we need to link sycl_device_fallback_libs as + // default too. + SmallVector sycl_device_fallback_libs = { + {"libsycl-fallback-cassert", "libc"}, + {"libsycl-fallback-complex", "libm-fp32"}, + {"libsycl-fallback-complex-fp64", "libm-fp64"}, + {"libsycl-fallback-cmath", "libm-fp32"}, + {"libsycl-fallback-cmath-fp64", "libm-fp64"}}; + + auto addInputs = [&](SYCLDeviceLibType t, StringRef SYCLArchName) { + auto sycl_libs = (t == sycl_devicelib_wrapper) ? sycl_device_wrapper_libs + : sycl_device_fallback_libs; + for (const DeviceLibOptInfo &Lib : sycl_libs) { + if (!devicelib_link_info[Lib.devicelib_option]) + continue; + SmallString<128> LibName(LibLoc); + llvm::sys::path::append(LibName, Lib.devicelib_name); + LibName.append("-"); + LibName.append(SYCLArchName); + llvm::sys::path::replace_extension(LibName, ".bc"); + std::cout << LibName.c_str() << " **********" << std::endl; + if (llvm::sys::fs::exists(LibName)) { + CC1Args.push_back("-mlink-builtin-bitcode"); + CC1Args.push_back(Args.MakeArgString(LibName.c_str())); + } + } + }; + addInputs(sycl_devicelib_wrapper, getTriple().getArchName()); + if (isSpirvAOT) + addInputs(sycl_devicelib_fallback, getTriple().getArchName()); +} + void SYCLToolChain::addClangTargetOptions( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadingKind) const { + if (DeviceOffloadingKind == Action::OFK_SYCL && doLLVMBCEmit(CC1Args)) + AddSYCLDeviceLibs(DriverArgs, CC1Args); HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind); } diff --git a/clang/lib/Driver/ToolChains/SYCL.h b/clang/lib/Driver/ToolChains/SYCL.h index 975c9127c89f8..a33d1b76691a0 100644 --- a/clang/lib/Driver/ToolChains/SYCL.h +++ b/clang/lib/Driver/ToolChains/SYCL.h @@ -162,6 +162,8 @@ class LLVM_LIBRARY_VISIBILITY SYCLToolChain : public ToolChain { void TranslateTargetOpt(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, llvm::opt::OptSpecifier Opt, llvm::opt::OptSpecifier Opt_EQ) const; + void AddSYCLDeviceLibs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const; }; } // end namespace toolchains From f12fcc88307d0344c7c2394dc2b5fc47afdc6c29 Mon Sep 17 00:00:00 2001 From: gejin Date: Mon, 30 Nov 2020 15:27:26 +0800 Subject: [PATCH 2/8] convert device libs to LLVM BC Signed-off-by: gejin --- clang/lib/Driver/ToolChains/SYCL.cpp | 2 - libdevice/cmake/modules/SYCLLibdevice.cmake | 362 +++++++++++--------- 2 files changed, 192 insertions(+), 172 deletions(-) diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index a74f7c87aab44..57e8febcae01c 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -5,7 +5,6 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// -#include #include "SYCL.h" #include "CommonArgs.h" #include "InputInfo.h" @@ -490,7 +489,6 @@ void SYCLToolChain::AddSYCLDeviceLibs(const llvm::opt::ArgList &Args, LibName.append("-"); LibName.append(SYCLArchName); llvm::sys::path::replace_extension(LibName, ".bc"); - std::cout << LibName.c_str() << " **********" << std::endl; if (llvm::sys::fs::exists(LibName)) { CC1Args.push_back("-mlink-builtin-bitcode"); CC1Args.push_back(Args.MakeArgString(LibName.c_str())); diff --git a/libdevice/cmake/modules/SYCLLibdevice.cmake b/libdevice/cmake/modules/SYCLLibdevice.cmake index 00bb9435a1b37..4f272104357e7 100644 --- a/libdevice/cmake/modules/SYCLLibdevice.cmake +++ b/libdevice/cmake/modules/SYCLLibdevice.cmake @@ -1,22 +1,13 @@ set(obj_binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") if (WIN32) - set(lib-suffix obj) set(spv_binary_dir "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") - set(lib_crt_source msvc_wrapper.cpp) + set(libcrt_source msvc_wrapper.cpp) else() - set(lib-suffix o) set(spv_binary_dir "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") - set(lib_crt_source glibc_wrapper.cpp) + set(libcrt_source glibc_wrapper.cpp) endif() set(clang $) -string(CONCAT sycl_targets_opt - "-fsycl-targets=" - "spir64_x86_64-unknown-unknown-sycldevice," - "spir64_gen-unknown-unknown-sycldevice," - "spir64_fpga-unknown-unknown-sycldevice," - "spir64-unknown-unknown-sycldevice") - set(compile_opts # suppress an error about SYCL_EXTERNAL being used for # a function with a raw pointer parameter. @@ -29,152 +20,138 @@ set(compile_opts -sycl-std=2017 ) -set(devicelib-obj-file ${obj_binary_dir}/libsycl-crt.${lib-suffix}) -add_custom_command(OUTPUT ${devicelib-obj-file} - COMMAND ${clang} -fsycl -c - ${compile_opts} ${sycl_targets_opt} - ${CMAKE_CURRENT_SOURCE_DIR}/${lib_crt_source} - -o ${devicelib-obj-file} - MAIN_DEPENDENCY ${lib_crt_source} - DEPENDS wrapper.h device.h spirv_vars.h clang clang-offload-bundler - VERBATIM) - -set(devicelib-obj-complex ${obj_binary_dir}/libsycl-complex.${lib-suffix}) -add_custom_command(OUTPUT ${devicelib-obj-complex} - COMMAND ${clang} -fsycl -c - ${compile_opts} ${sycl_targets_opt} - ${CMAKE_CURRENT_SOURCE_DIR}/complex_wrapper.cpp - -o ${devicelib-obj-complex} - MAIN_DEPENDENCY complex_wrapper.cpp - DEPENDS device_complex.h device.h clang clang-offload-bundler - VERBATIM) - -set(devicelib-obj-complex-fp64 ${obj_binary_dir}/libsycl-complex-fp64.${lib-suffix}) -add_custom_command(OUTPUT ${devicelib-obj-complex-fp64} - COMMAND ${clang} -fsycl -c - ${compile_opts} ${sycl_targets_opt} - ${CMAKE_CURRENT_SOURCE_DIR}/complex_wrapper_fp64.cpp - -o ${devicelib-obj-complex-fp64} - MAIN_DEPENDENCY complex_wrapper_fp64.cpp - DEPENDS device_complex.h device.h clang clang-offload-bundler - VERBATIM) - -set(devicelib-obj-cmath ${obj_binary_dir}/libsycl-cmath.${lib-suffix}) -add_custom_command(OUTPUT ${devicelib-obj-cmath} - COMMAND ${clang} -fsycl -c - ${compile_opts} ${sycl_targets_opt} - ${CMAKE_CURRENT_SOURCE_DIR}/cmath_wrapper.cpp - -o ${devicelib-obj-cmath} - MAIN_DEPENDENCY cmath_wrapper.cpp - DEPENDS device_math.h device.h clang clang-offload-bundler - VERBATIM) - -set(devicelib-obj-cmath-fp64 ${obj_binary_dir}/libsycl-cmath-fp64.${lib-suffix}) -add_custom_command(OUTPUT ${devicelib-obj-cmath-fp64} - COMMAND ${clang} -fsycl -c - ${compile_opts} ${sycl_targets_opt} - ${CMAKE_CURRENT_SOURCE_DIR}/cmath_wrapper_fp64.cpp - -o ${devicelib-obj-cmath-fp64} - MAIN_DEPENDENCY cmath_wrapper_fp64.cpp - DEPENDS device_math.h device.h clang clang-offload-bundler - VERBATIM) - -add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-cassert.spv - COMMAND ${clang} -S -fsycl-device-only -fno-sycl-use-bitcode - ${compile_opts} - ${CMAKE_CURRENT_SOURCE_DIR}/fallback-cassert.cpp - -o ${spv_binary_dir}/libsycl-fallback-cassert.spv - MAIN_DEPENDENCY fallback-cassert.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} - ${CMAKE_CURRENT_SOURCE_DIR}/fallback-cassert.cpp - -o ${obj_binary_dir}/libsycl-fallback-cassert.${lib-suffix} - MAIN_DEPENDENCY fallback-cassert.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} - ${CMAKE_CURRENT_SOURCE_DIR}/fallback-complex.cpp - -o ${spv_binary_dir}/libsycl-fallback-complex.spv - MAIN_DEPENDENCY fallback-complex.cpp - DEPENDS device_math.h device_complex.h device.h clang llvm-spirv - VERBATIM) - -add_custom_command(OUTPUT ${obj_binary_dir}/libsycl-fallback-complex.${lib-suffix} - COMMAND ${clang} -fsycl -c - ${compile_opts} ${sycl_targets_opt} - ${CMAKE_CURRENT_SOURCE_DIR}/fallback-complex.cpp - -o ${obj_binary_dir}/libsycl-fallback-complex.${lib-suffix} - MAIN_DEPENDENCY fallback-complex.cpp - DEPENDS device_math.h device_complex.h device.h clang clang-offload-bundler - VERBATIM) - -add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-complex-fp64.spv - COMMAND ${clang} -S -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 - MAIN_DEPENDENCY fallback-complex-fp64.cpp - DEPENDS device_math.h device_complex.h device.h clang llvm-spirv - VERBATIM) - -add_custom_command(OUTPUT ${obj_binary_dir}/libsycl-fallback-complex-fp64.${lib-suffix} - COMMAND ${clang} -fsycl -c - ${compile_opts} ${sycl_targets_opt} - ${CMAKE_CURRENT_SOURCE_DIR}/fallback-complex-fp64.cpp - -o ${obj_binary_dir}/libsycl-fallback-complex-fp64.${lib-suffix} - MAIN_DEPENDENCY fallback-complex-fp64.cpp - DEPENDS device_math.h device_complex.h device.h clang clang-offload-bundler - VERBATIM) - -add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-cmath.spv - COMMAND ${clang} -S -fsycl-device-only -fno-sycl-use-bitcode - ${compile_opts} - ${CMAKE_CURRENT_SOURCE_DIR}/fallback-cmath.cpp - -o ${spv_binary_dir}/libsycl-fallback-cmath.spv - MAIN_DEPENDENCY fallback-cmath.cpp - DEPENDS device_math.h device.h clang llvm-spirv - VERBATIM) - -add_custom_command(OUTPUT ${obj_binary_dir}/libsycl-fallback-cmath.${lib-suffix} - COMMAND ${clang} -fsycl -c - ${compile_opts} ${sycl_targets_opt} - ${CMAKE_CURRENT_SOURCE_DIR}/fallback-cmath.cpp - -o ${obj_binary_dir}/libsycl-fallback-cmath.${lib-suffix} - MAIN_DEPENDENCY fallback-cmath.cpp - DEPENDS device_math.h device.h clang clang-offload-bundler - VERBATIM) - -add_custom_command(OUTPUT ${spv_binary_dir}/libsycl-fallback-cmath-fp64.spv - COMMAND ${clang} -S -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 - MAIN_DEPENDENCY fallback-cmath-fp64.cpp - DEPENDS device_math.h device.h clang llvm-spirv - VERBATIM) - -add_custom_command(OUTPUT ${obj_binary_dir}/libsycl-fallback-cmath-fp64.${lib-suffix} - COMMAND ${clang} -fsycl -c - ${compile_opts} ${sycl_targets_opt} - ${CMAKE_CURRENT_SOURCE_DIR}/fallback-cmath-fp64.cpp - -o ${obj_binary_dir}/libsycl-fallback-cmath-fp64.${lib-suffix} - MAIN_DEPENDENCY fallback-cmath-fp64.cpp - DEPENDS device_math.h device.h clang clang-offload-bundler - VERBATIM) +function(BuildSYCLDeviceLib) + cmake_parse_arguments(DeviceLib "" "Path;Target;Source" "Depends" ${ARGN}) + add_custom_command(OUTPUT ${DeviceLib_Path} + COMMAND ${clang} -fsycl -fsycl-device-only -emit-llvm + ${compile_opts} -fsycl-targets=${DeviceLib_Target} + ${CMAKE_CURRENT_SOURCE_DIR}/${DeviceLib_Source} + -o ${DeviceLib_Path} -fno-sycl-device-lib=all + MAIN_DEPENDENCY ${DeviceLib_Source} + DEPENDS ${DeviceLib_Depends} + VERBATIM) +endfunction() + + +set(devicelib-wrapper-crt-spir64 ${obj_binary_dir}/libsycl-crt-spir64.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-crt-spir64} Target spir64-unknown-unknown-sycldevice Source ${libcrt_source} Depends wrapper.h device.h spirv_vars.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-spir64.bc Target spir64-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends wrapper.h device.h spirv_vars.h clang) + +set(devicelib-wrapper-crt-spir64_x86_64 ${obj_binary_dir}/libsycl-crt-spir64_x86_64.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-crt-spir64_x86_64} Target spir64_x86_64-unknown-unknown-sycldevice Source ${libcrt_source} Depends wrapper.h device.h spirv_vars.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-spir64_x86_64.bc Target spir64_x86_64-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends wrapper.h device.h spirv_vars.h clang) + +set(devicelib-wrapper-crt-spir64_gen ${obj_binary_dir}/libsycl-crt-spir64_gen.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-crt-spir64_gen} Target spir64_gen-unknown-unknown-sycldevice Source ${libcrt_source} Depends wrapper.h device.h spirv_vars.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-spir64_gen.bc Target spir64_gen-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends wrapper.h device.h spirv_vars.h clang) + +set(devicelib-wrapper-crt-spir64_fpga ${obj_binary_dir}/libsycl-crt-spir64_fpga.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-crt-spir64_fpga} Target spir64_fpga-unknown-unknown-sycldevice Source ${libcrt_source} Depends wrapper.h device.h spirv_vars.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-spir64_fpga.bc Target spir64_fpga-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends wrapper.h device.h spirv_vars.h clang) + +set(devicelib-wrapper-complex-spir64 ${obj_binary_dir}/libsycl-complex-spir64.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-spir64} Target spir64-unknown-unknown-sycldevice Source complex_wrapper.cpp Depends device_complex.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-spir64.bc Target spir64-unknown-unknown-sycldevice Source fallback-complex.cpp Depends device_math.h device_complex.h device.h clang) + +set(devicelib-wrapper-complex-spir64_x86_64 ${obj_binary_dir}/libsycl-complex-spir64_x86_64.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-spir64_x86_64} Target spir64_x86_64-unknown-unknown-sycldevice Source complex_wrapper.cpp Depends device_complex.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-spir64_x86_64.bc Target spir64_x86_64-unknown-unknown-sycldevice Source fallback-complex.cpp Depends device_math.h device_complex.h device.h clang) + +set(devicelib-wrapper-complex-spir64_gen ${obj_binary_dir}/libsycl-complex-spir64_gen.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-spir64_gen} Target spir64_gen-unknown-unknown-sycldevice Source complex_wrapper.cpp Depends device_complex.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-spir64_gen.bc Target spir64_gen-unknown-unknown-sycldevice Source fallback-complex.cpp Depends device_math.h device_complex.h device.h clang) + +set(devicelib-wrapper-complex-spir64_fpga ${obj_binary_dir}/libsycl-complex-spir64_fpga.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-spir64_fpga} Target spir64_fpga-unknown-unknown-sycldevice Source complex_wrapper.cpp Depends device_complex.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-spir64_fpga.bc Target spir64_fpga-unknown-unknown-sycldevice Source fallback-complex.cpp Depends device_math.h device_complex.h device.h clang) + +set(devicelib-wrapper-complex-fp64-spir64 ${obj_binary_dir}/libsycl-complex-fp64-spir64.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-fp64-spir64} Target spir64-unknown-unknown-sycldevice Source complex_wrapper_fp64.cpp Depends device_complex.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64.bc Target spir64-unknown-unknown-sycldevice Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h device.h clang) + +set(devicelib-wrapper-complex-fp64-spir64_x86_64 ${obj_binary_dir}/libsycl-complex-fp64-spir64_x86_64.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-fp64-spir64_x86_64} Target spir64_x86_64-unknown-unknown-sycldevice Source complex_wrapper_fp64.cpp Depends device_complex.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_x86_64.bc Target spir64_x86_64-unknown-unknown-sycldevice Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h device.h clang) + +set(devicelib-wrapper-complex-fp64-spir64_gen ${obj_binary_dir}/libsycl-complex-fp64-spir64_gen.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-fp64-spir64_gen} Target spir64_gen-unknown-unknown-sycldevice Source complex_wrapper_fp64.cpp Depends device_complex.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_gen.bc Target spir64_gen-unknown-unknown-sycldevice Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h device.h clang) + +set(devicelib-wrapper-complex-fp64-spir64_fpga ${obj_binary_dir}/libsycl-complex-fp64-spir64_fpga.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-fp64-spir64_fpga} Target spir64_fpga-unknown-unknown-sycldevice Source complex_wrapper_fp64.cpp Depends device_complex.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_fpga.bc Target spir64_fpga-unknown-unknown-sycldevice Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h device.h clang) + +set(devicelib-wrapper-cmath-spir64 ${obj_binary_dir}/libsycl-cmath-spir64.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-spir64} Target spir64-unknown-unknown-sycldevice Source cmath_wrapper.cpp Depends device_math.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-spir64.bc Target spir64-unknown-unknown-sycldevice Source fallback-cmath.cpp Depends device_math.h device.h clang) + +set(devicelib-wrapper-cmath-spir64_x86_64 ${obj_binary_dir}/libsycl-cmath-spir64_x86_64.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-spir64_x86_64} Target spir64_x86_64-unknown-unknown-sycldevice Source cmath_wrapper.cpp Depends device_math.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-spir64_x86_64.bc Target spir64_x86_64-unknown-unknown-sycldevice Source fallback-cmath.cpp Depends device_math.h device.h clang) + +set(devicelib-wrapper-cmath-spir64_gen ${obj_binary_dir}/libsycl-cmath-spir64_gen.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-spir64_gen} Target spir64_gen-unknown-unknown-sycldevice Source cmath_wrapper.cpp Depends device_math.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-spir64_gen.bc Target spir64_gen-unknown-unknown-sycldevice Source fallback-cmath.cpp Depends device_math.h device.h clang) + +set(devicelib-wrapper-cmath-spir64_fpga ${obj_binary_dir}/libsycl-cmath-spir64_fpga.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-spir64_fpga} Target spir64_fpga-unknown-unknown-sycldevice Source cmath_wrapper.cpp Depends device_math.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-spir64_fpga.bc Target spir64_fpga-unknown-unknown-sycldevice Source fallback-cmath.cpp Depends device_math.h device.h clang) + +set(devicelib-wrapper-cmath-fp64-spir64 ${obj_binary_dir}/libsycl-cmath-fp64-spir64.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-fp64-spir64} Target spir64-unknown-unknown-sycldevice Source cmath_wrapper_fp64.cpp Depends device_math.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64.bc Target spir64-unknown-unknown-sycldevice Source fallback-cmath-fp64.cpp Depends device_math.h device.h clang) + +set(devicelib-wrapper-cmath-fp64-spir64_x86_64 ${obj_binary_dir}/libsycl-cmath-fp64-spir64_x86_64.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-fp64-spir64_x86_64} Target spir64_x86_64-unknown-unknown-sycldevice Source cmath_wrapper_fp64.cpp Depends device_math.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_x86_64.bc Target spir64_x86_64-unknown-unknown-sycldevice Source fallback-cmath-fp64.cpp Depends device_math.h device.h clang) + +set(devicelib-wrapper-cmath-fp64-spir64_gen ${obj_binary_dir}/libsycl-cmath-fp64-spir64_gen.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-fp64-spir64_gen} Target spir64_gen-unknown-unknown-sycldevice Source cmath_wrapper_fp64.cpp Depends device_math.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_gen.bc Target spir64_gen-unknown-unknown-sycldevice Source fallback-cmath-fp64.cpp Depends device_math.h device.h clang) + +set(devicelib-wrapper-cmath-fp64-spir64_fpga ${obj_binary_dir}/libsycl-cmath-fp64-spir64_fpga.bc) +BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-fp64-spir64_fpga} Target spir64_fpga-unknown-unknown-sycldevice Source cmath_wrapper_fp64.cpp Depends device_math.h device.h clang) +BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_fpga.bc Target spir64_fpga-unknown-unknown-sycldevice Source fallback-cmath-fp64.cpp Depends device_math.h device.h clang) + +function(BuildSYCLFallbackDeviceLib) + cmake_parse_arguments(DeviceLib "" "Path;Source" "Depends" ${ARGN}) + add_custom_command(OUTPUT ${DeviceLib_Path} + COMMAND ${clang} -S -fsycl-device-only -fno-sycl-use-bitcode + ${compile_opts} + ${CMAKE_CURRENT_SOURCE_DIR}/${DeviceLib_Source} + -o ${DeviceLib_Path} -fno-sycl-device-lib=all + MAIN_DEPENDENCY ${DeviceLib_Source} + DEPENDS ${DeviceLib_Depends} + VERBATIM) +endfunction() + +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cassert.spv Source fallback-cassert.cpp Depends wrapper.h device.h clang spirv_vars.h llvm-spirv) +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-complex.spv Source fallback-complex.cpp Depends device_math.h device_complex.h device.h clang llvm-spirv) +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-complex-fp64.spv Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h device.h clang llvm-spirv) +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cmath.spv Source fallback-cmath.cpp Depends device_math.h device.h clang llvm-spirv) +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cmath-fp64.spv Source fallback-cmath-fp64.cpp Depends device_math.h device.h clang llvm-spirv) add_custom_target(libsycldevice-obj DEPENDS - ${devicelib-obj-file} - ${devicelib-obj-complex} - ${devicelib-obj-complex-fp64} - ${devicelib-obj-cmath} - ${devicelib-obj-cmath-fp64} + ${devicelib-wrapper-crt-spir64} + ${devicelib-wrapper-crt-spir64_x86_64} + ${devicelib-wrapper-crt-spir64_gen} + ${devicelib-wrapper-crt-spir64_fpga} + ${devicelib-wrapper-complex-spir64} + ${devicelib-wrapper-complex-spir64_x86_64} + ${devicelib-wrapper-complex-spir64_gen} + ${devicelib-wrapper-complex-spir64_fpga} + ${devicelib-wrapper-complex-fp64-spir64} + ${devicelib-wrapper-complex-fp64-spir64_x86_64} + ${devicelib-wrapper-complex-fp64-spir64_gen} + ${devicelib-wrapper-complex-fp64-spir64_fpga} + ${devicelib-wrapper-cmath-spir64} + ${devicelib-wrapper-cmath-spir64_x86_64} + ${devicelib-wrapper-cmath-spir64_gen} + ${devicelib-wrapper-cmath-spir64_fpga} + ${devicelib-wrapper-cmath-fp64-spir64} + ${devicelib-wrapper-cmath-fp64-spir64_x86_64} + ${devicelib-wrapper-cmath-fp64-spir64_gen} + ${devicelib-wrapper-cmath-fp64-spir64_fpga} ) add_custom_target(libsycldevice-spv DEPENDS ${spv_binary_dir}/libsycl-fallback-cassert.spv @@ -184,11 +161,26 @@ add_custom_target(libsycldevice-spv DEPENDS ${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-complex.${lib-suffix} - ${obj_binary_dir}/libsycl-fallback-complex-fp64.${lib-suffix} - ${obj_binary_dir}/libsycl-fallback-cmath.${lib-suffix} - ${obj_binary_dir}/libsycl-fallback-cmath-fp64.${lib-suffix} + ${obj_binary_dir}/libsycl-fallback-cassert-spir64.bc + ${obj_binary_dir}/libsycl-fallback-cassert-spir64_x86_64.bc + ${obj_binary_dir}/libsycl-fallback-cassert-spir64_gen.bc + ${obj_binary_dir}/libsycl-fallback-cassert-spir64_fpga.bc + ${obj_binary_dir}/libsycl-fallback-complex-spir64.bc + ${obj_binary_dir}/libsycl-fallback-complex-spir64_x86_64.bc + ${obj_binary_dir}/libsycl-fallback-complex-spir64_gen.bc + ${obj_binary_dir}/libsycl-fallback-complex-spir64_fpga.bc + ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64.bc + ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_x86_64.bc + ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_gen.bc + ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_fpga.bc + ${obj_binary_dir}/libsycl-fallback-cmath-spir64.bc + ${obj_binary_dir}/libsycl-fallback-cmath-spir64_x86_64.bc + ${obj_binary_dir}/libsycl-fallback-cmath-spir64_gen.bc + ${obj_binary_dir}/libsycl-fallback-cmath-spir64_fpga.bc + ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64.bc + ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_x86_64.bc + ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_gen.bc + ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_fpga.bc ) add_custom_target(libsycldevice DEPENDS libsycldevice-obj @@ -205,16 +197,46 @@ endif() set(install_dest_lib lib${LLVM_LIBDIR_SUFFIX}) -install(FILES ${devicelib-obj-file} - ${obj_binary_dir}/libsycl-fallback-cassert.${lib-suffix} - ${devicelib-obj-complex} - ${obj_binary_dir}/libsycl-fallback-complex.${lib-suffix} - ${devicelib-obj-complex-fp64} - ${obj_binary_dir}/libsycl-fallback-complex-fp64.${lib-suffix} - ${devicelib-obj-cmath} - ${obj_binary_dir}/libsycl-fallback-cmath.${lib-suffix} - ${devicelib-obj-cmath-fp64} - ${obj_binary_dir}/libsycl-fallback-cmath-fp64.${lib-suffix} +install(FILES ${devicelib-wrapper-crt-spir64} + ${devicelib-wrapper-crt-spir64_x86_64} + ${devicelib-wrapper-crt-spir64_gen} + ${devicelib-wrapper-crt-spir64_fpga} + ${obj_binary_dir}/libsycl-fallback-cassert-spir64.bc + ${obj_binary_dir}/libsycl-fallback-cassert-spir64_x86_64.bc + ${obj_binary_dir}/libsycl-fallback-cassert-spir64_gen.bc + ${obj_binary_dir}/libsycl-fallback-cassert-spir64_fpga.bc + ${devicelib-wrapper-complex-spir64} + ${devicelib-wrapper-complex-spir64_x86_64} + ${devicelib-wrapper-complex-spir64_gen} + ${devicelib-wrapper-complex-spir64_fpga} + ${obj_binary_dir}/libsycl-fallback-complex-spir64.bc + ${obj_binary_dir}/libsycl-fallback-complex-spir64_x86_64.bc + ${obj_binary_dir}/libsycl-fallback-complex-spir64_gen.bc + ${obj_binary_dir}/libsycl-fallback-complex-spir64_fpga.bc + ${devicelib-wrapper-complex-fp64-spir64} + ${devicelib-wrapper-complex-fp64-spir64_x86_64} + ${devicelib-wrapper-complex-fp64-spir64_gen} + ${devicelib-wrapper-complex-fp64-spir64_fpga} + ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64.bc + ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_x86_64.bc + ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_gen.bc + ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_fpga.bc + ${devicelib-wrapper-cmath-spir64} + ${devicelib-wrapper-cmath-spir64_x86_64} + ${devicelib-wrapper-cmath-spir64_gen} + ${devicelib-wrapper-cmath-spir64_fpga} + ${obj_binary_dir}/libsycl-fallback-cmath-spir64.bc + ${obj_binary_dir}/libsycl-fallback-cmath-spir64_x86_64.bc + ${obj_binary_dir}/libsycl-fallback-cmath-spir64_gen.bc + ${obj_binary_dir}/libsycl-fallback-cmath-spir64_fpga.bc + ${devicelib-wrapper-cmath-fp64-spir64} + ${devicelib-wrapper-cmath-fp64-spir64_x86_64} + ${devicelib-wrapper-cmath-fp64-spir64_gen} + ${devicelib-wrapper-cmath-fp64-spir64_fpga} + ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64.bc + ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_x86_64.bc + ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_gen.bc + ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_fpga.bc DESTINATION ${install_dest_lib} COMPONENT libsycldevice) From b0a57d93b7a26eb0b9c4bdba4f92a736c37ca103 Mon Sep 17 00:00:00 2001 From: gejin Date: Mon, 30 Nov 2020 15:37:09 +0800 Subject: [PATCH 3/8] Fix clang format issue Signed-off-by: gejin --- clang/lib/Driver/Driver.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 19fbb577760ee..b2b303fd10bcd 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5,7 +5,6 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// -#include #include "clang/Driver/Driver.h" #include "InputInfo.h" #include "ToolChains/AIX.h" From 2820a5495d0741fb0f0ed5df9402ccdad8bd3813 Mon Sep 17 00:00:00 2001 From: gejin Date: Wed, 2 Dec 2020 14:45:43 +0800 Subject: [PATCH 4/8] Fix lit test failure Signed-off-by: gejin --- clang/test/Driver/sycl-intelfpga-static-lib.cpp | 2 +- clang/test/Driver/sycl-offload-intelfpga.cpp | 2 +- clang/test/Driver/sycl-offload-static-lib.cpp | 2 +- clang/test/Driver/sycl-offload-win.c | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/clang/test/Driver/sycl-intelfpga-static-lib.cpp b/clang/test/Driver/sycl-intelfpga-static-lib.cpp index 1a77afd98465a..a6d7149d014fb 100644 --- a/clang/test/Driver/sycl-intelfpga-static-lib.cpp +++ b/clang/test/Driver/sycl-intelfpga-static-lib.cpp @@ -6,7 +6,7 @@ // make dummy archive // Build a fat static lib that will be used for all tests // RUN: echo "void foo(void) {}" > %t1.cpp -// RUN: %clangxx -target x86_64-unknown-linux-gnu -fintelfpga -fsycl %t1.cpp -c -o %t1_bundle.o +// RUN: %clangxx -target x86_64-unknown-linux-gnu -fintelfpga -fsycl -fno-sycl-device-lib=all %t1.cpp -c -o %t1_bundle.o // RUN: llvm-ar cr %t.a %t1_bundle.o /// Check phases with static lib diff --git a/clang/test/Driver/sycl-offload-intelfpga.cpp b/clang/test/Driver/sycl-offload-intelfpga.cpp index d2e35466bf2e4..a6eb8f19a6056 100644 --- a/clang/test/Driver/sycl-offload-intelfpga.cpp +++ b/clang/test/Driver/sycl-offload-intelfpga.cpp @@ -356,7 +356,7 @@ // RUN: echo "void foo2() {}" > %t2.c // RUN: %clang -c -o %t.o %t.c // RUN: %clang -fsycl -c -o %t2.o %t2.c -// RUN: %clang_cl -fsycl -c -o %t2_cl.o %t2.c +// RUN: %clang_cl -fsycl -c -o %t2_cl.o %t2.c -fno-sycl-device-lib=all // RUN: clang-offload-wrapper -o %t-aoco.bc -host=x86_64-unknown-linux-gnu -kind=sycl -target=fpga_aoco-intel-unknown-sycldevice %t.aoco // RUN: llc -filetype=obj -o %t-aoco.o %t-aoco.bc // RUN: clang-offload-wrapper -o %t-aoco_cl.bc -host=x86_64-unknown-linux-gnu -kind=sycl -target=fpga_aoco-intel-unknown-sycldevice %t.aoco diff --git a/clang/test/Driver/sycl-offload-static-lib.cpp b/clang/test/Driver/sycl-offload-static-lib.cpp index 95cb56245d539..9829749f14936 100644 --- a/clang/test/Driver/sycl-offload-static-lib.cpp +++ b/clang/test/Driver/sycl-offload-static-lib.cpp @@ -7,7 +7,7 @@ /// test behaviors of passing a fat static lib // Build a fat static lib that will be used for all tests // RUN: echo "void foo(void) {}" > %t1.cpp -// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl %t1.cpp -c -o %t1_bundle.o +// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-device-lib=all %t1.cpp -c -o %t1_bundle.o // RUN: llvm-ar cr %t.a %t1_bundle.o // RUN: llvm-ar cr %t_2.a %t1_bundle.o diff --git a/clang/test/Driver/sycl-offload-win.c b/clang/test/Driver/sycl-offload-win.c index 9071d99f1a7bd..e418c40c9b90d 100644 --- a/clang/test/Driver/sycl-offload-win.c +++ b/clang/test/Driver/sycl-offload-win.c @@ -8,11 +8,11 @@ /// Test behaviors of -foffload-static-lib= with single object. // Build the offload library that is used for the tests. // RUN: echo "void foo() {}" > %t.c -// RUN: %clang_cl -fsycl -c -Fo%t.obj %t.c +// RUN: %clang_cl -fsycl -c -Fo%t.obj %t.c -fno-sycl-device-lib=all // RUN: llvm-ar cr %t.lib %t.obj // RUN: %clang --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t.lib %t.obj -### 2>&1 \ // RUN: | FileCheck -DOBJ=%t.obj -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB -// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t.lib %t.obj -### 2>&1 \ +// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -fno-sycl-device-lib=all -foffload-static-lib=%t.lib %t.obj -### 2>&1 \ // RUN: | FileCheck -DOBJ=%t.obj -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB // FOFFLOAD_STATIC_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o" "-targets=host-x86_64-pc-windows-msvc,sycl-spir64-unknown-unknown-sycldevice" "-inputs=[[OBJ]]" "-outputs={{.+}}.{{(o|obj)}},{{.+}}.{{(o|obj)}}" "-unbundle" // FOFFLOAD_STATIC_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB]]"{{.+}} "-unbundle" @@ -28,7 +28,7 @@ // RUN: touch %t-3.obj // RUN: %clang --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t.lib %t-1.obj %t-2.obj %t-3.obj -### 2>&1 \ // RUN: | FileCheck -DOBJ1=%t-1.obj -DOBJ2=%t-2.obj -DOBJ3=%t-3.obj -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB_MULTI_O -// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t.lib %t-1.obj %t-2.obj %t-3.obj -### 2>&1 \ +// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -fno-sycl-device-lib=all -foffload-static-lib=%t.lib %t-1.obj %t-2.obj %t-3.obj -### 2>&1 \ // RUN: | FileCheck -DOBJ1=%t-1.obj -DOBJ2=%t-2.obj -DOBJ3=%t-3.obj -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB_MULTI_O // FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ1]]"{{.+}} "-unbundle" // FOFFLOAD_STATIC_LIB_MULTI_O: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ2]]"{{.+}} "-unbundle" @@ -45,7 +45,7 @@ // RUN: touch %t.obj // RUN: %clang --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t1.lib -foffload-static-lib=%t2.lib %t.obj -### 2>&1 \ // RUN: | FileCheck -DOBJ=%t.obj -DLIB1=%t1.lib -DLIB2=%t2.lib %s -check-prefix=FOFFLOAD_STATIC_MULTI_LIB -// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t1.lib -foffload-static-lib=%t2.lib %t.obj -### 2>&1 \ +// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -fno-sycl-device-lib=all -foffload-static-lib=%t1.lib -foffload-static-lib=%t2.lib %t.obj -### 2>&1 \ // RUN: | FileCheck -DOBJ=%t.obj -DLIB1=%t1.lib -DLIB2=%t2.lib %s -check-prefix=FOFFLOAD_STATIC_MULTI_LIB // FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=o"{{.+}} "-inputs=[[OBJ]]"{{.+}} "-unbundle" // FOFFLOAD_STATIC_MULTI_LIB: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB1]]"{{.+}} "-unbundle" @@ -89,14 +89,14 @@ // RUN: touch %t.lib // RUN: %clang --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t.lib %s -### 2>&1 \ // RUN: | FileCheck -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC2 -// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -foffload-static-lib=%t.lib %s -### 2>&1 \ +// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -fno-sycl-device-lib=all -foffload-static-lib=%t.lib %s -### 2>&1 \ // RUN: | FileCheck -DLIB=%t.lib %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC2 // FOFFLOAD_STATIC_LIB_SRC2: clang-offload-bundler{{(.exe)?}}{{.+}} "-type=aoo" "-targets=sycl-spir64-{{.+}}-sycldevice" "-inputs=[[LIB]]"{{.+}} "-unbundle" // FOFFLOAD_STATIC_LIB_SRC2: llvm-link{{(.exe)?}}{{.*}} "@{{.*}}" // FOFFLOAD_STATIC_LIB_SRC2: link{{(.exe)?}}{{.+}} "-defaultlib:[[LIB]]" // Check for /P behaviors -// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -P %s -### 2>&1 | FileCheck -check-prefix=FSYCL_P %s +// RUN: %clang_cl --target=x86_64-pc-windows-msvc -fsycl -fno-sycl-device-lib=all -P %s -### 2>&1 | FileCheck -check-prefix=FSYCL_P %s // FSYCL_P: clang{{.*}} "-cc1" "-triple" "spir64-unknown-unknown-sycldevice" {{.*}} "-E" {{.*}} "-o" "[[DEVICEPP:.+\.ii]]" // FSYCL_P: clang{{.*}} "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" {{.*}} "-E" {{.*}} "-o" "[[HOSTPP:.+\.ii]]" // FSYCL_P: clang-offload-bundler{{.*}} "-type=ii" "-targets=sycl-spir64-unknown-unknown-sycldevice,host-x86_64-pc-windows-msvc" {{.*}} "-inputs=[[DEVICEPP]],[[HOSTPP]]" From a35765a55af6e354bbde10908058ec3c3aaf4c4f Mon Sep 17 00:00:00 2001 From: gejin Date: Wed, 2 Dec 2020 16:41:35 +0800 Subject: [PATCH 5/8] Fix Clang lit test on Windows Signed-off-by: gejin --- clang/test/Driver/sycl-offload-static-lib.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/Driver/sycl-offload-static-lib.cpp b/clang/test/Driver/sycl-offload-static-lib.cpp index 9829749f14936..0a3fe36ef03fa 100644 --- a/clang/test/Driver/sycl-offload-static-lib.cpp +++ b/clang/test/Driver/sycl-offload-static-lib.cpp @@ -76,7 +76,7 @@ /// ########################################################################### // RUN: touch %t.a -// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -foffload-static-lib=%t.a -### %s 2>&1 \ +// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-device-lib=all -foffload-static-lib=%t.a -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC2 // FOFFLOAD_STATIC_LIB_SRC2: clang{{.*}} "-emit-obj" {{.*}} "-o" "[[HOSTOBJ:.+\.o]]" // FOFFLOAD_STATIC_LIB_SRC2: ld{{(.exe)?}}" "-r" "-o" {{.*}} "[[HOSTOBJ]]" "[[INPUT:.+\.a]]" @@ -86,7 +86,7 @@ /// ########################################################################### // RUN: touch %t.a -// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -foffload-static-lib=%t.a -o output_name -lOpenCL -### %s 2>&1 \ +// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-device-lib=all -foffload-static-lib=%t.a -o output_name -lOpenCL -### %s 2>&1 \ // RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC3 // FOFFLOAD_STATIC_LIB_SRC3: ld{{(.exe)?}}" "-r" "-o" {{.*}} "[[INPUT:.+\.a]]" // FOFFLOAD_STATIC_LIB_SRC3: clang-offload-bundler{{.*}} "-type=oo" From 37697e52ef4d0c5a36ad1c7596a88c7a7a86ee33 Mon Sep 17 00:00:00 2001 From: gejin Date: Fri, 4 Dec 2020 11:59:26 +0800 Subject: [PATCH 6/8] Using foreach to remove duplicate lines in SYCLDeviceLib CMake Signed-off-by: gejin --- libdevice/cmake/modules/SYCLLibdevice.cmake | 217 +++++--------------- 1 file changed, 49 insertions(+), 168 deletions(-) diff --git a/libdevice/cmake/modules/SYCLLibdevice.cmake b/libdevice/cmake/modules/SYCLLibdevice.cmake index 4f272104357e7..af0357ed12bd9 100644 --- a/libdevice/cmake/modules/SYCLLibdevice.cmake +++ b/libdevice/cmake/modules/SYCLLibdevice.cmake @@ -28,131 +28,73 @@ function(BuildSYCLDeviceLib) ${CMAKE_CURRENT_SOURCE_DIR}/${DeviceLib_Source} -o ${DeviceLib_Path} -fno-sycl-device-lib=all MAIN_DEPENDENCY ${DeviceLib_Source} - DEPENDS ${DeviceLib_Depends} + DEPENDS ${DeviceLib_Depends} clang device.h VERBATIM) endfunction() +set(SYCLWrapperLibs crt complex complex-fp64 cmath cmath-fp64) +set(SYCLFallbackLibs cassert complex complex-fp64 cmath cmath-fp64) +set(SYCLTargetTriples spir64 spir64_x86_64 spir64_gen spir64_fpga) -set(devicelib-wrapper-crt-spir64 ${obj_binary_dir}/libsycl-crt-spir64.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-crt-spir64} Target spir64-unknown-unknown-sycldevice Source ${libcrt_source} Depends wrapper.h device.h spirv_vars.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-spir64.bc Target spir64-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends wrapper.h device.h spirv_vars.h clang) +foreach(TTriple ${SYCLTargetTriples}) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-crt-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source ${libcrt_source} Depends wrapper.h spirv_vars.h) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends wrapper.h spirv_vars.h) +endforeach() -set(devicelib-wrapper-crt-spir64_x86_64 ${obj_binary_dir}/libsycl-crt-spir64_x86_64.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-crt-spir64_x86_64} Target spir64_x86_64-unknown-unknown-sycldevice Source ${libcrt_source} Depends wrapper.h device.h spirv_vars.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-spir64_x86_64.bc Target spir64_x86_64-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends wrapper.h device.h spirv_vars.h clang) +foreach(TTriple ${SYCLTargetTriples}) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-complex-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source complex_wrapper.cpp Depends device_complex.h) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source fallback-complex.cpp Depends device_math.h device_complex.h) +endforeach() -set(devicelib-wrapper-crt-spir64_gen ${obj_binary_dir}/libsycl-crt-spir64_gen.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-crt-spir64_gen} Target spir64_gen-unknown-unknown-sycldevice Source ${libcrt_source} Depends wrapper.h device.h spirv_vars.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-spir64_gen.bc Target spir64_gen-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends wrapper.h device.h spirv_vars.h clang) +foreach(TTriple ${SYCLTargetTriples}) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-complex-fp64-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source complex_wrapper_fp64.cpp Depends device_complex.h) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-fp64-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h) +endforeach() -set(devicelib-wrapper-crt-spir64_fpga ${obj_binary_dir}/libsycl-crt-spir64_fpga.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-crt-spir64_fpga} Target spir64_fpga-unknown-unknown-sycldevice Source ${libcrt_source} Depends wrapper.h device.h spirv_vars.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-spir64_fpga.bc Target spir64_fpga-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends wrapper.h device.h spirv_vars.h clang) +foreach(TTriple ${SYCLTargetTriples}) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-cmath-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source cmath_wrapper.cpp Depends device_math.h) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source fallback-cmath.cpp Depends device_math.h) +endforeach() -set(devicelib-wrapper-complex-spir64 ${obj_binary_dir}/libsycl-complex-spir64.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-spir64} Target spir64-unknown-unknown-sycldevice Source complex_wrapper.cpp Depends device_complex.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-spir64.bc Target spir64-unknown-unknown-sycldevice Source fallback-complex.cpp Depends device_math.h device_complex.h device.h clang) - -set(devicelib-wrapper-complex-spir64_x86_64 ${obj_binary_dir}/libsycl-complex-spir64_x86_64.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-spir64_x86_64} Target spir64_x86_64-unknown-unknown-sycldevice Source complex_wrapper.cpp Depends device_complex.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-spir64_x86_64.bc Target spir64_x86_64-unknown-unknown-sycldevice Source fallback-complex.cpp Depends device_math.h device_complex.h device.h clang) - -set(devicelib-wrapper-complex-spir64_gen ${obj_binary_dir}/libsycl-complex-spir64_gen.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-spir64_gen} Target spir64_gen-unknown-unknown-sycldevice Source complex_wrapper.cpp Depends device_complex.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-spir64_gen.bc Target spir64_gen-unknown-unknown-sycldevice Source fallback-complex.cpp Depends device_math.h device_complex.h device.h clang) - -set(devicelib-wrapper-complex-spir64_fpga ${obj_binary_dir}/libsycl-complex-spir64_fpga.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-spir64_fpga} Target spir64_fpga-unknown-unknown-sycldevice Source complex_wrapper.cpp Depends device_complex.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-spir64_fpga.bc Target spir64_fpga-unknown-unknown-sycldevice Source fallback-complex.cpp Depends device_math.h device_complex.h device.h clang) - -set(devicelib-wrapper-complex-fp64-spir64 ${obj_binary_dir}/libsycl-complex-fp64-spir64.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-fp64-spir64} Target spir64-unknown-unknown-sycldevice Source complex_wrapper_fp64.cpp Depends device_complex.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64.bc Target spir64-unknown-unknown-sycldevice Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h device.h clang) - -set(devicelib-wrapper-complex-fp64-spir64_x86_64 ${obj_binary_dir}/libsycl-complex-fp64-spir64_x86_64.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-fp64-spir64_x86_64} Target spir64_x86_64-unknown-unknown-sycldevice Source complex_wrapper_fp64.cpp Depends device_complex.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_x86_64.bc Target spir64_x86_64-unknown-unknown-sycldevice Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h device.h clang) - -set(devicelib-wrapper-complex-fp64-spir64_gen ${obj_binary_dir}/libsycl-complex-fp64-spir64_gen.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-fp64-spir64_gen} Target spir64_gen-unknown-unknown-sycldevice Source complex_wrapper_fp64.cpp Depends device_complex.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_gen.bc Target spir64_gen-unknown-unknown-sycldevice Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h device.h clang) - -set(devicelib-wrapper-complex-fp64-spir64_fpga ${obj_binary_dir}/libsycl-complex-fp64-spir64_fpga.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-complex-fp64-spir64_fpga} Target spir64_fpga-unknown-unknown-sycldevice Source complex_wrapper_fp64.cpp Depends device_complex.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_fpga.bc Target spir64_fpga-unknown-unknown-sycldevice Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h device.h clang) - -set(devicelib-wrapper-cmath-spir64 ${obj_binary_dir}/libsycl-cmath-spir64.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-spir64} Target spir64-unknown-unknown-sycldevice Source cmath_wrapper.cpp Depends device_math.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-spir64.bc Target spir64-unknown-unknown-sycldevice Source fallback-cmath.cpp Depends device_math.h device.h clang) - -set(devicelib-wrapper-cmath-spir64_x86_64 ${obj_binary_dir}/libsycl-cmath-spir64_x86_64.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-spir64_x86_64} Target spir64_x86_64-unknown-unknown-sycldevice Source cmath_wrapper.cpp Depends device_math.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-spir64_x86_64.bc Target spir64_x86_64-unknown-unknown-sycldevice Source fallback-cmath.cpp Depends device_math.h device.h clang) - -set(devicelib-wrapper-cmath-spir64_gen ${obj_binary_dir}/libsycl-cmath-spir64_gen.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-spir64_gen} Target spir64_gen-unknown-unknown-sycldevice Source cmath_wrapper.cpp Depends device_math.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-spir64_gen.bc Target spir64_gen-unknown-unknown-sycldevice Source fallback-cmath.cpp Depends device_math.h device.h clang) - -set(devicelib-wrapper-cmath-spir64_fpga ${obj_binary_dir}/libsycl-cmath-spir64_fpga.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-spir64_fpga} Target spir64_fpga-unknown-unknown-sycldevice Source cmath_wrapper.cpp Depends device_math.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-spir64_fpga.bc Target spir64_fpga-unknown-unknown-sycldevice Source fallback-cmath.cpp Depends device_math.h device.h clang) - -set(devicelib-wrapper-cmath-fp64-spir64 ${obj_binary_dir}/libsycl-cmath-fp64-spir64.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-fp64-spir64} Target spir64-unknown-unknown-sycldevice Source cmath_wrapper_fp64.cpp Depends device_math.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64.bc Target spir64-unknown-unknown-sycldevice Source fallback-cmath-fp64.cpp Depends device_math.h device.h clang) - -set(devicelib-wrapper-cmath-fp64-spir64_x86_64 ${obj_binary_dir}/libsycl-cmath-fp64-spir64_x86_64.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-fp64-spir64_x86_64} Target spir64_x86_64-unknown-unknown-sycldevice Source cmath_wrapper_fp64.cpp Depends device_math.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_x86_64.bc Target spir64_x86_64-unknown-unknown-sycldevice Source fallback-cmath-fp64.cpp Depends device_math.h device.h clang) - -set(devicelib-wrapper-cmath-fp64-spir64_gen ${obj_binary_dir}/libsycl-cmath-fp64-spir64_gen.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-fp64-spir64_gen} Target spir64_gen-unknown-unknown-sycldevice Source cmath_wrapper_fp64.cpp Depends device_math.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_gen.bc Target spir64_gen-unknown-unknown-sycldevice Source fallback-cmath-fp64.cpp Depends device_math.h device.h clang) - -set(devicelib-wrapper-cmath-fp64-spir64_fpga ${obj_binary_dir}/libsycl-cmath-fp64-spir64_fpga.bc) -BuildSYCLDeviceLib(Path ${devicelib-wrapper-cmath-fp64-spir64_fpga} Target spir64_fpga-unknown-unknown-sycldevice Source cmath_wrapper_fp64.cpp Depends device_math.h device.h clang) -BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_fpga.bc Target spir64_fpga-unknown-unknown-sycldevice Source fallback-cmath-fp64.cpp Depends device_math.h device.h clang) +foreach(TTriple ${SYCLTargetTriples}) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-cmath-fp64-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source cmath_wrapper_fp64.cpp Depends device_math.h) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cmath-fp64-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source fallback-cmath-fp64.cpp Depends device_math.h) +endforeach() function(BuildSYCLFallbackDeviceLib) cmake_parse_arguments(DeviceLib "" "Path;Source" "Depends" ${ARGN}) add_custom_command(OUTPUT ${DeviceLib_Path} - COMMAND ${clang} -S -fsycl-device-only -fno-sycl-use-bitcode + COMMAND ${clang} -fsycl -fsycl-device-only -fno-sycl-use-bitcode ${compile_opts} ${CMAKE_CURRENT_SOURCE_DIR}/${DeviceLib_Source} -o ${DeviceLib_Path} -fno-sycl-device-lib=all MAIN_DEPENDENCY ${DeviceLib_Source} - DEPENDS ${DeviceLib_Depends} + DEPENDS ${DeviceLib_Depends} llvm-spirv clang device.h VERBATIM) endfunction() -BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cassert.spv Source fallback-cassert.cpp Depends wrapper.h device.h clang spirv_vars.h llvm-spirv) -BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-complex.spv Source fallback-complex.cpp Depends device_math.h device_complex.h device.h clang llvm-spirv) -BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-complex-fp64.spv Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h device.h clang llvm-spirv) -BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cmath.spv Source fallback-cmath.cpp Depends device_math.h device.h clang llvm-spirv) -BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cmath-fp64.spv Source fallback-cmath-fp64.cpp Depends device_math.h device.h clang llvm-spirv) - -add_custom_target(libsycldevice-obj DEPENDS - ${devicelib-wrapper-crt-spir64} - ${devicelib-wrapper-crt-spir64_x86_64} - ${devicelib-wrapper-crt-spir64_gen} - ${devicelib-wrapper-crt-spir64_fpga} - ${devicelib-wrapper-complex-spir64} - ${devicelib-wrapper-complex-spir64_x86_64} - ${devicelib-wrapper-complex-spir64_gen} - ${devicelib-wrapper-complex-spir64_fpga} - ${devicelib-wrapper-complex-fp64-spir64} - ${devicelib-wrapper-complex-fp64-spir64_x86_64} - ${devicelib-wrapper-complex-fp64-spir64_gen} - ${devicelib-wrapper-complex-fp64-spir64_fpga} - ${devicelib-wrapper-cmath-spir64} - ${devicelib-wrapper-cmath-spir64_x86_64} - ${devicelib-wrapper-cmath-spir64_gen} - ${devicelib-wrapper-cmath-spir64_fpga} - ${devicelib-wrapper-cmath-fp64-spir64} - ${devicelib-wrapper-cmath-fp64-spir64_x86_64} - ${devicelib-wrapper-cmath-fp64-spir64_gen} - ${devicelib-wrapper-cmath-fp64-spir64_fpga} -) +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cassert.spv Source fallback-cassert.cpp Depends wrapper.h spirv_vars.h) +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-complex.spv Source fallback-complex.cpp Depends device_math.h device_complex.h) +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-complex-fp64.spv Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h) +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cmath.spv Source fallback-cmath.cpp Depends device_math.h) +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cmath-fp64.spv Source fallback-cmath-fp64.cpp Depends device_math.h) + +set(sycl-wrapper-lib-files "") +foreach(SYCLLib ${SYCLWrapperLibs}) + foreach(TTriple ${SYCLTargetTriples}) + list(APPEND sycl-wrapper-lib-files ${obj_binary_dir}/libsycl-${SYCLLib}-${TTriple}.bc) + endforeach() +endforeach() + +set(sycl-fallback-lib-files "") +foreach(SYCLLib ${SYCLFallbackLibs}) + foreach(TTriple ${SYCLTargetTriples}) + list(APPEND sycl-fallback-lib-files ${obj_binary_dir}/libsycl-fallback-${SYCLLib}-${TTriple}.bc) + endforeach() +endforeach() + +add_custom_target(libsycldevice-obj DEPENDS ${sycl-wrapper-lib-files}) +add_custom_target(libsycldevice-fallback-obj DEPENDS ${sycl-fallback-lib-files}) add_custom_target(libsycldevice-spv DEPENDS ${spv_binary_dir}/libsycl-fallback-cassert.spv ${spv_binary_dir}/libsycl-fallback-complex.spv @@ -160,28 +102,6 @@ add_custom_target(libsycldevice-spv DEPENDS ${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-spir64.bc - ${obj_binary_dir}/libsycl-fallback-cassert-spir64_x86_64.bc - ${obj_binary_dir}/libsycl-fallback-cassert-spir64_gen.bc - ${obj_binary_dir}/libsycl-fallback-cassert-spir64_fpga.bc - ${obj_binary_dir}/libsycl-fallback-complex-spir64.bc - ${obj_binary_dir}/libsycl-fallback-complex-spir64_x86_64.bc - ${obj_binary_dir}/libsycl-fallback-complex-spir64_gen.bc - ${obj_binary_dir}/libsycl-fallback-complex-spir64_fpga.bc - ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64.bc - ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_x86_64.bc - ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_gen.bc - ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_fpga.bc - ${obj_binary_dir}/libsycl-fallback-cmath-spir64.bc - ${obj_binary_dir}/libsycl-fallback-cmath-spir64_x86_64.bc - ${obj_binary_dir}/libsycl-fallback-cmath-spir64_gen.bc - ${obj_binary_dir}/libsycl-fallback-cmath-spir64_fpga.bc - ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64.bc - ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_x86_64.bc - ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_gen.bc - ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_fpga.bc -) add_custom_target(libsycldevice DEPENDS libsycldevice-obj libsycldevice-fallback-obj @@ -197,46 +117,7 @@ endif() set(install_dest_lib lib${LLVM_LIBDIR_SUFFIX}) -install(FILES ${devicelib-wrapper-crt-spir64} - ${devicelib-wrapper-crt-spir64_x86_64} - ${devicelib-wrapper-crt-spir64_gen} - ${devicelib-wrapper-crt-spir64_fpga} - ${obj_binary_dir}/libsycl-fallback-cassert-spir64.bc - ${obj_binary_dir}/libsycl-fallback-cassert-spir64_x86_64.bc - ${obj_binary_dir}/libsycl-fallback-cassert-spir64_gen.bc - ${obj_binary_dir}/libsycl-fallback-cassert-spir64_fpga.bc - ${devicelib-wrapper-complex-spir64} - ${devicelib-wrapper-complex-spir64_x86_64} - ${devicelib-wrapper-complex-spir64_gen} - ${devicelib-wrapper-complex-spir64_fpga} - ${obj_binary_dir}/libsycl-fallback-complex-spir64.bc - ${obj_binary_dir}/libsycl-fallback-complex-spir64_x86_64.bc - ${obj_binary_dir}/libsycl-fallback-complex-spir64_gen.bc - ${obj_binary_dir}/libsycl-fallback-complex-spir64_fpga.bc - ${devicelib-wrapper-complex-fp64-spir64} - ${devicelib-wrapper-complex-fp64-spir64_x86_64} - ${devicelib-wrapper-complex-fp64-spir64_gen} - ${devicelib-wrapper-complex-fp64-spir64_fpga} - ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64.bc - ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_x86_64.bc - ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_gen.bc - ${obj_binary_dir}/libsycl-fallback-complex-fp64-spir64_fpga.bc - ${devicelib-wrapper-cmath-spir64} - ${devicelib-wrapper-cmath-spir64_x86_64} - ${devicelib-wrapper-cmath-spir64_gen} - ${devicelib-wrapper-cmath-spir64_fpga} - ${obj_binary_dir}/libsycl-fallback-cmath-spir64.bc - ${obj_binary_dir}/libsycl-fallback-cmath-spir64_x86_64.bc - ${obj_binary_dir}/libsycl-fallback-cmath-spir64_gen.bc - ${obj_binary_dir}/libsycl-fallback-cmath-spir64_fpga.bc - ${devicelib-wrapper-cmath-fp64-spir64} - ${devicelib-wrapper-cmath-fp64-spir64_x86_64} - ${devicelib-wrapper-cmath-fp64-spir64_gen} - ${devicelib-wrapper-cmath-fp64-spir64_fpga} - ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64.bc - ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_x86_64.bc - ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_gen.bc - ${obj_binary_dir}/libsycl-fallback-cmath-fp64-spir64_fpga.bc +install(FILES ${sycl-wrapper-lib-files} ${sycl-fallback-lib-files} DESTINATION ${install_dest_lib} COMPONENT libsycldevice) From a82798e03c23757c7bba85971d5b49fa484a09ae Mon Sep 17 00:00:00 2001 From: gejin Date: Fri, 4 Dec 2020 13:23:41 +0800 Subject: [PATCH 7/8] Enable libm-fp64 link by default Signed-off-by: gejin --- clang/lib/Driver/ToolChains/SYCL.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index 57e8febcae01c..6137a3cb636d5 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -435,7 +435,7 @@ void SYCLToolChain::AddSYCLDeviceLibs(const llvm::opt::ArgList &Args, // Currently, libc, libm-fp32 will be linked in by default. In order // to use libm-fp64, -fsycl-device-lib=libm-fp64/all should be used. llvm::StringMap devicelib_link_info = { - {"libc", true}, {"libm-fp32", true}, {"libm-fp64", false}}; + {"libc", true}, {"libm-fp32", true}, {"libm-fp64", true}}; if (Arg *A = Args.getLastArg(options::OPT_fsycl_device_lib_EQ, options::OPT_fno_sycl_device_lib_EQ)) { if (A->getValues().size() == 0) From 3afa020f36379d1b41755daeda63d6534146f68f Mon Sep 17 00:00:00 2001 From: gejin Date: Mon, 7 Dec 2020 13:52:50 +0800 Subject: [PATCH 8/8] Rename wrapper.h to devicelib_assert.h Signed-off-by: gejin --- libdevice/cmake/modules/SYCLLibdevice.cmake | 6 +++--- libdevice/{wrapper.h => devicelib_assert.h} | 8 ++++---- libdevice/fallback-cassert.cpp | 2 +- libdevice/glibc_wrapper.cpp | 2 +- libdevice/msvc_wrapper.cpp | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) rename libdevice/{wrapper.h => devicelib_assert.h} (82%) diff --git a/libdevice/cmake/modules/SYCLLibdevice.cmake b/libdevice/cmake/modules/SYCLLibdevice.cmake index af0357ed12bd9..c26dc9d8d00fc 100644 --- a/libdevice/cmake/modules/SYCLLibdevice.cmake +++ b/libdevice/cmake/modules/SYCLLibdevice.cmake @@ -37,8 +37,8 @@ set(SYCLFallbackLibs cassert complex complex-fp64 cmath cmath-fp64) set(SYCLTargetTriples spir64 spir64_x86_64 spir64_gen spir64_fpga) foreach(TTriple ${SYCLTargetTriples}) - BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-crt-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source ${libcrt_source} Depends wrapper.h spirv_vars.h) - BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends wrapper.h spirv_vars.h) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-crt-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source ${libcrt_source} Depends devicelib_assert.h spirv_vars.h) + BuildSYCLDeviceLib(Path ${obj_binary_dir}/libsycl-fallback-cassert-${TTriple}.bc Target ${TTriple}-unknown-unknown-sycldevice Source fallback-cassert.cpp Depends devicelib_assert.h spirv_vars.h) endforeach() foreach(TTriple ${SYCLTargetTriples}) @@ -73,7 +73,7 @@ function(BuildSYCLFallbackDeviceLib) VERBATIM) endfunction() -BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cassert.spv Source fallback-cassert.cpp Depends wrapper.h spirv_vars.h) +BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cassert.spv Source fallback-cassert.cpp Depends devicelib_assert.h spirv_vars.h) BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-complex.spv Source fallback-complex.cpp Depends device_math.h device_complex.h) BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-complex-fp64.spv Source fallback-complex-fp64.cpp Depends device_math.h device_complex.h) BuildSYCLFallbackDeviceLib(Path ${spv_binary_dir}/libsycl-fallback-cmath.spv Source fallback-cmath.cpp Depends device_math.h) diff --git a/libdevice/wrapper.h b/libdevice/devicelib_assert.h similarity index 82% rename from libdevice/wrapper.h rename to libdevice/devicelib_assert.h index 2116d1e55a226..d182c3a501b01 100644 --- a/libdevice/wrapper.h +++ b/libdevice/devicelib_assert.h @@ -1,4 +1,4 @@ -//==--- wrapper.h - declarations for devicelib functions -----*- C++ -*-----==// +//==- devicelib_assert.h - declarations for devicelib functions --*- C++ -*-==// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef __LIBDEVICE_WRAPPER_H__ -#define __LIBDEVICE_WRAPPER_H__ +#ifndef __LIBDEVICE_ASSERT_H__ +#define __LIBDEVICE_ASSERT_H__ #include "device.h" @@ -25,4 +25,4 @@ void __devicelib_assert_fail(const char *expr, const char *file, int32_t line, uint64_t gid2, uint64_t lid0, uint64_t lid1, uint64_t lid2); #endif // __SPIR__ -#endif // __LIBDEVICE_WRAPPER_H__ +#endif // __LIBDEVICE_ASSERT_H__ diff --git a/libdevice/fallback-cassert.cpp b/libdevice/fallback-cassert.cpp index 724d4635fb0b5..c218db6383b84 100644 --- a/libdevice/fallback-cassert.cpp +++ b/libdevice/fallback-cassert.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "wrapper.h" +#include "devicelib_assert.h" #ifdef __SPIR__ static const __attribute__((opencl_constant)) char assert_fmt[] = diff --git a/libdevice/glibc_wrapper.cpp b/libdevice/glibc_wrapper.cpp index 6003c520cf0ff..69fdf7efe28ac 100644 --- a/libdevice/glibc_wrapper.cpp +++ b/libdevice/glibc_wrapper.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "wrapper.h" +#include "devicelib_assert.h" #ifdef __SPIR__ DEVICE_EXTERN_C diff --git a/libdevice/msvc_wrapper.cpp b/libdevice/msvc_wrapper.cpp index d96bc973dffc4..c35ea94f9f6a3 100644 --- a/libdevice/msvc_wrapper.cpp +++ b/libdevice/msvc_wrapper.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "wrapper.h" +#include "devicelib_assert.h" #ifdef __SPIR__ // Truncates a wide (16 or 32 bit) string (wstr) into an ASCII string (str).