Skip to content

Commit 345b9ab

Browse files
authored
[SYCL][Driver] Improve SYCL libspirv linking test coverage (NFC) (#19130)
<!-- start git-machete generated --> # Based on PR #18956 ## Tree of downstream PRs as of 2025-06-25 * **PR #19130 (THIS ONE)** * PR #19131 * PR #19134 * PR #19135 * PR #19136 <!-- end git-machete generated --> In the next commits I'd like to refactor and fix SYCL libspirv linking. This adds a few tests to cover the current behavior. Some of it is buggy, and not consistent between NVPTX and AMDGPU, it will be improved in the next commits.
1 parent 3b04aeb commit 345b9ab

8 files changed

+53
-11
lines changed

clang/test/Driver/Inputs/SYCL/share/clc/remangled-l32-signed_char.libspirv-nvptx64-nvidia-cuda.bc

Whitespace-only changes.

clang/test/Driver/Inputs/SYCL/share/clc/remangled-l64-signed_char.libspirv-amdgcn-amd-amdhsa.bc

Whitespace-only changes.

clang/test/Driver/Inputs/SYCL/share/clc/remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda.bc

Whitespace-only changes.

clang/test/Driver/cuda-nvptx-target.cpp

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Test the search logic for the libspirv bitcode library in the offloading toolchains that need it.
2+
3+
// DEFINE: %{install_dir} = %/S/Inputs/SYCL/bin
4+
// DEFINE: %{resource_dir} = %/S/Inputs/SYCL/lib/clang/resource_dir
5+
6+
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib -target x86_64-unknown-windows-msvc %s 2>&1 \
7+
// RUN: | FileCheck %s --check-prefixes=CHECK-WINDOWS
8+
// CHECK-WINDOWS: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-l32-signed_char.libspirv-nvptx64-nvidia-cuda.bc"
9+
//
10+
// RUN: %clang -### -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib -target x86_64-unknown-linux-gnu %s 2>&1 \
11+
// RUN: | FileCheck %s --check-prefixes=CHECK-LINUX
12+
// CHECK-LINUX: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-l64-signed_char.libspirv-nvptx64-nvidia-cuda.bc"
13+
//
14+
// AMDGCN wrongly uses 32-bit longs on Windows
15+
// RUN: %clang -### -resource-dir %{resource_dir} -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 -nogpulib -target x86_64-unknown-windows-msvc %s 2>&1 \
16+
// RUN: | FileCheck %s --check-prefixes=CHECK-AMDGCN-WINDOWS
17+
// CHECK-AMDGCN-WINDOWS: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "{{.*[\\/]}}remangled-l64-signed_char.libspirv-amdgcn-amd-amdhsa.bc"
18+
//
19+
// RUN: %clang -### -fsycl -fsycl-device-only -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
20+
// RUN: | FileCheck %s --check-prefixes=CHECK-DEVICE-ONLY
21+
// CHECK-DEVICE-ONLY: "-cc1"{{.*}} "-fsycl-is-device"
22+
// CHECK-DEVICE-ONLY-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
23+
//
24+
// Only link libspirv in SYCL language mode, but `-fno-sycl-libspirv` does not result in a warning
25+
// RUN: %clang -### -x cu -fno-sycl-libspirv -nocudainc -nocudalib %s 2>&1 | FileCheck %s --check-prefixes=CHECK-CUDA
26+
// CHECK-CUDA-NOT: warning: argument unused during compilation: '-fno-sycl-libspirv' [-Wunused-command-line-argument]
27+
// CHECK-CUDA: "-cc1"{{.*}} "-fcuda-is-device"
28+
// CHECK-CUDA-NOT: "-mlink-builtin-bitcode" "{{.*}}.libspirv-{{.*}}.bc"
29+
//
30+
// The path to the remangled libspirv bitcode file is determined by the resource directory.
31+
// RUN: %clang -### -ccc-install-dir %{install_dir} -resource-dir %{resource_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
32+
// RUN: | FileCheck %s -DINSTALL_DIR=%{install_dir} -DRESOURCE_DIR=%{resource_dir} --check-prefixes=CHECK-DIR
33+
// CHECK-DIR: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[RESOURCE_DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
34+
//
35+
// The `-###` option disables file existence checks
36+
// DEFINE: %{nonexistent_dir} = %/S/Inputs/SYCL/does_not_exist/lib/clang/resource_dir
37+
// RUN: %clang -### -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
38+
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-HHH-NONEXISTENT
39+
// CHECK-HHH-NONEXISTENT: "-cc1"{{.*}} "-fsycl-is-device"{{.*}} "-mlink-builtin-bitcode" "[[DIR]]{{.*[\\/]}}remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc"
40+
//
41+
// But not for AMDGCN :^)
42+
// RUN: not %clang -### -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=gfx908 -nogpulib %s 2>&1 \
43+
// RUN: | FileCheck %s -DDIR=%{nonexistent_dir} --check-prefixes=CHECK-AMDGCN-HHH-NONEXISTENT
44+
// CHECK-AMDGCN-HHH-NONEXISTENT: error: cannot find 'remangled-{{.*}}.libspirv-amdgcn-amd-amdhsa.bc'; provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv
45+
//
46+
// `-fdriver-only` has no such special handling, so it will not find the file
47+
// RUN: not %clang -fdriver-only -resource-dir %{nonexistent_dir} -fsycl -fsycl-targets=nvptx64-nvidia-cuda -nocudalib %s 2>&1 \
48+
// RUN: | FileCheck %s --check-prefixes=CHECK-DO-NONEXISTENT
49+
// CHECK-DO-NONEXISTENT: error: cannot find 'remangled-{{.*}}.libspirv-nvptx64-nvidia-cuda.bc'; provide path to libspirv library via '-fsycl-libspirv-path', or pass '-fno-sycl-libspirv' to build without linking with libspirv

clang/test/Driver/sycl-offload-nvptx.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
// RUN: %clangxx -ccc-print-phases --sysroot=%S/Inputs/SYCL -std=c++11 \
3939
// RUN: -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-device-lib=all \
4040
// RUN: -fsycl-instrument-device-code -fsycl-targets=nvptx64-nvidia-cuda %s 2>&1 \
41-
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/lib/nvidiacl \
41+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/share/clc/remangled-l32-signed_char.libspirv-nvptx64-nvidia-cuda.bc \
4242
// RUN: --cuda-path=%S/Inputs/CUDA_111/usr/local/cuda \
4343
// RUN: | FileCheck -check-prefix=CHK-PHASES-NO-CC %s
4444
//
@@ -57,7 +57,7 @@
5757
// CHK-PHASES-NO-CC: 10: input, "{{.*}}libsycl-itt-user-wrappers.bc", ir, (device-sycl, sm_50)
5858
// CHK-PHASES-NO-CC: 11: input, "{{.*}}libsycl-itt-compiler-wrappers.bc", ir, (device-sycl, sm_50)
5959
// CHK-PHASES-NO-CC: 12: input, "{{.*}}libsycl-itt-stubs.bc", ir, (device-sycl, sm_50)
60-
// CHK-PHASES-NO-CC: 13: input, "{{.*}}nvidiacl{{.*}}", ir, (device-sycl, sm_50)
60+
// CHK-PHASES-NO-CC: 13: input, "{{.*}}libspirv-nvptx64{{.*}}", ir, (device-sycl, sm_50)
6161
// CHK-PHASES-NO-CC: 14: input, "{{.*}}libdevice{{.*}}", ir, (device-sycl, sm_50)
6262
// CHK-PHASES-NO-CC: 15: linker, {9, 10, 11, 12, 13, 14}, ir, (device-sycl, sm_50)
6363
// CHK-PHASES-NO-CC: 16: sycl-post-link, {15}, ir, (device-sycl, sm_50)
@@ -75,7 +75,7 @@
7575
// RUN: %clangxx -ccc-print-phases --sysroot=%S/Inputs/SYCL -std=c++11 \
7676
// RUN: -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-device-lib=all \
7777
// RUN: -fsycl-instrument-device-code -fsycl-targets=nvptx64-nvidia-cuda \
78-
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/lib/nvidiacl \
78+
// RUN: -fsycl-libspirv-path=%S/Inputs/SYCL/share/clc/remangled-l32-signed_char.libspirv-nvptx64-nvidia-cuda.bc \
7979
// RUN: --cuda-path=%S/Inputs/CUDA_111/usr/local/cuda \
8080
// RUN: -Xsycl-target-backend "--cuda-gpu-arch=sm_35" %s 2>&1 \
8181
// RUN: | FileCheck -check-prefix=CHK-PHASES %s
@@ -95,7 +95,7 @@
9595
// CHK-PHASES: 10: input, "{{.*}}libsycl-itt-user-wrappers.bc", ir, (device-sycl, sm_35)
9696
// CHK-PHASES: 11: input, "{{.*}}libsycl-itt-compiler-wrappers.bc", ir, (device-sycl, sm_35)
9797
// CHK-PHASES: 12: input, "{{.*}}libsycl-itt-stubs.bc", ir, (device-sycl, sm_35)
98-
// CHK-PHASES: 13: input, "{{.*}}nvidiacl{{.*}}", ir, (device-sycl, sm_35)
98+
// CHK-PHASES: 13: input, "{{.*}}libspirv-nvptx64{{.*}}", ir, (device-sycl, sm_35)
9999
// CHK-PHASES: 14: input, "{{.*}}libdevice{{.*}}", ir, (device-sycl, sm_35)
100100
// CHK-PHASES: 15: linker, {9, 10, 11, 12, 13, 14}, ir, (device-sycl, sm_35)
101101
// CHK-PHASES: 16: sycl-post-link, {15}, ir, (device-sycl, sm_35)

0 commit comments

Comments
 (0)