Skip to content

Commit fecd559

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. Authored by @jhuber6
1 parent 83f7f2e commit fecd559

22 files changed

+90
-118
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4398,15 +4398,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43984398
void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
43994399
const InputList &Inputs,
44004400
ActionList &Actions) const {
4401-
4402-
bool UseNewOffloadingDriver =
4403-
C.isOffloadingHostKind(Action::OFK_OpenMP) ||
4404-
C.isOffloadingHostKind(Action::OFK_SYCL) ||
4405-
Args.hasFlag(options::OPT_foffload_via_llvm,
4406-
options::OPT_fno_offload_via_llvm, false) ||
4407-
Args.hasFlag(options::OPT_offload_new_driver,
4408-
options::OPT_no_offload_new_driver,
4409-
C.isOffloadingHostKind(Action::OFK_Cuda));
4401+
bool UseNewOffloadingDriver = Args.hasFlag(
4402+
options::OPT_offload_new_driver, options::OPT_no_offload_new_driver,
4403+
C.getActiveOffloadKinds() != Action::OFK_None);
44104404

44114405
bool HIPNoRDC =
44124406
C.isOffloadingHostKind(Action::OFK_HIP) &&
@@ -5036,8 +5030,8 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
50365030
bool ShouldBundleHIP =
50375031
Args.hasFlag(options::OPT_gpu_bundle_output,
50385032
options::OPT_no_gpu_bundle_output, false) ||
5039-
(HIPNoRDC && offloadDeviceOnly() &&
5040-
llvm::none_of(OffloadActions, [](Action *A) {
5033+
(!Args.getLastArg(options::OPT_no_gpu_bundle_output) && HIPNoRDC &&
5034+
offloadDeviceOnly() && llvm::none_of(OffloadActions, [](Action *A) {
50415035
return A->getType() != types::TY_Image;
50425036
}));
50435037

@@ -5212,8 +5206,13 @@ Action *Driver::ConstructPhaseAction(
52125206
Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
52135207
return C.MakeAction<BackendJobAction>(Input, Output);
52145208
}
5209+
5210+
bool IsAMDGCNSPIRV = Input->getOffloadingToolChain() &&
5211+
Input->getOffloadingToolChain()->getTriple().getOS() ==
5212+
llvm::Triple::OSType::AMDHSA &&
5213+
Input->getOffloadingToolChain()->getTriple().isSPIRV();
52155214
if (Args.hasArg(options::OPT_emit_llvm) ||
5216-
TargetDeviceOffloadKind == Action::OFK_SYCL ||
5215+
TargetDeviceOffloadKind == Action::OFK_SYCL || IsAMDGCNSPIRV ||
52175216
(((Input->getOffloadingToolChain() &&
52185217
Input->getOffloadingToolChain()->getTriple().isAMDGPU()) ||
52195218
TargetDeviceOffloadKind == Action::OFK_HIP) &&
@@ -5233,7 +5232,8 @@ Action *Driver::ConstructPhaseAction(
52335232
(TargetDeviceOffloadKind == Action::OFK_HIP &&
52345233
!Args.hasFlag(options::OPT_offload_new_driver,
52355234
options::OPT_no_offload_new_driver,
5236-
C.isOffloadingHostKind(Action::OFK_Cuda))))
5235+
C.getActiveOffloadKinds() !=
5236+
Action::OFK_None)))
52375237
? types::TY_LLVM_IR
52385238
: types::TY_LLVM_BC;
52395239
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
@@ -4927,7 +4927,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
49274927
(JA.isHostOffloading(C.getActiveOffloadKinds()) &&
49284928
Args.hasFlag(options::OPT_offload_new_driver,
49294929
options::OPT_no_offload_new_driver,
4930-
C.isOffloadingHostKind(Action::OFK_Cuda)));
4930+
C.getActiveOffloadKinds() != Action::OFK_None));
49314931

49324932
bool IsRDCMode =
49334933
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
@@ -5295,7 +5295,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
52955295
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) &&
52965296
!Args.hasFlag(options::OPT_offload_new_driver,
52975297
options::OPT_no_offload_new_driver,
5298-
C.isOffloadingHostKind(Action::OFK_Cuda)) &&
5298+
C.getActiveOffloadKinds() != Action::OFK_None) &&
52995299
!Triple.isAMDGPU()) {
53005300
D.Diag(diag::err_drv_unsupported_opt_for_target)
53015301
<< Args.getLastArg(options::OPT_foffload_lto,
@@ -6863,7 +6863,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
68636863
CmdArgs.append({"--offload-new-driver", "-foffload-via-llvm"});
68646864
} else if (Args.hasFlag(options::OPT_offload_new_driver,
68656865
options::OPT_no_offload_new_driver,
6866-
C.isOffloadingHostKind(Action::OFK_Cuda))) {
6866+
C.getActiveOffloadKinds() != Action::OFK_None)) {
68676867
CmdArgs.push_back("--offload-new-driver");
68686868
}
68696869

@@ -9290,6 +9290,7 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
92909290
OPT_fno_lto,
92919291
OPT_flto,
92929292
OPT_flto_partitions_EQ,
9293+
OPT_hipspv_pass_plugin_EQ,
92939294
OPT_flto_EQ};
92949295
const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm, OPT_Zlinker_input};
92959296
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
@@ -20,11 +20,10 @@
2020
// CUDA-SAME: "-Weverything"
2121
// CUDA: link
2222

23-
// HIP: "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" "-aux-triple" "amdgcn-amd-amdhsa"
24-
// HIP-SAME: "-Weverything"
2523
// HIP: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-pc-windows-msvc"
2624
// HIP-SAME: "-Weverything"
27-
// HIP: {{lld.* "-flavor" "gnu" "-m" "elf64_amdgpu"}}
25+
// HIP: "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" "-aux-triple" "amdgcn-amd-amdhsa"
26+
// HIP-SAME: "-Weverything"
2827
// HIP: {{link.* "amdhip64.lib"}}
2928

3029
// 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
@@ -77,8 +77,6 @@
7777
// RUN: %clang -E -dM --offload-arch=gfx942 --cuda-device-only -nogpuinc -nogpulib \
7878
// RUN: %s 2>&1 | FileCheck --check-prefixes=NOPTS %s
7979
// PTS-DAG: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__ 1
80-
// PTS-DAG: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__ 1
81-
// PTS-DAG: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1
8280
// PTS-DAG: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1
8381
// NOPTS-NOT: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__
8482
// NOPTS-NOT: #define HIP_API_PER_THREAD_DEFAULT_STREAM
@@ -89,4 +87,3 @@
8987
// RUN: %s 2>&1 | FileCheck --check-prefix=APPROX %s
9088
// NOAPPROX-NOT: #define __CLANG_GPU_APPROX_TRANSCENDENTALS__
9189
// APPROX: #define __CLANG_GPU_APPROX_TRANSCENDENTALS__ 1
92-
// 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)