Skip to content

Commit 9332f1e

Browse files
authored
[Clang] add option --offload-jobs=N (#135229)
for specifying number of threads for clang-linker-wrapper.
1 parent f5c5f9f commit 9332f1e

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,10 @@ def offload_compression_level_EQ : Joined<["--"], "offload-compression-level=">,
12341234
Flags<[HelpHidden]>,
12351235
HelpText<"Compression level for offload device binaries (HIP only)">;
12361236

1237+
def offload_jobs_EQ : Joined<["--"], "offload-jobs=">,
1238+
HelpText<"Specify the number of threads to use for device offloading tasks"
1239+
" during compilation.">;
1240+
12371241
defm offload_via_llvm : BoolFOption<"offload-via-llvm",
12381242
LangOpts<"OffloadViaLLVM">, DefaultFalse,
12391243
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Use">,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
10311031
if (JA.isOffloading(Action::OFK_HIP)) {
10321032
Args.ClaimAllArgs(options::OPT_offload_compress);
10331033
Args.ClaimAllArgs(options::OPT_no_offload_compress);
1034+
Args.ClaimAllArgs(options::OPT_offload_jobs_EQ);
10341035
}
10351036

10361037
bool HasTarget = false;
@@ -9361,6 +9362,18 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
93619362
CmdArgs.push_back(LinkArg);
93629363

93639364
addOffloadCompressArgs(Args, CmdArgs);
9365+
9366+
if (Arg *A = Args.getLastArg(options::OPT_offload_jobs_EQ)) {
9367+
int NumThreads;
9368+
if (StringRef(A->getValue()).getAsInteger(10, NumThreads) ||
9369+
NumThreads <= 0)
9370+
C.getDriver().Diag(diag::err_drv_invalid_int_value)
9371+
<< A->getAsString(Args) << A->getValue();
9372+
else
9373+
CmdArgs.push_back(
9374+
Args.MakeArgString("--wrapper-jobs=" + Twine(NumThreads)));
9375+
}
9376+
93649377
const char *Exec =
93659378
Args.MakeArgString(getToolChain().GetProgramPath("clang-linker-wrapper"));
93669379

clang/test/Driver/hip-options.hip

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,19 @@
243243
// NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-Werror=atomic-alignment"
244244
// NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-Wno-error=atomic-alignment"
245245

246-
// Check --offload-compress does not cause warning.
246+
// Check --offload-compress --offload-jobs=N does not cause warning.
247247
// RUN: %clang -### -Werror --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
248-
// RUN: --offload-arch=gfx1100 --offload-compress --offload-host-only -M %s
248+
// RUN: --offload-arch=gfx1100 --offload-compress --offload-host-only -M %s \
249+
// RUN: --offload-jobs=4
250+
251+
// Check --offload-jobs=N option.
252+
253+
// RUN: %clang -### -Werror --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
254+
// RUN: --offload-arch=gfx1100 --offload-new-driver --offload-jobs=4 %s 2>&1 | \
255+
// RUN: FileCheck -check-prefix=JOBS %s
256+
// JOBS: clang-linker-wrapper{{.*}} "--wrapper-jobs=4"
257+
258+
// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
259+
// RUN: --offload-arch=gfx1100 --offload-new-driver --offload-jobs=0x4 %s 2>&1 | \
260+
// RUN: FileCheck -check-prefix=INVJOBS %s
261+
// INVJOBS: clang: error: invalid integral value '0x4' in '--offload-jobs=0x4'

0 commit comments

Comments
 (0)