Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,10 @@ def offload_compression_level_EQ : Joined<["--"], "offload-compression-level=">,
Flags<[HelpHidden]>,
HelpText<"Compression level for offload device binaries (HIP only)">;

def offload_jobs_EQ : Joined<["--"], "offload-jobs=">,
HelpText<"Specify the number of threads to use for device offloading tasks"
" during compilation.">;

defm offload_via_llvm : BoolFOption<"offload-via-llvm",
LangOpts<"OffloadViaLLVM">, DefaultFalse,
PosFlag<SetTrue, [], [ClangOption, CC1Option], "Use">,
Expand Down
13 changes: 13 additions & 0 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,7 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
if (JA.isOffloading(Action::OFK_HIP)) {
Args.ClaimAllArgs(options::OPT_offload_compress);
Args.ClaimAllArgs(options::OPT_no_offload_compress);
Args.ClaimAllArgs(options::OPT_offload_jobs_EQ);
}

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

addOffloadCompressArgs(Args, CmdArgs);

if (Arg *A = Args.getLastArg(options::OPT_offload_jobs_EQ)) {
int NumThreads;
if (StringRef(A->getValue()).getAsInteger(10, NumThreads) ||
NumThreads <= 0)
C.getDriver().Diag(diag::err_drv_invalid_int_value)
<< A->getAsString(Args) << A->getValue();
else
CmdArgs.push_back(
Args.MakeArgString("--wrapper-jobs=" + Twine(NumThreads)));
}

const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath("clang-linker-wrapper"));

Expand Down
17 changes: 15 additions & 2 deletions clang/test/Driver/hip-options.hip
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@
// NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-Werror=atomic-alignment"
// NO-WARN-ATOMIC-NOT: clang{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-Wno-error=atomic-alignment"

// Check --offload-compress does not cause warning.
// Check --offload-compress --offload-jobs=N does not cause warning.
// RUN: %clang -### -Werror --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
// RUN: --offload-arch=gfx1100 --offload-compress --offload-host-only -M %s
// RUN: --offload-arch=gfx1100 --offload-compress --offload-host-only -M %s \
// RUN: --offload-jobs=4

// Check --offload-jobs=N option.

// RUN: %clang -### -Werror --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
// RUN: --offload-arch=gfx1100 --offload-new-driver --offload-jobs=4 %s 2>&1 | \
// RUN: FileCheck -check-prefix=JOBS %s
// JOBS: clang-linker-wrapper{{.*}} "--wrapper-jobs=4"

// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
// RUN: --offload-arch=gfx1100 --offload-new-driver --offload-jobs=0x4 %s 2>&1 | \
// RUN: FileCheck -check-prefix=INVJOBS %s
// INVJOBS: clang: error: invalid integral value '0x4' in '--offload-jobs=0x4'
Loading