Author: Srividya Sundaram Date: 2026-11-03T10:58:15-08:00 New Revision: 921fdd3ec5c0e4510e8f8c7473630dae7dbc54b7
URL: https://github.com/llvm/llvm-project/commit/921fdd3ec5c0e4510e8f8c7473630dae7dbc54b7 DIFF: https://github.com/llvm/llvm-project/commit/921fdd3ec5c0e4510e8f8c7473630dae7dbc54b7.diff LOG: [Clang][SYCL] Reject an NVIDIA offload target for SYCL (#229937) Reject an NVIDIA offload target for SYCL. Previously, `clang++ -fsycl --offload-arch=sm_80`, or `--offload-targets=nvptx64-nvidia-cuda`, hit an assertion in the CUDA toolchain, which supports only CUDA and OpenMP. Clang does not support SYCL offloading to NVIDIA GPUs without `-foffload-via-llvm`, so the driver now reports "invalid or unsupported offload target" instead. With `-foffload-via-llvm`, SYCL offloading to an NVIDIA GPU is unchanged. Added: Modified: clang/lib/Driver/Driver.cpp clang/test/Driver/sycl-offload-arch-igca.cpp clang/test/Driver/sycl-offload-jit.cpp Removed: ################################################################################ diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 37fb69baf6a3e..ce28ca4934a9a 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -1167,6 +1167,8 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C, // Build an offloading toolchain for every requested target and kind. llvm::StringMap<StringRef> FoundNormalizedTriples; + bool UsesLLVMOffloading = C.getInputArgs().hasFlag( + options::OPT_foffload_via_llvm, options::OPT_fno_offload_via_llvm, false); for (const llvm::Triple &Target : Triples) { // OpenMP offloading requires a compatible libomp. if (Kinds.contains(Action::OFK_OpenMP)) { @@ -1184,6 +1186,14 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C, if (Arg *IncompatArg = C.getInputArgs().getLastArg(ID)) Diag(clang::diag::err_drv_argument_not_allowed_with) << IncompatArg->getSpelling() << "-fsycl"; + + // The CUDA toolchain supports only CUDA and OpenMP, so diagnose SYCL + // offloading to an NVIDIA GPU here, unless it uses -foffload-via-llvm. + if (Target.isNVPTX() && !UsesLLVMOffloading) { + Diag(diag::err_drv_invalid_or_unsupported_offload_target) + << Target.str(); + continue; + } } // Create a device toolchain for every specified kind and triple. diff --git a/clang/test/Driver/sycl-offload-arch-igca.cpp b/clang/test/Driver/sycl-offload-arch-igca.cpp index 7a3a2b4f7d7ac..f8646c0faef4d 100644 --- a/clang/test/Driver/sycl-offload-arch-igca.cpp +++ b/clang/test/Driver/sycl-offload-arch-igca.cpp @@ -20,12 +20,13 @@ // CHK-FEATURE: error: unsupported IGCA gpu architecture: igca_20ca:foo // CHK-FEATURE-NOT: llvm-offload-binary -/// A valid IGCA target is still rejected on NVPTX and AMDGPU device triples, -/// with the existing CUDA/HIP diagnostic: +/// A valid IGCA target is still rejected on NVPTX and AMDGPU device triples. +/// SYCL rejects an NVIDIA target itself, and AMDGPU uses the existing HIP +/// diagnostic: // RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fsycl \ // RUN: --offload-targets=nvptx64-nvidia-cuda --offload-arch=igca_20ca \ // RUN: -c %s 2>&1 | FileCheck -check-prefix=CHK-NVPTX %s -// CHK-NVPTX: error: unsupported CUDA gpu architecture: igca_20ca +// CHK-NVPTX: error: invalid or unsupported offload target: 'nvptx64-nvidia-cuda' // CHK-NVPTX-NOT: llvm-offload-binary // RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fsycl \ diff --git a/clang/test/Driver/sycl-offload-jit.cpp b/clang/test/Driver/sycl-offload-jit.cpp index ab38aad61ca6d..40b6a9ede9ed8 100644 --- a/clang/test/Driver/sycl-offload-jit.cpp +++ b/clang/test/Driver/sycl-offload-jit.cpp @@ -95,6 +95,21 @@ // CHK-PHASES-NORDC-ARCHS-NEXT: 13: llvm-offload-binary, {7, 12}, image, (device-sycl) // CHK-PHASES-NORDC-ARCHS-NEXT: 14: clang-linker-wrapper, {13}, sycl-fatbin, (device-sycl) +/// Clang does not support SYCL offloading to NVIDIA GPUs without +/// -foffload-via-llvm. +// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fsycl \ +// RUN: --offload-arch=sm_80 -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHK-NVPTX %s +// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fsycl \ +// RUN: --offload-targets=nvptx64-nvidia-cuda -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHK-NVPTX %s +// CHK-NVPTX: error: invalid or unsupported offload target: 'nvptx64-nvidia-cuda' +// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fsycl -foffload-via-llvm \ +// RUN: --offload-arch=sm_80 -c %s 2>&1 \ +// RUN: | FileCheck -check-prefix=CHK-NVPTX-VIA-LLVM %s +// CHK-NVPTX-VIA-LLVM-NOT: error: +// CHK-NVPTX-VIA-LLVM: "-cc1" "-triple" "nvptx64-nvidia-cuda-llvm" + /// Multiple device triples are not supported today in non-RDC mode. // RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fsycl -fno-gpu-rdc \ // RUN: --offload-targets=spirv64-unknown-unknown,spirv32-unknown-unknown -c %s 2>&1 \ _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
