Skip to content

Commit c6274d5

Browse files
committed
[HIP] Move HIP to the new driver by default
Summary: This patch matches CUDA, moving the HIP compilation jobs to the new driver by default. The old behavior will return with `--no-offload-new-driver`. The main difference is that objects compiled with the old driver are no longer compatible and will need to be recompiled or the old driver used. Fix after offload binary change
1 parent 515924f commit c6274d5

22 files changed

+92
-119
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,15 +4403,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
44034403
void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
44044404
const InputList &Inputs,
44054405
ActionList &Actions) const {
4406-
4407-
bool UseNewOffloadingDriver =
4408-
C.isOffloadingHostKind(Action::OFK_OpenMP) ||
4409-
C.isOffloadingHostKind(Action::OFK_SYCL) ||
4410-
Args.hasFlag(options::OPT_foffload_via_llvm,
4411-
options::OPT_fno_offload_via_llvm, false) ||
4412-
Args.hasFlag(options::OPT_offload_new_driver,
4413-
options::OPT_no_offload_new_driver,
4414-
C.isOffloadingHostKind(Action::OFK_Cuda));
4406+
bool UseNewOffloadingDriver = Args.hasFlag(
4407+
options::OPT_offload_new_driver, options::OPT_no_offload_new_driver,
4408+
C.getActiveOffloadKinds() != Action::OFK_None);
44154409

44164410
// Builder to be used to build offloading actions.
44174411
std::unique_ptr<OffloadingActionBuilder> OffloadBuilder =
@@ -5018,8 +5012,8 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
50185012
bool ShouldBundleHIP =
50195013
Args.hasFlag(options::OPT_gpu_bundle_output,
50205014
options::OPT_no_gpu_bundle_output, false) ||
5021-
(HIPNoRDC && offloadDeviceOnly() &&
5022-
llvm::none_of(OffloadActions, [](Action *A) {
5015+
(!Args.getLastArg(options::OPT_no_gpu_bundle_output) && HIPNoRDC &&
5016+
offloadDeviceOnly() && llvm::none_of(OffloadActions, [](Action *A) {
50235017
return A->getType() != types::TY_Image;
50245018
}));
50255019

@@ -5195,7 +5189,8 @@ Action *Driver::ConstructPhaseAction(
51955189
// offload driver, where mid-end is done in linker wrapper.
51965190
if (TargetDeviceOffloadKind == Action::OFK_HIP &&
51975191
Args.hasFlag(options::OPT_offload_new_driver,
5198-
options::OPT_no_offload_new_driver, false) &&
5192+
options::OPT_no_offload_new_driver,
5193+
C.getActiveOffloadKinds() != Action::OFK_None) &&
51995194
!offloadDeviceOnly())
52005195
return Input;
52015196

@@ -5215,8 +5210,13 @@ Action *Driver::ConstructPhaseAction(
52155210
Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
52165211
return C.MakeAction<BackendJobAction>(Input, Output);
52175212
}
5213+
5214+
bool IsAMDGCNSPIRV = Input->getOffloadingToolChain() &&
5215+
Input->getOffloadingToolChain()->getTriple().getOS() ==
5216+
llvm::Triple::OSType::AMDHSA &&
5217+
Input->getOffloadingToolChain()->getTriple().isSPIRV();
52185218
if (Args.hasArg(options::OPT_emit_llvm) ||
5219-
TargetDeviceOffloadKind == Action::OFK_SYCL ||
5219+
TargetDeviceOffloadKind == Action::OFK_SYCL || IsAMDGCNSPIRV ||
52205220
(((Input->getOffloadingToolChain() &&
52215221
Input->getOffloadingToolChain()->getTriple().isAMDGPU() &&
52225222
TargetDeviceOffloadKind != Action::OFK_None) ||
@@ -5237,7 +5237,8 @@ Action *Driver::ConstructPhaseAction(
52375237
(TargetDeviceOffloadKind == Action::OFK_HIP &&
52385238
!Args.hasFlag(options::OPT_offload_new_driver,
52395239
options::OPT_no_offload_new_driver,
5240-
C.isOffloadingHostKind(Action::OFK_Cuda))))
5240+
C.getActiveOffloadKinds() !=
5241+
Action::OFK_None)))
52415242
? types::TY_LLVM_IR
52425243
: types::TY_LLVM_BC;
52435244
return C.MakeAction<BackendJobAction>(Input, Output);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4804,7 +4804,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
48044804
(JA.isHostOffloading(C.getActiveOffloadKinds()) &&
48054805
Args.hasFlag(options::OPT_offload_new_driver,
48064806
options::OPT_no_offload_new_driver,
4807-
C.isOffloadingHostKind(Action::OFK_Cuda)));
4807+
C.getActiveOffloadKinds() != Action::OFK_None));
48084808

48094809
bool IsRDCMode =
48104810
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
@@ -5169,7 +5169,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51695169
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) &&
51705170
!Args.hasFlag(options::OPT_offload_new_driver,
51715171
options::OPT_no_offload_new_driver,
5172-
C.isOffloadingHostKind(Action::OFK_Cuda)) &&
5172+
C.getActiveOffloadKinds() != Action::OFK_None) &&
51735173
!Triple.isAMDGPU()) {
51745174
D.Diag(diag::err_drv_unsupported_opt_for_target)
51755175
<< Args.getLastArg(options::OPT_foffload_lto,
@@ -6651,7 +6651,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
66516651
CmdArgs.append({"--offload-new-driver", "-foffload-via-llvm"});
66526652
} else if (Args.hasFlag(options::OPT_offload_new_driver,
66536653
options::OPT_no_offload_new_driver,
6654-
C.isOffloadingHostKind(Action::OFK_Cuda))) {
6654+
C.getActiveOffloadKinds() != Action::OFK_None)) {
66556655
CmdArgs.push_back("--offload-new-driver");
66566656
}
66576657

@@ -9084,6 +9084,7 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
90849084
OPT_fno_lto,
90859085
OPT_flto,
90869086
OPT_flto_partitions_EQ,
9087+
OPT_hipspv_pass_plugin_EQ,
90879088
OPT_flto_EQ};
90889089
const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm, OPT_Zlinker_input};
90899090
auto ShouldForwardForToolChain = [&](Arg *A, const ToolChain &TC) {

clang/lib/Driver/ToolChains/Darwin.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,9 @@ void darwin::Linker::ConstructJob(Compilation &C, const JobAction &JA,
573573
const InputInfoList &Inputs,
574574
const ArgList &Args,
575575
const char *LinkingOutput) const {
576-
assert(Output.getType() == types::TY_Image && "Invalid linker output type.");
576+
assert((Output.getType() == types::TY_Image ||
577+
Output.getType() == types::TY_Object) &&
578+
"Invalid linker output type.");
577579

578580
// If the number of arguments surpasses the system limits, we will encode the
579581
// input files in a separate file, shortening the command line. To this end,

clang/test/Driver/cl-offload.cu

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
// CUDA-SAME: "-Weverything"
1919
// CUDA: link
2020

21-
// HIP: "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" "-aux-triple" "amdgcn-amd-amdhsa"
22-
// HIP-SAME: "-Weverything"
2321
// HIP: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-pc-windows-msvc"
2422
// HIP-SAME: "-Weverything"
25-
// HIP: {{lld.* "-flavor" "gnu" "-m" "elf64_amdgpu"}}
23+
// HIP: "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" "-aux-triple" "amdgcn-amd-amdhsa"
24+
// HIP-SAME: "-Weverything"
2625
// HIP: {{link.* "amdhip64.lib"}}
2726

2827
// CMake uses this option when finding packages for HIP, so

clang/test/Driver/cuda-arch-translation.cu

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
// CUDA-SAME: -m64
6767
// CUDA: fatbinary
6868

69-
// HIP: clang-offload-bundler
69+
// HIP: llvm-offload-binary
7070

7171
// SM20:--image3=kind=elf,sm=20{{.*}}
7272
// SM21:--image3=kind=elf,sm=21{{.*}}
@@ -81,20 +81,20 @@
8181
// SM61:--image3=kind=elf,sm=61{{.*}}
8282
// SM62:--image3=kind=elf,sm=62{{.*}}
8383
// SM70:--image3=kind=elf,sm=70{{.*}}
84-
// GFX600:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx600
85-
// GFX601:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx601
86-
// GFX602:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx602
87-
// GFX700:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx700
88-
// GFX701:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx701
89-
// GFX702:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx702
90-
// GFX703:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx703
91-
// GFX704:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx704
92-
// GFX705:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx705
93-
// GFX801:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx801
94-
// GFX802:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx802
95-
// GFX803:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx803
96-
// GFX805:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx805
97-
// GFX810:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx810
98-
// GFX900:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx900
99-
// GFX902:-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx902
100-
// SPIRV:-targets=host-x86_64-unknown-linux-gnu,hip-spirv64-amd-amdhsa--amdgcnspirv
84+
// GFX600:triple=amdgcn-amd-amdhsa,arch=gfx600
85+
// GFX601:triple=amdgcn-amd-amdhsa,arch=gfx601
86+
// GFX602:triple=amdgcn-amd-amdhsa,arch=gfx602
87+
// GFX700:triple=amdgcn-amd-amdhsa,arch=gfx700
88+
// GFX701:triple=amdgcn-amd-amdhsa,arch=gfx701
89+
// GFX702:triple=amdgcn-amd-amdhsa,arch=gfx702
90+
// GFX703:triple=amdgcn-amd-amdhsa,arch=gfx703
91+
// GFX704:triple=amdgcn-amd-amdhsa,arch=gfx704
92+
// GFX705:triple=amdgcn-amd-amdhsa,arch=gfx705
93+
// GFX801:triple=amdgcn-amd-amdhsa,arch=gfx801
94+
// GFX802:triple=amdgcn-amd-amdhsa,arch=gfx802
95+
// GFX803:triple=amdgcn-amd-amdhsa,arch=gfx803
96+
// GFX805:triple=amdgcn-amd-amdhsa,arch=gfx805
97+
// GFX810:triple=amdgcn-amd-amdhsa,arch=gfx810
98+
// GFX900:triple=amdgcn-amd-amdhsa,arch=gfx900
99+
// GFX902:triple=amdgcn-amd-amdhsa,arch=gfx902
100+
// SPIRV:triple=spirv64-amd-amdhsa,arch=amdgcnspirv
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// RUN: %clang -### -nogpuinc -nogpulib --offload-arch=gfx1030 --offload-arch=gfx1100 --offload-arch=gfx1101 --target=x86_64-linux-gnu -MD -MF tmp.d %s 2>&1 | FileCheck %s
22

33
// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1030"{{.*}}"-dependency-file" "tmp.d"
4-
// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1030"
54
// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1100"{{.*}}"-dependency-file" "tmp.d"
6-
// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1100"
75
// CHECK-NOT: {{.*}}clang{{.*}}"-target-cpu" "gfx1101"{{.*}}"-dependency-file" "tmp.d"
8-
// CHECK: {{.*}}lld{{.*}}"-plugin-opt=mcpu=gfx1101"
9-
// CHECK: {{.*}}clang-offload-bundler
6+
// CHECK: {{.*}}llvm-offload-binary
107
// CHECK: {{.*}}clang{{.*}}"-target-cpu"{{.*}}"-dependency-file" "tmp.d"
118

129
void main(){}

clang/test/Driver/hip-code-object-version.hip

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
// V4: "-mcode-object-version=4"
99
// V4: "-mllvm" "--amdhsa-code-object-version=4"
10-
// V4: "-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx906"
1110

1211
// Check bundle ID for code object version 5.
1312

@@ -18,7 +17,6 @@
1817

1918
// V5: "-mcode-object-version=5"
2019
// V5: "-mllvm" "--amdhsa-code-object-version=5"
21-
// V5: "-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx906"
2220

2321
// Check bundle ID for code object version 6.
2422

@@ -29,11 +27,10 @@
2927

3028
// V6: "-mcode-object-version=6"
3129
// V6: "-mllvm" "--amdhsa-code-object-version=6"
32-
// V6: "-targets=host-x86_64-unknown-linux-gnu,hipv4-amdgcn-amd-amdhsa--gfx906"
3330

3431
// Check bundle ID for code object version default
3532

36-
// RUN: %clang -### --target=x86_64-linux-gnu \
33+
// RUN: %clang -### --target=x86_64-linux-gnu --no-offload-new-driver \
3734
// RUN: --offload-arch=gfx906 -nogpuinc -nogpulib \
3835
// RUN: %s 2>&1 | FileCheck -check-prefix=VD %s
3936

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
// REQUIRES: zlib
22

33
// RUN: %clang -### --target=x86_64-unknown-linux-gnu \
4-
// RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \
4+
// RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \
55
// RUN: -ggdb -gz=zlib 2>&1 | FileCheck %s
66

77
// RUN: %clang -### --target=x86_64-unknown-linux-gnu \
88
// RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
99
// RUN: -ggdb -gz=zlib 2>&1 | FileCheck %s
1010

11-
// CHECK-DAG: {{".*clang(-[0-9]+)?(.exe)?" .* "--compress-debug-sections=zlib"}}
12-
// CHECK-DAG: {{".*lld(.exe)?" .* "--compress-debug-sections=zlib"}}
13-
// CHECK-DAG: {{".*clang(-[0-9]+)?(.exe)?" .* "--compress-debug-sections=zlib"}}
11+
// CHECK-DAG: {{".*clang(-[0-9]+)?(.exe)?" .* "-triple" "amdgcn-amd-amdhsa" .* "--compress-debug-sections=zlib"}}
12+
// CHECK-DAG: {{".*clang(-[0-9]+)?(.exe)?" .* "-triple" "x86_64-unknown-linux-gnu".* "--compress-debug-sections=zlib"}}
1413
// CHECK: "--compress-debug-sections=zlib"

clang/test/Driver/hip-macros.hip

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@
5454
// RUN: %clang -E -dM --offload-arch=gfx942 --cuda-device-only -nogpuinc -nogpulib \
5555
// RUN: %s 2>&1 | FileCheck --check-prefixes=NOPTS %s
5656
// PTS-DAG: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__ 1
57-
// PTS-DAG: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__ 1
58-
// PTS-DAG: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1
5957
// PTS-DAG: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1
6058
// NOPTS-NOT: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__
6159
// NOPTS-NOT: #define HIP_API_PER_THREAD_DEFAULT_STREAM
@@ -66,4 +64,3 @@
6664
// RUN: %s 2>&1 | FileCheck --check-prefix=APPROX %s
6765
// NOAPPROX-NOT: #define __CLANG_GPU_APPROX_TRANSCENDENTALS__
6866
// APPROX: #define __CLANG_GPU_APPROX_TRANSCENDENTALS__ 1
69-
// APPROX: #define __CLANG_GPU_APPROX_TRANSCENDENTALS__ 1

clang/test/Driver/hip-offload-arch.hip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
// RUN: -nogpuinc -nogpulib \
55
// RUN: %s 2>&1 | FileCheck %s
66

7-
// CHECK: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx1030"}}
8-
// CHECK: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx1031"}}
7+
// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-target-cpu" "gfx1030"
8+
// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-target-cpu" "gfx1031"

0 commit comments

Comments
 (0)