Skip to content

Commit 00d49b9

Browse files
authored
[SYCL][Driver][libdevice] Link libspirv in -fsycl-device-only mode (#19136)
<!-- start git-machete generated --> # Based on PR #19135 ## Chain of upstream PRs as of 2025-06-25 * PR #19130 * PR #19131 * PR #19134 * PR #19135 * **PR #19136 (THIS ONE)** <!-- end git-machete generated --> 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 8d1e141 commit 00d49b9

File tree

7 files changed

+10
-14
lines changed

7 files changed

+10
-14
lines changed

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,6 @@ const char *SYCLInstallationDetector::findLibspirvPath(
210210
void SYCLInstallationDetector::addLibspirvLinkArgs(
211211
const llvm::Triple &DeviceTriple, const llvm::opt::ArgList &DriverArgs,
212212
const llvm::Triple &HostTriple, llvm::opt::ArgStringList &CC1Args) const {
213-
DriverArgs.claimAllArgs(options::OPT_fno_sycl_libspirv);
214-
215-
if (D.offloadDeviceOnly())
216-
return;
217-
218213
if (DriverArgs.hasArg(options::OPT_fno_sycl_libspirv)) {
219214
// -fno-sycl-libspirv flag is reserved for very unusual cases where the
220215
// libspirv library is not linked when required by the device: so output

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ set(full_build_archs)
9595
if ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD)
9696
list(APPEND full_build_archs nvptx64-nvidia-cuda)
9797
set(compile_opts_nvptx64-nvidia-cuda "-fsycl-targets=nvptx64-nvidia-cuda"
98-
"-Xsycl-target-backend" "--cuda-gpu-arch=sm_50" "-nocudalib")
98+
"-Xsycl-target-backend" "--cuda-gpu-arch=sm_50" "-nocudalib" "-fno-sycl-libspirv" "-Wno-unsafe-libspirv-not-linked")
9999
set(opt_flags_nvptx64-nvidia-cuda "-O3" "--nvvm-reflect-enable=false")
100100
endif()
101101
if("AMDGPU" IN_LIST LLVM_TARGETS_TO_BUILD)
102102
list(APPEND full_build_archs amdgcn-amd-amdhsa)
103103
set(compile_opts_amdgcn-amd-amdhsa "-nogpulib" "-fsycl-targets=amdgcn-amd-amdhsa"
104-
"-Xsycl-target-backend" "--offload-arch=gfx942")
104+
"-Xsycl-target-backend" "--offload-arch=gfx942" "-fno-sycl-libspirv" "-Wno-unsafe-libspirv-not-linked")
105105
set(opt_flags_amdgcn-amd-amdhsa "-O3" "--amdgpu-oclc-reflect-enable=false")
106106
endif()
107107

@@ -435,7 +435,8 @@ if("native_cpu" IN_LIST SYCL_ENABLE_BACKENDS)
435435
# libsycl-nativecpu_utils is only needed as BC file by NativeCPU.
436436
add_custom_command(
437437
OUTPUT ${bc_binary_dir}/nativecpu_utils.bc
438-
COMMAND ${clang_exe} ${compile_opts} ${bc_device_compile_opts} -fsycl-targets=native_cpu
438+
COMMAND ${clang_exe} ${compile_opts} ${bc_device_compile_opts}
439+
-fsycl-targets=native_cpu -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked
439440
-I ${PROJECT_BINARY_DIR}/include -I ${NATIVE_CPU_DIR}
440441
${CMAKE_CURRENT_SOURCE_DIR}/nativecpu_utils.cpp
441442
-o ${bc_binary_dir}/nativecpu_utils.bc

sycl/test/check_device_code/math-builtins/cmath-spirv-mapping.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Note: This isn't really target specific and should be switched to spir when
33
// it's enabled for it.
44

5-
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -S -Xclang -emit-llvm -fsycl-device-only %s -o - | FileCheck %s
5+
// RUN: %clangxx -fsycl -fsycl-targets=nvptx64-nvidia-cuda -S -Xclang -emit-llvm \
6+
// RUN: -fsycl-device-only -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked %s -o - | FileCheck %s
67

78
#include <cmath>
89

sycl/test/check_device_code/native_cpu/kernelhandler-scalar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -fsycl-device-only -fsycl-targets=native_cpu -Xclang -sycl-std=2020 -mllvm -sycl-opt -S -emit-llvm -o %t_temp.ll %s
1+
// RUN: %clangxx -fsycl-device-only -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked -fsycl-targets=native_cpu -Xclang -sycl-std=2020 -mllvm -sycl-opt -S -emit-llvm -o %t_temp.ll %s
22
// RUN: %clangxx -mllvm -sycl-native-cpu-backend -S -emit-llvm -o - %t_temp.ll | FileCheck %s
33
#include <sycl/sycl.hpp>
44

sycl/test/check_device_code/native_cpu/native_cpu_subhandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx -fsycl-device-only -O2 -g -fexceptions -fsycl-targets=native_cpu -Xclang -sycl-std=2020 -mllvm -sycl-opt -S -emit-llvm -o %t_temp.ll %s
1+
// RUN: %clangxx -fsycl-device-only -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked -O2 -g -fexceptions -fsycl-targets=native_cpu -Xclang -sycl-std=2020 -mllvm -sycl-opt -S -emit-llvm -o %t_temp.ll %s
22
// RUN: %clangxx -mllvm -sycl-native-cpu-backend -S -emit-llvm -o - %t_temp.ll | FileCheck %s
33

44
// Checks that the subhandler is correctly emitted in the module

sycl/test/check_device_code/native_cpu/offload-wrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This test checks the output for the clang-offload-wrapper for the Native CPU
22
// target:
3-
// RUN: %clangxx -fsycl-device-only -fsycl-targets=native_cpu %s -o %t.bc
3+
// RUN: %clangxx -fsycl-device-only -fno-sycl-libspirv -Wno-unsafe-libspirv-not-linked -fsycl-targets=native_cpu %s -o %t.bc
44
// RUN: sycl-post-link -properties -emit-param-info -symbols -emit-exported-symbols -O2 -spec-const=native -device-globals -o %t.table %t.bc
55
// RUN: clang-offload-wrapper -o=%t_wrap.bc -host=x86_64-unknown-linux-gnu -target=native_cpu -kind=sycl -batch %t.table
66
// RUN: llvm-dis %t_wrap.bc -o - | FileCheck %s

0 commit comments

Comments
 (0)