Skip to content

Commit e405eb0

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 0bb5db5 commit e405eb0

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
@@ -209,11 +209,6 @@ const char *SYCLInstallationDetector::findLibspirvPath(
209209
void SYCLInstallationDetector::addLibspirvLinkArgs(
210210
const llvm::Triple &DeviceTriple, const llvm::opt::ArgList &DriverArgs,
211211
const llvm::Triple &HostTriple, llvm::opt::ArgStringList &CC1Args) const {
212-
DriverArgs.claimAllArgs(options::OPT_fno_sycl_libspirv);
213-
214-
if (D.offloadDeviceOnly())
215-
return;
216-
217212
if (DriverArgs.hasArg(options::OPT_fno_sycl_libspirv)) {
218213
// -fno-sycl-libspirv flag is reserved for very unusual cases where the
219214
// 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
@@ -21,8 +21,7 @@
2121
//
2222
// RUN: %clang -### -fsycl -fsycl-device-only -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
2323
// RUN: | FileCheck %s --check-prefixes=CHECK-DEVICE-ONLY
24-
// CHECK-DEVICE-ONLY: "-cc1"{{.*}} "-fsycl-is-device"
25-
// CHECK-DEVICE-ONLY-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
24+
// CHECK-DEVICE-ONLY: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
2625
//
2726
// Only link libspirv in SYCL language mode, `-fno-sycl-libspirv` should result in a warning
2827
// 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)