Skip to content

Commit 8890706

Browse files
committed
Revert "Reland [HIP] use offload wrapper for non-device-only non-rdc (#132869) (#143964)"
This reverts commit 22f9b4a.
1 parent 029f889 commit 8890706

File tree

8 files changed

+92
-168
lines changed

8 files changed

+92
-168
lines changed

clang/lib/CodeGen/CGCUDANV.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,8 +1280,7 @@ llvm::Function *CGNVCUDARuntime::finalizeModule() {
12801280
return nullptr;
12811281
}
12821282
if (CGM.getLangOpts().OffloadViaLLVM ||
1283-
(CGM.getLangOpts().OffloadingNewDriver &&
1284-
(CGM.getLangOpts().HIP || RelocatableDeviceCode)))
1283+
(CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode))
12851284
createOffloadingEntries();
12861285
else
12871286
return makeModuleCtorFunction();

clang/lib/Driver/Driver.cpp

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4423,10 +4423,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
44234423
options::OPT_no_offload_new_driver,
44244424
C.isOffloadingHostKind(Action::OFK_Cuda));
44254425

4426-
bool HIPNoRDC =
4427-
C.isOffloadingHostKind(Action::OFK_HIP) &&
4428-
!Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
4429-
44304426
// Builder to be used to build offloading actions.
44314427
std::unique_ptr<OffloadingActionBuilder> OffloadBuilder =
44324428
!UseNewOffloadingDriver
@@ -4560,7 +4556,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
45604556
// Check if this Linker Job should emit a static library.
45614557
if (ShouldEmitStaticLibrary(Args)) {
45624558
LA = C.MakeAction<StaticLibJobAction>(LinkerInputs, types::TY_Image);
4563-
} else if ((UseNewOffloadingDriver && !HIPNoRDC) ||
4559+
} else if (UseNewOffloadingDriver ||
45644560
Args.hasArg(options::OPT_offload_link)) {
45654561
LA = C.MakeAction<LinkerWrapperJobAction>(LinkerInputs, types::TY_Image);
45664562
LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
@@ -4871,31 +4867,10 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
48714867
const InputTy &Input, StringRef CUID,
48724868
Action *HostAction) const {
48734869
// Don't build offloading actions if explicitly disabled or we do not have a
4874-
// valid source input.
4875-
if (offloadHostOnly() || !types::isSrcFile(Input.first))
4876-
return HostAction;
4877-
4878-
bool HIPNoRDC =
4879-
C.isOffloadingHostKind(Action::OFK_HIP) &&
4880-
!Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
4881-
4882-
// For HIP non-rdc non-device-only compilation, create a linker wrapper
4883-
// action for each host object to link, bundle and wrap device files in
4884-
// it.
4885-
if ((isa<AssembleJobAction>(HostAction) ||
4886-
(isa<BackendJobAction>(HostAction) &&
4887-
HostAction->getType() == types::TY_LTO_BC)) &&
4888-
HIPNoRDC && !offloadDeviceOnly()) {
4889-
ActionList AL{HostAction};
4890-
HostAction = C.MakeAction<LinkerWrapperJobAction>(AL, types::TY_Object);
4891-
HostAction->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
4892-
/*BoundArch=*/nullptr);
4893-
return HostAction;
4894-
}
4895-
4896-
// Don't build offloading actions if we do not have a compile action. If
4897-
// preprocessing only ignore embedding.
4898-
if (!(isa<CompileJobAction>(HostAction) ||
4870+
// valid source input and compile action to embed it in. If preprocessing only
4871+
// ignore embedding.
4872+
if (offloadHostOnly() || !types::isSrcFile(Input.first) ||
4873+
!(isa<CompileJobAction>(HostAction) ||
48994874
getFinalPhase(Args) == phases::Preprocess))
49004875
return HostAction;
49014876

@@ -4991,12 +4966,12 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
49914966
}
49924967
}
49934968

4994-
// Compiling HIP in device-only non-RDC mode requires linking each action
4995-
// individually.
4969+
// Compiling HIP in non-RDC mode requires linking each action individually.
49964970
for (Action *&A : DeviceActions) {
49974971
if ((A->getType() != types::TY_Object &&
49984972
A->getType() != types::TY_LTO_BC) ||
4999-
!HIPNoRDC || !offloadDeviceOnly())
4973+
Kind != Action::OFK_HIP ||
4974+
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false))
50004975
continue;
50014976
ActionList LinkerInput = {A};
50024977
A = C.MakeAction<LinkJobAction>(LinkerInput, types::TY_Image);
@@ -5020,12 +4995,12 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
50204995
}
50214996
}
50224997

5023-
// HIP code in device-only non-RDC mode will bundle the output if it invoked
5024-
// the linker.
4998+
// HIP code in non-RDC mode will bundle the output if it invoked the linker.
50254999
bool ShouldBundleHIP =
5026-
HIPNoRDC && offloadDeviceOnly() &&
5000+
C.isOffloadingHostKind(Action::OFK_HIP) &&
50275001
Args.hasFlag(options::OPT_gpu_bundle_output,
50285002
options::OPT_no_gpu_bundle_output, true) &&
5003+
!Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false) &&
50295004
!llvm::any_of(OffloadActions,
50305005
[](Action *A) { return A->getType() != types::TY_Image; });
50315006

@@ -5045,9 +5020,11 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
50455020
C.MakeAction<LinkJobAction>(OffloadActions, types::TY_CUDA_FATBIN);
50465021
DDep.add(*FatbinAction, *C.getSingleOffloadToolChain<Action::OFK_Cuda>(),
50475022
nullptr, Action::OFK_Cuda);
5048-
} else if (HIPNoRDC && offloadDeviceOnly()) {
5049-
// If we are in device-only non-RDC-mode we just emit the final HIP
5050-
// fatbinary for each translation unit, linking each input individually.
5023+
} else if (C.isOffloadingHostKind(Action::OFK_HIP) &&
5024+
!Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
5025+
false)) {
5026+
// If we are not in RDC-mode we just emit the final HIP fatbinary for each
5027+
// translation unit, linking each input individually.
50515028
Action *FatbinAction =
50525029
C.MakeAction<LinkJobAction>(OffloadActions, types::TY_HIP_FATBIN);
50535030
DDep.add(*FatbinAction, *C.getSingleOffloadToolChain<Action::OFK_HIP>(),
@@ -5200,11 +5177,8 @@ Action *Driver::ConstructPhaseAction(
52005177
(((Input->getOffloadingToolChain() &&
52015178
Input->getOffloadingToolChain()->getTriple().isAMDGPU()) ||
52025179
TargetDeviceOffloadKind == Action::OFK_HIP) &&
5203-
((Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
5204-
false) ||
5205-
(Args.hasFlag(options::OPT_offload_new_driver,
5206-
options::OPT_no_offload_new_driver, false) &&
5207-
!offloadDeviceOnly())) ||
5180+
(Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc,
5181+
false) ||
52085182
TargetDeviceOffloadKind == Action::OFK_OpenMP))) {
52095183
types::ID Output =
52105184
Args.hasArg(options::OPT_S) &&

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7710,7 +7710,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
77107710
CmdArgs.push_back("-fcuda-include-gpubinary");
77117711
CmdArgs.push_back(CudaDeviceInput->getFilename());
77127712
} else if (!HostOffloadingInputs.empty()) {
7713-
if (IsCuda && !IsRDCMode) {
7713+
if ((IsCuda || IsHIP) && !IsRDCMode) {
77147714
assert(HostOffloadingInputs.size() == 1 && "Only one input expected");
77157715
CmdArgs.push_back("-fcuda-include-gpubinary");
77167716
CmdArgs.push_back(HostOffloadingInputs.front().getFilename());
@@ -9257,20 +9257,8 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
92579257
// Add the linker arguments to be forwarded by the wrapper.
92589258
CmdArgs.push_back(Args.MakeArgString(Twine("--linker-path=") +
92599259
LinkCommand->getExecutable()));
9260-
9261-
// We use action type to differentiate two use cases of the linker wrapper.
9262-
// TY_Image for normal linker wrapper work.
9263-
// TY_Object for HIP fno-gpu-rdc embedding device binary in a relocatable
9264-
// object.
9265-
assert(JA.getType() == types::TY_Object || JA.getType() == types::TY_Image);
9266-
if (JA.getType() == types::TY_Object) {
9267-
CmdArgs.append({"-o", Output.getFilename()});
9268-
for (auto Input : Inputs)
9269-
CmdArgs.push_back(Input.getFilename());
9270-
CmdArgs.push_back("-r");
9271-
} else
9272-
for (const char *LinkArg : LinkCommand->getArguments())
9273-
CmdArgs.push_back(LinkArg);
9260+
for (const char *LinkArg : LinkCommand->getArguments())
9261+
CmdArgs.push_back(LinkArg);
92749262

92759263
addOffloadCompressArgs(Args, CmdArgs);
92769264

clang/test/Driver/hip-binding.hip

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
// RUN: -nogpulib -nogpuinc -foffload-lto --offload-arch=gfx90a --offload-arch=gfx908 -c %s 2>&1 \
9494
// RUN: | FileCheck -check-prefix=LTO-NO-RDC %s
9595
// LTO-NO-RDC: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[LTO_908:.+]]"
96+
// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[LTO_908]]"], output: "[[OBJ_908:.+]]"
9697
// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "clang", inputs: ["[[INPUT]]"], output: "[[LTO_90A:.+]]"
97-
// LTO-NO-RDC-NEXT: # "x86_64-unknown-linux-gnu" - "Offload::Packager", inputs: ["[[LTO_908]]", "[[LTO_90A]]"], output: "[[PKG:.+]]"
98-
// LTO-NO-RDC-NEXT: # "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT]]", "[[PKG]]"], output: "[[OBJ:.+]]"
99-
// LTO-NO-RDC-NEXT: # "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[OBJ]]"], output: "hip-binding.o"
98+
// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[LTO_90A]]"], output: "[[OBJ_90A:.+]]"
99+
// LTO-NO-RDC-NEXT: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[OBJ_908]]", "[[OBJ_90A]]"], output: "[[HIPFB:.+]]"

clang/test/Driver/hip-phases.hip

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,39 @@
88
//
99
// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \
1010
// RUN: --no-offload-new-driver --cuda-gpu-arch=gfx803 %s 2>&1 \
11-
// RUN: | FileCheck -check-prefixes=BIN,OLD,OLDN %s
11+
// RUN: | FileCheck -check-prefixes=BIN,NRD,OLD %s
1212
// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \
1313
// RUN: --offload-new-driver --cuda-gpu-arch=gfx803 %s 2>&1 \
14-
// RUN: | FileCheck -check-prefixes=BIN,NEW,NEWN %s
15-
// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \
16-
// RUN: --offload-new-driver --cuda-gpu-arch=gfx803 -flto -c %s 2>&1 \
17-
// RUN: | FileCheck -check-prefixes=BIN,NEW,NEWLTO %s
14+
// RUN: | FileCheck -check-prefixes=BIN,NRD,NEW %s
1815
//
1916
// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \
2017
// RUN: --no-offload-new-driver --cuda-gpu-arch=gfx803 -fgpu-rdc %s 2>&1 \
21-
// RUN: | FileCheck -check-prefixes=BIN,OLD,OLDR %s
22-
// RUN: %clang -x hip --target=x86_64-unknown-linux-gnu -ccc-print-phases \
23-
// RUN: --offload-new-driver --cuda-gpu-arch=gfx803 -fgpu-rdc %s 2>&1 \
24-
// RUN: | FileCheck -check-prefixes=BIN,NEW,NEWR %s
18+
// RUN: | FileCheck -check-prefixes=BIN,RDC %s
2519
//
2620
// BIN-DAG: [[P0:[0-9]+]]: input, "{{.*}}hip-phases.hip", [[T:hip]], (host-[[T]])
2721
// BIN-DAG: [[P1:[0-9]+]]: preprocessor, {[[P0]]}, [[T]]-cpp-output, (host-[[T]])
2822
// BIN-DAG: [[P2:[0-9]+]]: compiler, {[[P1]]}, ir, (host-[[T]])
29-
// OLDR-DAG: [[P12:[0-9]+]]: backend, {[[P2]]}, assembler, (host-[[T]])
30-
// OLDR-DAG: [[P13:[0-9]+]]: assembler, {[[P12]]}, object, (host-[[T]])
23+
// RDC-DAG: [[P12:[0-9]+]]: backend, {[[P2]]}, assembler, (host-[[T]])
24+
// RDC-DAG: [[P13:[0-9]+]]: assembler, {[[P12]]}, object, (host-[[T]])
3125

3226
// BIN-DAG: [[P3:[0-9]+]]: input, "{{.*}}hip-phases.hip", [[T]], (device-[[T]], [[ARCH:gfx803]])
3327
// BIN-DAG: [[P4:[0-9]+]]: preprocessor, {[[P3]]}, [[T]]-cpp-output, (device-[[T]], [[ARCH]])
3428
// BIN-DAG: [[P5:[0-9]+]]: compiler, {[[P4]]}, ir, (device-[[T]], [[ARCH]])
35-
// OLDN-DAG: [[P6:[0-9]+]]: backend, {[[P5]]}, assembler, (device-[[T]], [[ARCH]])
36-
// NEW-DAG: [[P6:[0-9]+]]: backend, {[[P5]]}, ir, (device-[[T]], [[ARCH]])
37-
// OLDN-DAG: [[P7:[0-9]+]]: assembler, {[[P6]]}, object, (device-[[T]], [[ARCH]])
38-
// OLDR-DAG: [[P7:[0-9]+]]: backend, {[[P5]]}, ir, (device-[[T]], [[ARCH]])
39-
// OLD-DAG: [[P8:[0-9]+]]: linker, {[[P7]]}, image, (device-[[T]], [[ARCH]])
40-
// OLD-DAG: [[P9:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa:[[ARCH]])" {[[P8]]}, image
41-
// NEW-DAG: [[P9:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa:[[ARCH]])" {[[P6]]}, ir
42-
// OLDN-DAG: [[P10:[0-9]+]]: linker, {[[P9]]}, hip-fatbin, (device-[[T]])
43-
// NEW-DAG: [[P10:[0-9]+]]: clang-offload-packager, {[[P9]]}, image, (device-[[T]])
44-
// OLDR-DAG: [[P10:[0-9]+]]: linker, {[[P9]]}, object, (device-[[T]])
45-
46-
// OLDN-DAG: [[P11:[0-9]+]]: offload, "host-[[T]] (x86_64-unknown-linux-gnu)" {[[P2]]}, "device-[[T]] (amdgcn-amd-amdhsa)" {[[P10]]}, ir
47-
// NEW-DAG: [[P11:[0-9]+]]: offload, "host-[[T]] (x86_64-unknown-linux-gnu)" {[[P2]]}, "device-[[T]] (x86_64-unknown-linux-gnu)" {[[P10]]}, ir
48-
// OLDR-DAG: [[P11:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa)" {[[P10]]}, object
49-
// OLDN-DAG: [[P12:[0-9]+]]: backend, {[[P11]]}, assembler, (host-[[T]])
50-
// OLDN-DAG: [[P13:[0-9]+]]: assembler, {[[P12]]}, object, (host-[[T]])
51-
// NEWN-DAG: [[P12:[0-9]+]]: backend, {[[P11]]}, assembler, (host-[[T]])
52-
// NEWN-DAG: [[P13:[0-9]+]]: assembler, {[[P12]]}, object, (host-[[T]])
53-
// NEWLTO-DAG: [[P13:[0-9]+]]: backend, {[[P11]]}, lto-bc, (host-hip)
54-
// NEWR-DAG: [[P12:[0-9]+]]: backend, {[[P11]]}, assembler, (host-[[T]])
55-
// NEWR-DAG: [[P13:[0-9]+]]: assembler, {[[P12]]}, object, (host-[[T]])
56-
// OLDN-DAG: [[P14:[0-9]+]]: linker, {[[P13]]}, image, (host-[[T]])
57-
// NEWN-DAG: [[P14:[0-9]+]]: clang-linker-wrapper, {[[P13]]}, object, (host-[[T]])
58-
// NEWLTO-DAG: [[P14:[0-9]+]]: clang-linker-wrapper, {[[P13]]}, object, (host-[[T]])
59-
// OLDR-DAG: [[P14:[0-9]+]]: linker, {[[P13]], [[P11]]}, image, (host-[[T]])
60-
// NEWR-DAG: [[P14:[0-9]+]]: clang-linker-wrapper, {[[P13]]}, image, (host-[[T]])
61-
// NEWN-DAG: [[P15:[0-9]+]]: linker, {[[P14]]}, image
29+
// NRD-DAG: [[P6:[0-9]+]]: backend, {[[P5]]}, assembler, (device-[[T]], [[ARCH]])
30+
// NRD-DAG: [[P7:[0-9]+]]: assembler, {[[P6]]}, object, (device-[[T]], [[ARCH]])
31+
// RDC-DAG: [[P7:[0-9]+]]: backend, {[[P5]]}, ir, (device-[[T]], [[ARCH]])
32+
// BIN-DAG: [[P8:[0-9]+]]: linker, {[[P7]]}, image, (device-[[T]], [[ARCH]])
33+
// BIN-DAG: [[P9:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa:[[ARCH]])" {[[P8]]}, image
34+
// NRD-DAG: [[P10:[0-9]+]]: linker, {[[P9]]}, hip-fatbin, (device-[[T]])
35+
// RDC-DAG: [[P10:[0-9]+]]: linker, {[[P9]]}, object, (device-[[T]])
36+
37+
// NRD-DAG: [[P11:[0-9]+]]: offload, "host-[[T]] (x86_64-unknown-linux-gnu)" {[[P2]]}, "device-[[T]] (amdgcn-amd-amdhsa)" {[[P10]]}, ir
38+
// RDC-DAG: [[P11:[0-9]+]]: offload, "device-[[T]] (amdgcn-amd-amdhsa)" {[[P10]]}, object
39+
// NRD-DAG: [[P12:[0-9]+]]: backend, {[[P11]]}, assembler, (host-[[T]])
40+
// NRD-DAG: [[P13:[0-9]+]]: assembler, {[[P12]]}, object, (host-[[T]])
41+
// OLD-DAG: [[P14:[0-9]+]]: linker, {[[P13]]}, image, (host-[[T]])
42+
// NEW-DAG: [[P14:[0-9]+]]: clang-linker-wrapper, {[[P13]]}, image, (host-[[T]])
43+
// RDC-DAG: [[P14:[0-9]+]]: linker, {[[P13]], [[P11]]}, image, (host-[[T]])
6244

6345
//
6446
// Test single gpu architecture up to the assemble phase.

0 commit comments

Comments
 (0)