https://github.com/yxsamliu created https://github.com/llvm/llvm-project/pull/214310
Clang reported `--offload-jobs` as unused when an individual compilation had no device work that could run in parallel. CMake tests compiler options with `-Werror`, so this warning made option detection fail. It also caused unnecessary build errors and CMake workarounds in projects targeting one or several GPU architectures. `--offload-jobs` sets the maximum number of parallel jobs, not a required number. A compilation with fewer jobs, including zero or one, is valid and should not produce an unused argument warning. Claim and validate the option independently of whether parallel device jobs are found. Keep job discovery responsible only for marking work that can run in parallel. >From 4408b300d5fd91c8d6a33d84f7e66fbee5e8f654 Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" <[email protected]> Date: Wed, 5 Aug 2026 14:41:54 -0400 Subject: [PATCH] [Clang][Driver] Accept `--offload-jobs` without parallel work Clang reported `--offload-jobs` as unused when an individual compilation had no device work that could run in parallel. CMake tests compiler options with `-Werror`, so this warning made option detection fail. It also caused unnecessary build errors and CMake workarounds in projects targeting one or several GPU architectures. `--offload-jobs` sets the maximum number of parallel jobs, not a required number. A compilation with fewer jobs, including zero or one, is valid and should not produce an unused argument warning. Claim and validate the option independently of whether parallel device jobs are found. Keep job discovery responsible only for marking work that can run in parallel. --- clang/lib/Driver/Driver.cpp | 6 +----- clang/test/Driver/offload-parallel-device-cc1.cu | 3 +++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 3b5d0c0aad981..81590a6fbc113 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5495,18 +5495,13 @@ static void claimAndDiagnoseOffloadJobs(const Driver &D, const ArgList &Args) { } static void markOffloadDeviceCC1JobsForParallelExecution(Compilation &C) { - bool FoundCandidate = false; for (auto &Job : C.getJobs()) { if (!isOffloadDeviceCC1JobCandidate(Job)) continue; Job.setOffloadDeviceParallelJobGroup( getOffloadDeviceCC1ParallelJobGroup(Job)); - FoundCandidate = true; } - - if (FoundCandidate) - claimAndDiagnoseOffloadJobs(C.getDriver(), C.getArgs()); } void Driver::BuildJobs(Compilation &C) const { @@ -5610,6 +5605,7 @@ void Driver::BuildJobs(Compilation &C) const { J.InProcess = false; markOffloadDeviceCC1JobsForParallelExecution(C); + claimAndDiagnoseOffloadJobs(*this, C.getArgs()); if (CCPrintProcessStats) { C.setPostCallback([=](const Command &Cmd, int Res) { diff --git a/clang/test/Driver/offload-parallel-device-cc1.cu b/clang/test/Driver/offload-parallel-device-cc1.cu index 3d8447b1cd4a8..1689825df196e 100644 --- a/clang/test/Driver/offload-parallel-device-cc1.cu +++ b/clang/test/Driver/offload-parallel-device-cc1.cu @@ -2,6 +2,9 @@ // REQUIRES: nvptx-registered-target, lld // RUN: rm -rf %t && mkdir -p %t +// RUN: %clang -x c++ --offload-jobs=1 -Werror -c %s -o %t/host.o +// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \ +// RUN: --offload-arch=gfx900 --offload-jobs=1 -Werror -E %s -o %t/hip.i // RUN: %clang -x hip --target=x86_64-unknown-linux-gnu \ // RUN: -nostdinc -nogpuinc -nohipwrapperinc -nogpulib \ // RUN: --offload-arch=gfx900 --offload-arch=gfx906 --offload-jobs=2 \ _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
