[clang] 5845c25 - [Clang][SYCL] Infer the SPIR-V target from an Intel offload architecture (#229248)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 2 14:03:03 PST 2026
Author: Srividya Sundaram
Date: 2026-11-02T14:02:58-08:00
New Revision: 5845c25b47c8ab32a7db408335b5a42634621220
URL: https://github.com/llvm/llvm-project/commit/5845c25b47c8ab32a7db408335b5a42634621220
DIFF: https://github.com/llvm/llvm-project/commit/5845c25b47c8ab32a7db408335b5a42634621220.diff
LOG: [Clang][SYCL] Infer the SPIR-V target from an Intel offload architecture (#229248)
Select the SPIR-V target from an Intel offload architecture.
Previously, `clang++ -fsycl --offload-arch=xe-pvc` failed with "invalid
or unsupported offload target" unless `--offload-targets` was also
given. For SYCL, an Intel GPU (by name or numeric name), an Intel CPU,
an IGCA target or `generic` now selects `spirv64-unknown-unknown` on a
64-bit host and `spirv32-unknown-unknown` otherwise. Other offload kinds
are unchanged.
For SYCL offloading, `--offload-arch=native` now asks offload-arch for
Intel GPUs only, with `--only=intel`, as HIP and CUDA already do for
their vendors. Without an Intel GPU, SYCL now reports "No GPU detected
in the system".
Added:
clang/test/Driver/Inputs/offload-arch/offload_arch_sm_70_gfx906_gfx90a_xe_pvc
clang/test/Driver/Inputs/offload-arch/offload_arch_sm_70_gfx90a
clang/test/Driver/sycl-system-arch.cpp
Modified:
clang/lib/Driver/Driver.cpp
clang/test/Driver/sycl-intel-gpu-arch.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 3f0bce700b7b7f..37fb69baf6a3eb 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -958,6 +958,8 @@ getSystemOffloadArchs(Compilation &C, Action::OffloadKind Kind) {
Args.push_back("--only=amdgpu");
else if (Kind == Action::OFK_Cuda)
Args.push_back("--only=nvptx");
+ else if (Kind == Action::OFK_SYCL)
+ Args.push_back("--only=intel");
}
auto StdoutOrErr = C.getDriver().executeProgram(Args);
@@ -985,6 +987,13 @@ getSystemOffloadArchs(Compilation &C, Action::OffloadKind Kind) {
using TripleSet = std::multiset<llvm::Triple>;
+/// \return the SPIR-V target for SYCL on \p HostTriple: spirv64 on a 64-bit
+/// host, spirv32 otherwise.
+static llvm::Triple getSYCLDefaultTriple(const llvm::Triple &HostTriple) {
+ return llvm::Triple(HostTriple.isArch64Bit() ? llvm::Triple::spirv64
+ : llvm::Triple::spirv32);
+}
+
// Attempts to infer the correct offloading toolchain triple by looking at the
// requested offloading kind and architectures.
static TripleSet inferOffloadToolchains(Compilation &C,
@@ -1045,6 +1054,11 @@ static TripleSet inferOffloadToolchains(Compilation &C,
llvm::Triple Triple =
OffloadArchToTriple(C.getDefaultToolChain().getTriple(), ID);
+ // For SYCL, compile an Intel GPU or CPU, an IGCA target or "generic" for
+ // SPIR-V: spirv64-unknown-unknown on a 64-bit host, spirv32-unknown-unknown
+ // otherwise.
+ if (Kind == Action::OFK_SYCL && (ID.isIntel() || ID.isGeneric()))
+ Triple = getSYCLDefaultTriple(C.getDefaultToolChain().getTriple());
if (UsesLLVMOffloading)
Triple.setEnvironment(llvm::Triple::LLVM);
@@ -1077,10 +1091,7 @@ static TripleSet inferOffloadToolchains(Compilation &C,
Triples.insert(llvm::Triple(Arch, llvm::Triple::NoSubArch,
llvm::Triple::NVIDIA, llvm::Triple::CUDA));
} else if (Archs.empty() && Kind == Action::OFK_SYCL)
- Triples.insert(
- llvm::Triple(C.getDefaultToolChain().getTriple().isArch64Bit()
- ? llvm::Triple::spirv64
- : llvm::Triple::spirv32));
+ Triples.insert(getSYCLDefaultTriple(C.getDefaultToolChain().getTriple()));
// We need to dispatch these to the appropriate toolchain now.
C.getArgs().eraseArg(options::OPT_offload_arch_EQ);
diff --git a/clang/test/Driver/Inputs/offload-arch/offload_arch_sm_70_gfx906_gfx90a_xe_pvc b/clang/test/Driver/Inputs/offload-arch/offload_arch_sm_70_gfx906_gfx90a_xe_pvc
new file mode 100755
index 00000000000000..c9ae7fdda1cf89
--- /dev/null
+++ b/clang/test/Driver/Inputs/offload-arch/offload_arch_sm_70_gfx906_gfx90a_xe_pvc
@@ -0,0 +1,11 @@
+#!/bin/sh
+# Like offload-arch, print only the Intel GPU for --only=intel.
+if [ "$1" = "--only=intel" ]; then
+ echo "xe-pvc"
+ exit 0
+fi
+echo "sm_70"
+echo "gfx906"
+echo "gfx90a:sramecc+:xnack-"
+echo "xe-pvc"
+exit 0
diff --git a/clang/test/Driver/Inputs/offload-arch/offload_arch_sm_70_gfx90a b/clang/test/Driver/Inputs/offload-arch/offload_arch_sm_70_gfx90a
new file mode 100755
index 00000000000000..b654674de614d3
--- /dev/null
+++ b/clang/test/Driver/Inputs/offload-arch/offload_arch_sm_70_gfx90a
@@ -0,0 +1,8 @@
+#!/bin/sh
+# Like offload-arch, print nothing for --only=intel, as there is no Intel GPU.
+if [ "$1" = "--only=intel" ]; then
+ exit 0
+fi
+echo "sm_70"
+echo "gfx90a:sramecc+:xnack-"
+exit 0
diff --git a/clang/test/Driver/sycl-intel-gpu-arch.cpp b/clang/test/Driver/sycl-intel-gpu-arch.cpp
index 555391b379ac0e..e0169b95b84ee3 100644
--- a/clang/test/Driver/sycl-intel-gpu-arch.cpp
+++ b/clang/test/Driver/sycl-intel-gpu-arch.cpp
@@ -16,3 +16,44 @@
// CHK-AS-GIVEN-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-mtl-u)"
// CHK-AS-GIVEN-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-arl-u)"
// CHK-AS-GIVEN-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe_12.70.0)"
+
+/// Without --offload-targets, an Intel device (by name or numeric name), an IGCA
+/// target or "generic" picks SPIR-V of the host's width.
+// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fsycl \
+// RUN: --offload-arch=xe-pvc --offload-arch=xe-bmg-g21 --offload-arch=graniterapids \
+// RUN: --offload-arch=generic --offload-arch=igca_20ca --offload-arch=xe_12.60.7 \
+// RUN: -c %s 2>&1 | FileCheck -check-prefixes=CHK-NO-TARGETS %s
+// CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:generic)"
+// CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:graniterapids)"
+// CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:igca_20ca)"
+// CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-bmg-g21)"
+// CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-pvc)"
+// CHK-NO-TARGETS-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe_12.60.7)"
+// RUN: %clang -ccc-print-phases --target=i386-unknown-linux-gnu -fsycl \
+// RUN: --offload-arch=xe-pvc --offload-arch=igca_20ca -c %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=CHK-NO-TARGETS-32 %s
+// CHK-NO-TARGETS-32-DAG: offload, "device-sycl (spirv32-unknown-unknown:xe-pvc)"
+// CHK-NO-TARGETS-32-DAG: offload, "device-sycl (spirv32-unknown-unknown:igca_20ca)"
+/// Names are kept as given, so two aliases of one device make two device jobs,
+/// and --no-offload-arch removes a name.
+// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fsycl \
+// RUN: --offload-arch=xe-mtl-u --offload-arch=xe-arl-u --offload-arch=xe-pvc \
+// RUN: --no-offload-arch=xe-pvc -c %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=CHK-NO-TARGETS-AS-GIVEN %s
+// CHK-NO-TARGETS-AS-GIVEN-NOT: xe-pvc
+// CHK-NO-TARGETS-AS-GIVEN-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-mtl-u)"
+// CHK-NO-TARGETS-AS-GIVEN-DAG: offload, "device-sycl (spirv64-unknown-unknown:xe-arl-u)"
+// CHK-NO-TARGETS-AS-GIVEN-NOT: xe-pvc
+
+/// As for CUDA and HIP, -foffload-via-llvm gives the inferred target the LLVM
+/// environment.
+// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl -foffload-via-llvm \
+// RUN: --offload-arch=xe-pvc -c %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=CHK-VIA-LLVM %s
+// CHK-VIA-LLVM: "-cc1" "-triple" "spirv64-unknown-unknown-llvm"
+
+/// Only SYCL infers a target from an Intel name.
+// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -x cuda -nocudainc \
+// RUN: -nocudalib --offload-arch=xe-pvc -c %s 2>&1 \
+// RUN: | FileCheck -check-prefixes=CHK-CUDA %s
+// CHK-CUDA: error: unsupported CUDA gpu architecture: xe-pvc
diff --git a/clang/test/Driver/sycl-system-arch.cpp b/clang/test/Driver/sycl-system-arch.cpp
new file mode 100644
index 00000000000000..b5c86ab760f04f
--- /dev/null
+++ b/clang/test/Driver/sycl-system-arch.cpp
@@ -0,0 +1,25 @@
+// Needs chmod
+// UNSUPPORTED: system-windows
+// XFAIL: target={{.*}}-zos{{.*}}
+
+// RUN: mkdir -p %t
+// RUN: cp %S/Inputs/offload-arch/offload_arch_sm_70_gfx906_gfx90a_xe_pvc %t/
+// RUN: cp %S/Inputs/offload-arch/offload_arch_sm_70_gfx90a %t/
+// RUN: chmod +x %t/offload_arch_sm_70_gfx906_gfx90a_xe_pvc
+// RUN: chmod +x %t/offload_arch_sm_70_gfx90a
+
+/// For SYCL offloading, --offload-arch=native asks offload-arch for Intel GPUs
+/// only.
+// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fsycl \
+// RUN: --offload-arch=native --offload-arch-tool=%t/offload_arch_sm_70_gfx906_gfx90a_xe_pvc \
+// RUN: -c %s 2>&1 | FileCheck %s
+// CHECK-NOT: "device-sycl ({{amdgpu|nvptx}}
+// CHECK: offload, "device-sycl (spirv64-unknown-unknown:xe-pvc)"
+// CHECK-NOT: "device-sycl ({{amdgpu|nvptx}}
+
+/// Without an Intel GPU, SYCL reports that no GPU was found, as HIP and CUDA
+/// do.
+// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fsycl \
+// RUN: --offload-arch=native --offload-arch-tool=%t/offload_arch_sm_70_gfx90a \
+// RUN: -c %s 2>&1 | FileCheck -check-prefix=NO-GPU %s
+// NO-GPU: error: cannot determine sycl architecture: No GPU detected in the system
More information about the cfe-commits
mailing list