Skip to content

Commit 1d22692

Browse files
committed
[HIP] Make the new driver bundle outputs for device-only
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 9d30f11 commit 1d22692

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4638,7 +4638,10 @@ 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_fgpu_rdc, options::OPT_fno_gpu_rdc, false)))
46424645
return C.MakeAction<OffloadAction>(DDeps, types::TY_Nothing);
46434646

46444647
if (OffloadActions.empty())
@@ -4671,6 +4674,10 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
46714674
nullptr, C.getActiveOffloadKinds());
46724675
}
46734676

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

clang/test/Driver/hip-binding.hip

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@
6464
// MULTI-D-ONLY-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[GFX90a:.+]]"
6565
// MULTI-D-ONLY-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX90a]]"], output: "[[GFX90a_OUT:.+]]"
6666
//
67-
// 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 \
67+
// RUN: %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 a.out %s 2>&1 \
6969
// RUN: | FileCheck -check-prefix=MULTI-D-ONLY-O %s
70-
// MULTI-D-ONLY-O: error: cannot specify -o when generating multiple output files
70+
// MULTI-D-ONLY-O: "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[GFX908_OBJ:.+]]"
71+
// MULTI-D-ONLY-O-NEXT: "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX908_OBJ]]"], output: "[[GFX908:.+]]"
72+
// MULTI-D-ONLY-O-NEXT: "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[GFX90A_OBJ:.+]]"
73+
// MULTI-D-ONLY-O-NEXT: "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX90A_OBJ]]"], output: "[[GFX90A:.+]]"
74+
// MULTI-D-ONLY-O-NEXT: "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[GFX908]]", "[[GFX90A]]"], output: "a.out"
7175

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

0 commit comments

Comments
 (0)