Skip to content

Commit 5123637

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 134a58a commit 5123637

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
@@ -4384,15 +4384,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43844384
void Driver::BuildDefaultActions(Compilation &C, DerivedArgList &Args,
43854385
const InputList &Inputs,
43864386
ActionList &Actions) const {
4387-
4388-
bool UseNewOffloadingDriver =
4389-
C.isOffloadingHostKind(Action::OFK_OpenMP) ||
4390-
C.isOffloadingHostKind(Action::OFK_SYCL) ||
4391-
Args.hasFlag(options::OPT_foffload_via_llvm,
4392-
options::OPT_fno_offload_via_llvm, false) ||
4393-
Args.hasFlag(options::OPT_offload_new_driver,
4394-
options::OPT_no_offload_new_driver,
4395-
C.isOffloadingHostKind(Action::OFK_Cuda));
4387+
bool UseNewOffloadingDriver = Args.hasFlag(
4388+
options::OPT_offload_new_driver, options::OPT_no_offload_new_driver,
4389+
C.getActiveOffloadKinds() != Action::OFK_None);
43964390

43974391
bool HIPNoRDC =
43984392
C.isOffloadingHostKind(Action::OFK_HIP) &&
@@ -5017,8 +5011,8 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
50175011
bool ShouldBundleHIP =
50185012
Args.hasFlag(options::OPT_gpu_bundle_output,
50195013
options::OPT_no_gpu_bundle_output, false) ||
5020-
(HIPNoRDC && offloadDeviceOnly() &&
5021-
llvm::none_of(OffloadActions, [](Action *A) {
5014+
(!Args.getLastArg(options::OPT_no_gpu_bundle_output) && HIPNoRDC &&
5015+
offloadDeviceOnly() && llvm::none_of(OffloadActions, [](Action *A) {
50225016
return A->getType() != types::TY_Image;
50235017
}));
50245018

@@ -5191,8 +5185,13 @@ Action *Driver::ConstructPhaseAction(
51915185
Args.hasArg(options::OPT_S) ? types::TY_LTO_IR : types::TY_LTO_BC;
51925186
return C.MakeAction<BackendJobAction>(Input, Output);
51935187
}
5188+
5189+
bool IsAMDGCNSPIRV = Input->getOffloadingToolChain() &&
5190+
Input->getOffloadingToolChain()->getTriple().getOS() ==
5191+
llvm::Triple::OSType::AMDHSA &&
5192+
Input->getOffloadingToolChain()->getTriple().isSPIRV();
51945193
if (Args.hasArg(options::OPT_emit_llvm) ||
5195-
TargetDeviceOffloadKind == Action::OFK_SYCL ||
5194+
TargetDeviceOffloadKind == Action::OFK_SYCL || IsAMDGCNSPIRV ||
51965195
(((Input->getOffloadingToolChain() &&
51975196
Input->getOffloadingToolChain()->getTriple().isAMDGPU()) ||
51985197
TargetDeviceOffloadKind == Action::OFK_HIP) &&
@@ -5212,7 +5211,8 @@ Action *Driver::ConstructPhaseAction(
52125211
(TargetDeviceOffloadKind == Action::OFK_HIP &&
52135212
!Args.hasFlag(options::OPT_offload_new_driver,
52145213
options::OPT_no_offload_new_driver,
5215-
C.isOffloadingHostKind(Action::OFK_Cuda))))
5214+
C.getActiveOffloadKinds() !=
5215+
Action::OFK_None)))
52165216
? types::TY_LLVM_IR
52175217
: types::TY_LLVM_BC;
52185218
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
@@ -4864,7 +4864,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
48644864
(JA.isHostOffloading(C.getActiveOffloadKinds()) &&
48654865
Args.hasFlag(options::OPT_offload_new_driver,
48664866
options::OPT_no_offload_new_driver,
4867-
C.isOffloadingHostKind(Action::OFK_Cuda)));
4867+
C.getActiveOffloadKinds() != Action::OFK_None));
48684868

48694869
bool IsRDCMode =
48704870
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
@@ -5229,7 +5229,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
52295229
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) &&
52305230
!Args.hasFlag(options::OPT_offload_new_driver,
52315231
options::OPT_no_offload_new_driver,
5232-
C.isOffloadingHostKind(Action::OFK_Cuda)) &&
5232+
C.getActiveOffloadKinds() != Action::OFK_None) &&
52335233
!Triple.isAMDGPU()) {
52345234
D.Diag(diag::err_drv_unsupported_opt_for_target)
52355235
<< Args.getLastArg(options::OPT_foffload_lto,
@@ -6704,7 +6704,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
67046704
CmdArgs.append({"--offload-new-driver", "-foffload-via-llvm"});
67056705
} else if (Args.hasFlag(options::OPT_offload_new_driver,
67066706
options::OPT_no_offload_new_driver,
6707-
C.isOffloadingHostKind(Action::OFK_Cuda))) {
6707+
C.getActiveOffloadKinds() != Action::OFK_None)) {
67086708
CmdArgs.push_back("--offload-new-driver");
67096709
}
67106710

@@ -9101,6 +9101,7 @@ void LinkerWrapper::ConstructJob(Compilation &C, const JobAction &JA,
91019101
OPT_fno_lto,
91029102
OPT_flto,
91039103
OPT_flto_partitions_EQ,
9104+
OPT_hipspv_pass_plugin_EQ,
91049105
OPT_flto_EQ};
91059106
const llvm::DenseSet<unsigned> LinkerOptions{OPT_mllvm, OPT_Zlinker_input};
91069107
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
@@ -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)