Skip to content

Commit bfe4aa4

Browse files
committed
[SYCL][Driver][libdevice] Link libspirv in -fsycl-device-only mode
Previously, the `-fsycl-device-only` mode disabled linking libspirv. `-fsycl-device-only` should produce the same LLVM-IR as `-fsycl` would, but without any host actions. Libdevice is the likely reason why this was done as is, but it should not be the default. This patch changes libdevice options to disable libspirv linking there, and enables linking by default in `-fsycl-device-only` mode.
1 parent d5440ef commit bfe4aa4

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,6 @@ const char *SYCLInstallationDetector::findLibspirvPath(
204204
void SYCLInstallationDetector::addLibspirvLinkArgs(
205205
const llvm::Triple &DeviceTriple, const llvm::opt::ArgList &DriverArgs,
206206
const llvm::Triple &HostTriple, llvm::opt::ArgStringList &CC1Args) const {
207-
DriverArgs.claimAllArgs(options::OPT_fno_sycl_libspirv);
208-
209-
if (D.offloadDeviceOnly())
210-
return;
211-
212207
if (DriverArgs.hasArg(options::OPT_fno_sycl_libspirv)) {
213208
// -fno-sycl-libspirv flag is reserved for very unusual cases where the
214209
// libspirv library is not linked when required by the device: so output appropriate

clang/test/Driver/sycl-libspirv-toolchain.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
//
1818
// RUN: %clang -### -fsycl -fsycl-device-only -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
1919
// RUN: | FileCheck %s --check-prefixes=CHECK-DEVICE-ONLY
20-
// CHECK-DEVICE-ONLY: "-cc1"{{.*}} "-fsycl-is-device"
21-
// CHECK-DEVICE-ONLY-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
20+
// CHECK-DEVICE-ONLY: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
2221
//
2322
// Only link libspirv in SYCL language mode, `-fno-sycl-libspirv` should result in a warning
2423
// RUN: %clang -### -x cu -fno-sycl-libspirv -nocudainc -nocudalib %s 2>&1 | FileCheck %s --check-prefixes=CHECK-CUDA

libdevice/cmake/modules/SYCLLibdevice.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ set(devicelib_arch)
8282
if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
8383
list(APPEND devicelib_arch nvptx64-nvidia-cuda)
8484
set(compile_opts_nvptx64-nvidia-cuda "-fsycl-targets=nvptx64-nvidia-cuda"
85-
"-Xsycl-target-backend" "--cuda-gpu-arch=sm_50" "-nocudalib")
85+
"-Xsycl-target-backend" "--cuda-gpu-arch=sm_50" "-nocudalib" "-fno-sycl-libspirv" "-Wno-unsafe-libspirv-not-linked")
8686
set(opt_flags_nvptx64-nvidia-cuda "-O3" "--nvvm-reflect-enable=false")
8787
endif()
8888
if("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
8989
list(APPEND devicelib_arch amdgcn-amd-amdhsa)
9090
set(compile_opts_amdgcn-amd-amdhsa "-nogpulib" "-fsycl-targets=amdgcn-amd-amdhsa"
91-
"-Xsycl-target-backend" "--offload-arch=gfx942")
91+
"-Xsycl-target-backend" "--offload-arch=gfx942" "-fno-sycl-libspirv" "-Wno-unsafe-libspirv-not-linked")
9292
set(opt_flags_amdgcn-amd-amdhsa "-O3" "--amdgpu-oclc-reflect-enable=false")
9393
endif()
9494

0 commit comments

Comments
 (0)