Skip to content

Commit

Permalink
[HIP] Correctly omit bundling with the new driver (llvm#85842)
Browse files Browse the repository at this point in the history
Summary:
The HIP phases do not emit the offload bundler output when we do not
invoke the final linker phase in device only mode. Check this propery.
  • Loading branch information
jhuber6 authored and chencha3 committed Mar 22, 2024
1 parent 42b5459 commit 09b7118
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 10 additions & 6 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4645,13 +4645,17 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
}
}

// HIP code in non-RDC mode will bundle the output if it invoked the linker.
bool ShouldBundleHIP =
C.isOffloadingHostKind(Action::OFK_HIP) &&
Args.hasFlag(options::OPT_gpu_bundle_output,
options::OPT_no_gpu_bundle_output, true) &&
!Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false) &&
!llvm::any_of(OffloadActions,
[](Action *A) { return A->getType() != types::TY_Image; });

// All kinds exit now in device-only mode except for non-RDC mode HIP.
if (offloadDeviceOnly() &&
(getFinalPhase(Args) == phases::Preprocess ||
!C.isOffloadingHostKind(Action::OFK_HIP) ||
!Args.hasFlag(options::OPT_gpu_bundle_output,
options::OPT_no_gpu_bundle_output, true) ||
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false)))
if (offloadDeviceOnly() && !ShouldBundleHIP)
return C.MakeAction<OffloadAction>(DDeps, types::TY_Nothing);

if (OffloadActions.empty())
Expand Down
12 changes: 12 additions & 0 deletions clang/test/Driver/hip-phases.hip
Original file line number Diff line number Diff line change
Expand Up @@ -648,3 +648,15 @@
// LTO-NEXT: 14: offload, "host-hip (x86_64-unknown-linux-gnu)" {2}, "device-hip (x86_64-unknown-linux-gnu)" {13}, ir
// LTO-NEXT: 15: backend, {14}, assembler, (host-hip)
// LTO-NEXT: 16: assembler, {15}, object, (host-hip)

//
// Test the new driver when not bundling
//
// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-phases \
// RUN: --offload-device-only --offload-arch=gfx90a -emit-llvm -c %s 2>&1 \
// RUN: | FileCheck -check-prefix=DEVICE-ONLY %s
// DEVICE-ONLY: 0: input, "[[INPUT:.+]]", hip, (device-hip, gfx90a)
// DEVICE-ONLY-NEXT: 1: preprocessor, {0}, hip-cpp-output, (device-hip, gfx90a)
// DEVICE-ONLY-NEXT: 2: compiler, {1}, ir, (device-hip, gfx90a)
// DEVICE-ONLY-NEXT: 3: backend, {2}, ir, (device-hip, gfx90a)
// DEVICE-ONLY-NEXT: 4: offload, "device-hip (amdgcn-amd-amdhsa:gfx90a)" {3}, none

0 comments on commit 09b7118

Please sign in to comment.