Skip to content

Commit 32e900b

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.
1 parent 9c26170 commit 32e900b

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
@@ -4397,15 +4397,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43974397
void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
43984398
const InputList &Inputs,
43994399
ActionList &Actions) const {
4400-
4401-
bool UseNewOffloadingDriver =
4402-
C.isOffloadingHostKind(Action::OFK_OpenMP) ||
4403-
C.isOffloadingHostKind(Action::OFK_SYCL) ||
4404-
Args.hasFlag(options::OPT_foffload_via_llvm,
4405-
options::OPT_fno_offload_via_llvm, false) ||
4406-
Args.hasFlag(options::OPT_offload_new_driver,
4407-
options::OPT_no_offload_new_driver,
4408-
C.isOffloadingHostKind(Action::OFK_Cuda));
4400+
bool UseNewOffloadingDriver = Args.hasFlag(
4401+
options::OPT_offload_new_driver, options::OPT_no_offload_new_driver,
4402+
C.getActiveOffloadKinds() != Action::OFK_None);
44094403

44104404
bool HIPNoRDC =
44114405
C.isOffloadingHostKind(Action::OFK_HIP) &&
@@ -5030,8 +5024,8 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
50305024
bool ShouldBundleHIP =
50315025
Args.hasFlag(options::OPT_gpu_bundle_output,
50325026
options::OPT_no_gpu_bundle_output, false) ||
5033-
(HIPNoRDC && offloadDeviceOnly() &&
5034-
llvm::none_of(OffloadActions, [](Action *A) {
5027+
(!Args.getLastArg(options::OPT_no_gpu_bundle_output) && HIPNoRDC &&
5028+
offloadDeviceOnly() && llvm::none_of(OffloadActions, [](Action *A) {
50355029
return A->getType() != types::TY_Image;
50365030
}));
50375031

@@ -5204,8 +5198,13 @@ Action *Driver::ConstructPhaseAction(
52045198
Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
52055199
return C.MakeAction<BackendJobAction>(Input, Output);
52065200
}
5201+
5202+
bool IsAMDGCNSPIRV = Input->getOffloadingToolChain() &&
5203+
Input->getOffloadingToolChain()->getTriple().getOS() ==
5204+
llvm::Triple::OSType::AMDHSA &&
5205+
Input->getOffloadingToolChain()->getTriple().isSPIRV();
52075206
if (Args.hasArg(options::OPT_emit_llvm) ||
5208-
TargetDeviceOffloadKind == Action::OFK_SYCL ||
5207+
TargetDeviceOffloadKind == Action::OFK_SYCL || IsAMDGCNSPIRV ||
52095208
(((Input->getOffloadingToolChain() &&
52105209
Input->getOffloadingToolChain()->getTriple().isAMDGPU()) ||
52115210
TargetDeviceOffloadKind == Action::OFK_HIP) &&
@@ -5225,7 +5224,8 @@ Action *Driver::ConstructPhaseAction(
52255224
(TargetDeviceOffloadKind == Action::OFK_HIP &&
52265225
!Args.hasFlag(options::OPT_offload_new_driver,
52275226
options::OPT_no_offload_new_driver,
5228-
C.isOffloadingHostKind(Action::OFK_Cuda))))
5227+
C.getActiveOffloadKinds() !=
5228+
Action::OFK_None)))
52295229
? types::TY_LLVM_IR
52305230
: types::TY_LLVM_BC;
52315231
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
@@ -4805,7 +4805,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
48054805
(JA.isHostOffloading(C.getActiveOffloadKinds()) &&
48064806
Args.hasFlag(options::OPT_offload_new_driver,
48074807
options::OPT_no_offload_new_driver,
4808-
C.isOffloadingHostKind(Action::OFK_Cuda)));
4808+
C.getActiveOffloadKinds() != Action::OFK_None));
48094809

48104810
bool IsRDCMode =
48114811
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
@@ -5170,7 +5170,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
51705170
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) &&
51715171
!Args.hasFlag(options::OPT_offload_new_driver,
51725172
options::OPT_no_offload_new_driver,
5173-
C.isOffloadingHostKind(Action::OFK_Cuda)) &&
5173+
C.getActiveOffloadKinds() != Action::OFK_None) &&
51745174
!Triple.isAMDGPU()) {
51755175
D.Diag(diag::err_drv_unsupported_opt_for_target)
51765176
<< Args.getLastArg(options::OPT_foffload_lto,
@@ -6649,7 +6649,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
66496649
CmdArgs.append({"--offload-new-driver", "-foffload-via-llvm"});
66506650
} else if (Args.hasFlag(options::OPT_offload_new_driver,
66516651
options::OPT_no_offload_new_driver,
6652-
C.isOffloadingHostKind(Action::OFK_Cuda))) {
6652+
C.getActiveOffloadKinds() != Action::OFK_None)) {
66536653
CmdArgs.push_back("--offload-new-driver");
66546654
}
66556655

@@ -9048,6 +9048,7 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
90489048
OPT_fno_lto,
90499049
OPT_flto,
90509050
OPT_flto_partitions_EQ,
9051+
OPT_hipspv_pass_plugin_EQ,
90519052
OPT_flto_EQ};
90529053
const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm, OPT_Zlinker_input};
90539054
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: clang-offload-packager
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: {{.*}}clang-offload-packager
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)