Skip to content

Commit d1d80cc

Browse files
authored
[HIP] Make the new driver bundle outputs for device-only (#84534)
Summary: The current behavior of HIP is that when --offload-device-only is set it still bundles the outputs into a fat binary. Even though this is different from how all the other targets handle this, it seems to be dependned on by some tooling so just make it backwards compatible for the `-fno-gpu-rdc` case.
1 parent eaa71a9 commit d1d80cc

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4638,7 +4638,12 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
46384638
}
46394639
}
46404640

4641-
if (offloadDeviceOnly())
4641+
// All kinds exit now in device-only mode except for non-RDC mode HIP.
4642+
if (offloadDeviceOnly() &&
4643+
(!C.isOffloadingHostKind(Action::OFK_HIP) ||
4644+
!Args.hasFlag(options::OPT_gpu_bundle_output,
4645+
options::OPT_no_gpu_bundle_output, true) ||
4646+
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false)))
46424647
return C.MakeAction<OffloadAction>(DDeps, types::TY_Nothing);
46434648

46444649
if (OffloadActions.empty())
@@ -4671,6 +4676,10 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
46714676
nullptr, C.getActiveOffloadKinds());
46724677
}
46734678

4679+
// HIP wants '--offload-device-only' to create a fatbinary by default.
4680+
if (offloadDeviceOnly())
4681+
return C.MakeAction<OffloadAction>(DDep, types::TY_Nothing);
4682+
46744683
// If we are unable to embed a single device output into the host, we need to
46754684
// add each device output as a host dependency to ensure they are still built.
46764685
bool SingleDeviceOutput = !llvm::any_of(OffloadActions, [](Action *A) {

clang/test/Driver/hip-binding.hip

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,18 @@
6565
// MULTI-D-ONLY-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX90a]]"], output: "[[GFX90a_OUT:.+]]"
6666
//
6767
// RUN: not %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-bindings -nogpulib -nogpuinc \
68-
// RUN: --offload-arch=gfx90a --offload-arch=gfx908 --offload-device-only -c -o %t %s 2>&1 \
68+
// RUN: --no-gpu-bundle-output --offload-arch=gfx90a --offload-arch=gfx908 --offload-device-only -c -o %t %s 2>&1 \
69+
// RUN: | FileCheck -check-prefix=MULTI-D-ONLY-NO-BUNDLE-O %s
70+
// MULTI-D-ONLY-NO-BUNDLE-O: error: cannot specify -o when generating multiple output files
71+
72+
// RUN: %clang -### --target=x86_64-linux-gnu --offload-new-driver -ccc-print-bindings -nogpulib -nogpuinc \
73+
// RUN: --gpu-bundle-output --offload-arch=gfx90a --offload-arch=gfx908 --offload-device-only -c -o a.out %s 2>&1 \
6974
// RUN: | FileCheck -check-prefix=MULTI-D-ONLY-O %s
70-
// MULTI-D-ONLY-O: error: cannot specify -o when generating multiple output files
75+
// MULTI-D-ONLY-O: "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[GFX908_OBJ:.+]]"
76+
// MULTI-D-ONLY-O-NEXT: "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX908_OBJ]]"], output: "[[GFX908:.+]]"
77+
// MULTI-D-ONLY-O-NEXT: "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[GFX90A_OBJ:.+]]"
78+
// MULTI-D-ONLY-O-NEXT: "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX90A_OBJ]]"], output: "[[GFX90A:.+]]"
79+
// MULTI-D-ONLY-O-NEXT: "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX908]]", "[[GFX90A]]"], output: "a.out"
7180

7281
//
7382
// Check to ensure that we can use '-fsyntax-only' for HIP output with the new

0 commit comments

Comments
 (0)