Skip to content

Commit ce890d0

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. Currently, we only regress on one feature: surface and texture registering in RDC mode. Those runtime functions require more information than I can pack in the current struct. I don't know how important that is, or if we could hack around it.
1 parent 1c00d0d commit ce890d0

15 files changed

+36
-51
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4360,14 +4360,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43604360

43614361
handleArguments(C, Args, Inputs, Actions);
43624362

4363-
bool UseNewOffloadingDriver =
4364-
C.isOffloadingHostKind(Action::OFK_OpenMP) ||
4365-
C.isOffloadingHostKind(Action::OFK_SYCL) ||
4366-
Args.hasFlag(options::OPT_foffload_via_llvm,
4367-
options::OPT_fno_offload_via_llvm, false) ||
4368-
Args.hasFlag(options::OPT_offload_new_driver,
4369-
options::OPT_no_offload_new_driver,
4370-
C.isOffloadingHostKind(Action::OFK_Cuda));
4363+
bool UseNewOffloadingDriver = Args.hasFlag(
4364+
options::OPT_offload_new_driver, options::OPT_no_offload_new_driver,
4365+
C.getActiveOffloadKinds() != Action::OFK_None);
43714366

43724367
// Builder to be used to build offloading actions.
43734368
std::unique_ptr<OffloadingActionBuilder> OffloadBuilder =
@@ -5124,7 +5119,8 @@ Action *Driver::ConstructPhaseAction(
51245119
(TargetDeviceOffloadKind == Action::OFK_HIP &&
51255120
!Args.hasFlag(options::OPT_offload_new_driver,
51265121
options::OPT_no_offload_new_driver,
5127-
C.isOffloadingHostKind(Action::OFK_Cuda))))
5122+
C.getActiveOffloadKinds() !=
5123+
Action::OFK_None)))
51285124
? types::TY_LLVM_IR
51295125
: types::TY_LLVM_BC;
51305126
return C.MakeAction<BackendJobAction>(Input, Output);

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5073,7 +5073,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
50735073
(JA.isHostOffloading(C.getActiveOffloadKinds()) &&
50745074
Args.hasFlag(options::OPT_offload_new_driver,
50755075
options::OPT_no_offload_new_driver,
5076-
C.isOffloadingHostKind(Action::OFK_Cuda)));
5076+
C.getActiveOffloadKinds() != Action::OFK_None));
50775077

50785078
bool IsRDCMode =
50795079
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
@@ -5429,7 +5429,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
54295429
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) &&
54305430
!Args.hasFlag(options::OPT_offload_new_driver,
54315431
options::OPT_no_offload_new_driver,
5432-
C.isOffloadingHostKind(Action::OFK_Cuda)) &&
5432+
C.getActiveOffloadKinds() != Action::OFK_None) &&
54335433
!Triple.isAMDGPU()) {
54345434
D.Diag(diag::err_drv_unsupported_opt_for_target)
54355435
<< Args.getLastArg(options::OPT_foffload_lto,
@@ -6907,7 +6907,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
69076907
CmdArgs.append({"--offload-new-driver", "-foffload-via-llvm"});
69086908
} else if (Args.hasFlag(options::OPT_offload_new_driver,
69096909
options::OPT_no_offload_new_driver,
6910-
C.isOffloadingHostKind(Action::OFK_Cuda))) {
6910+
C.getActiveOffloadKinds() != Action::OFK_None)) {
69116911
CmdArgs.push_back("--offload-new-driver");
69126912
}
69136913

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/hip-gz-options.hip

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

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

77
// RUN: %clang -### --target=x86_64-unknown-linux-gnu \
8+
// RUN: -Xoffload-linker --compress-debug-sections=zlib \
89
// RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
9-
// RUN: -ggdb -gz=zlib 2>&1 | FileCheck %s
10+
// RUN: -ggdb -gz=zlib 2>&1 | FileCheck %s --check-prefix=RDC
1011

11-
// CHECK-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
12-
// CHECK-DAG: {{".*lld" .* "--compress-debug-sections=zlib"}}
13-
// CHECK-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
14-
// CHECK: "--compress-debug-sections=zlib"
12+
// NORDC-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
13+
// NORDC-DAG: {{".*lld" .* "--compress-debug-sections=zlib"}}
14+
// NORDC-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
15+
16+
// RDC-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
17+
// RDC-DAG: {{".*clang-linker-wrapper" .* "--device-linker=--compress-debug-sections=zlib"}}

clang/test/Driver/hip-invalid-target-id.hip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// RUN: --rocm-path=%S/Inputs/rocm \
55
// RUN: %s 2>&1 | FileCheck -check-prefix=NOPLUS %s
66

7-
// NOPLUS: error: invalid target ID 'gfx908xnack'
7+
// NOPLUS: error: unsupported HIP gpu architecture: gfx908xnack
88

99
// RUN: not %clang -### --target=x86_64-linux-gnu \
1010
// RUN: -x hip --offload-arch=gfx900 \
@@ -55,7 +55,7 @@
5555
// RUN: --rocm-path=%S/Inputs/rocm \
5656
// RUN: %s 2>&1 | FileCheck -check-prefix=NOCOLON %s
5757

58-
// NOCOLON: error: invalid target ID 'gfx900+xnack'
58+
// NOCOLON: error: unsupported HIP gpu architecture: gfx900+xnack
5959

6060
// RUN: not %clang -### --target=x86_64-linux-gnu \
6161
// RUN: -x hip --offload-arch=gfx908 \

clang/test/Driver/hip-macros.hip

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@
7373
// RUN: %clang -E -dM --offload-arch=gfx940 --cuda-device-only -nogpuinc -nogpulib \
7474
// RUN: %s 2>&1 | FileCheck --check-prefixes=NOPTS %s
7575
// PTS-DAG: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__ 1
76-
// PTS-DAG: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__ 1
77-
// PTS-DAG: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1
7876
// PTS-DAG: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1
7977
// NOPTS-NOT: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__
8078
// NOPTS-NOT: #define HIP_API_PER_THREAD_DEFAULT_STREAM
@@ -85,4 +83,3 @@
8583
// RUN: %s 2>&1 | FileCheck --check-prefix=APPROX %s
8684
// NOAPPROX-NOT: #define __CLANG_GPU_APPROX_TRANSCENDENTALS__
8785
// APPROX: #define __CLANG_GPU_APPROX_TRANSCENDENTALS__ 1
88-
// 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"

clang/test/Driver/hip-options.hip

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@
8383
// RUN: --cuda-gpu-arch=gfx906 -foffload-lto=thin -fwhole-program-vtables %s 2>&1 \
8484
// RUN: | FileCheck -check-prefix=HIPTHINLTO %s
8585

86-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
87-
// RUN: --cuda-gpu-arch=gfx906 -fgpu-rdc -foffload-lto=thin -fwhole-program-vtables %s 2>&1 \
88-
// RUN: | FileCheck -check-prefix=HIPTHINLTO %s
89-
9086
// Ensure we don't error about -fwhole-program-vtables for the non-device offload compile.
9187
// HIPTHINLTO-NOT: error: invalid argument '-fwhole-program-vtables' only allowed with '-flto'
9288
// HIPTHINLTO-NOT: "-cc1"{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-flto-unit"
@@ -122,7 +118,7 @@
122118

123119
// Check -Xoffload-linker option is passed to lld.
124120

125-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
121+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib --no-offload-new-driver \
126122
// RUN: --cuda-gpu-arch=gfx906 -fgpu-rdc -Xoffload-linker --build-id=md5 %s 2>&1 \
127123
// RUN: | FileCheck -check-prefix=OFL-LINK %s
128124
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \

clang/test/Driver/hip-sanitize-options.hip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
// NORDC-NOT: {{"[^"]*lld(\.exe){0,1}".*}} "[[OUT]]" {{".*asanrtl.bc" ".*hip.bc"}}
5757
// NORDC: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* "-fsanitize=address"}}
5858

59-
// RDC: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* "-fsanitize=address"}}
6059
// RDC: {{"[^"]*clang[^"]*".* "-emit-llvm-bc".* "-fcuda-is-device".* "-mlink-bitcode-file" ".*asanrtl.bc".* "-mlink-builtin-bitcode" ".*hip.bc".* "-fsanitize=address".*}} "-o" "[[OUT:[^"]*.bc]]"
60+
// RDC: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* "-fsanitize=address"}}
6161
// RDC-NOT: {{"[^"]*lld(\.exe){0,1}".*}} "[[OUT]]" {{".*asanrtl.bc" ".*hip.bc"}}
6262

6363
// FAIL: AMDGPU address sanitizer runtime library (asanrtl) is not found. Please install ROCm device library which supports address sanitizer

clang/test/Driver/hip-save-temps.hip

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
// -fno-gpu-rdc without -o with -c
22
// RUN: %clang -### --target=x86_64-linux-gnu -nogpulib -save-temps \
3-
// RUN: -nogpuinc --offload-arch=gfx900 -c %s 2>&1 | \
3+
// RUN: --no-offload-new-driver -nogpuinc --offload-arch=gfx900 -c %s 2>&1 | \
44
// RUN: FileCheck -check-prefixes=CHECK,NORDC %s
55

66
// -fno-gpu-rdc without -o
77
// RUN: %clang -### --target=x86_64-linux-gnu -nogpulib -save-temps \
8-
// RUN: -nogpuinc --offload-arch=gfx900 %s 2>&1 | \
8+
// RUN: --no-offload-new-driver -nogpuinc --offload-arch=gfx900 %s 2>&1 | \
99
// RUN: FileCheck -check-prefixes=CHECK,NORDC,NOUT %s
1010

1111
// -fno-gpu-rdc with -o
1212
// RUN: %clang -### --target=x86_64-linux-gnu -nogpulib -save-temps \
13-
// RUN: -nogpuinc -o executable --offload-arch=gfx900 %s 2>&1 | \
13+
// RUN: --no-offload-new-driver -nogpuinc -o executable --offload-arch=gfx900 %s 2>&1 | \
1414
// RUN: FileCheck -check-prefixes=CHECK,NORDC,WOUT %s
1515

1616
// -fgpu-rdc without -o with -c
1717
// RUN: %clang -### --target=x86_64-linux-gnu -nogpulib -save-temps \
18-
// RUN: -nogpuinc -fgpu-rdc --offload-arch=gfx900 -c %s 2>&1 | \
18+
// RUN: --no-offload-new-driver -nogpuinc -fgpu-rdc --offload-arch=gfx900 -c %s 2>&1 | \
1919
// RUN: FileCheck -check-prefixes=CHECK,RDC,RDCC %s
2020

2121
// -fgpu-rdc without -o
2222
// RUN: %clang -### --target=x86_64-linux-gnu -nogpulib -save-temps \
23-
// RUN: -nogpuinc -fgpu-rdc --offload-arch=gfx900 %s 2>&1 | \
23+
// RUN: --no-offload-new-driver -nogpuinc -fgpu-rdc --offload-arch=gfx900 %s 2>&1 | \
2424
// RUN: FileCheck -check-prefixes=CHECK,RDC,RDCL,NOUT %s
2525

2626
// -fgpu-rdc with -o
2727
// UN: %clang -### --target=x86_64-linux-gnu -nogpulib -save-temps \
28-
// UN: -nogpuinc -o executable -fgpu-rdc --offload-arch=gfx900 %s 2>&1 | \
28+
// UN: --offload-new-driver -nogpuinc -o executable -fgpu-rdc --offload-arch=gfx900 %s 2>&1 | \
2929
// UN: FileCheck -check-prefixes=CHECK,RDC,RDCL,WOUT %s
3030

3131
// -fgpu-rdc host object path

clang/test/Driver/hip-toolchain-device-only.hip

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,3 @@
2121

2222
// CHECK: [[LLD]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" "-shared"
2323
// CHECK-SAME: "-o" "[[IMG_DEV_A_900:.*out]]" [[OBJ_DEV_A_900]]
24-
25-
// CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
26-
// CHECK-SAME: "-targets={{.*}},hip{{.*}}-amdgcn-amd-amdhsa--gfx803,hip{{.*}}-amdgcn-amd-amdhsa--gfx900"
27-
// CHECK-SAME: "-input={{.*}}" "-input=[[IMG_DEV_A_803]]" "-input=[[IMG_DEV_A_900]]" "-output=[[BUNDLE_A:.*hipfb]]"

clang/test/Driver/hip-toolchain-mllvm.hip

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@
3030
// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
3131
// CHECK-SAME: {{.*}} "-target-cpu" "gfx803"
3232
// CHECK-SAME: {{.*}} "-mllvm" "-unroll-count=10" {{.*}}
33-
// CHECK: [[LLD:".*lld.*"]] {{.*}}"-m" "elf64_amdgpu"{{.*}} "-plugin-opt=-unroll-count=10"{{.*}} "-plugin-opt=-inline-threshold=100"
3433

3534
// CHECK: [[CLANG]] "-cc1" "-triple" "amdgcn-amd-amdhsa"
3635
// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
3736
// CHECK-SAME: {{.*}} "-target-cpu" "gfx900"
3837
// CHECK-SAME: {{.*}} "-mllvm" "-unroll-count=10" {{.*}}
39-
// CHECK: [[LLD:".*lld.*"]] {{.*}} "-plugin-opt=-unroll-count=10"{{.*}} "-plugin-opt=-inline-threshold=100"
4038

4139
// NEG-NOT: {{".*opt"}}
4240
// NEG-NOT: {{".*llc"}}

clang/test/Driver/hip-toolchain-no-rdc.hip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
// RUN: %t/a.o %t/b.o \
3737
// RUN: 2>&1 | FileCheck -check-prefixes=LKONLY %s
3838

39-
// RUN: %clang -### --target=x86_64-linux-gnu \
39+
// RUN: %clang -### --target=x86_64-linux-gnu --no-offload-new-driver \
4040
// RUN: --offload-arch=amdgcnspirv --offload-arch=gfx900 \
4141
// RUN: %s -nogpuinc -nogpulib \
4242
// RUN: 2>&1 | FileCheck -check-prefixes=AMDGCNSPIRV %s

clang/test/Driver/invalid-offload-options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
// RUN: --offload=amdgcn-amd-amdhsa --offload-arch=gfx900 %s \
2727
// RUN: 2>&1 | FileCheck --check-prefix=OFFLOAD-ARCH-MIX %s
2828

29-
// OFFLOAD-ARCH-MIX: error: option '--offload-arch' cannot be specified with '--offload'
29+
// OFFLOAD-ARCH-MIX: error: option '--offload' cannot be specified with '--offload-arch'

clang/unittests/Tooling/ToolingTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ TEST_F(CommandLineExtractorTest, AcceptOffloadingCompile) {
436436
TEST_F(CommandLineExtractorTest, AcceptOffloadingSyntaxOnly) {
437437
addFile("test.c", "int main() {}\n");
438438
const char *Args[] = {
439-
"clang", "-target", "arm64-apple-macosx11.0.0",
440-
"-fsyntax-only", "-x", "hip",
441-
"test.c", "-nogpulib", "-nogpuinc"};
439+
"clang", "-target", "arm64-apple-macosx11.0.0", "-fsyntax-only",
440+
"-x", "hip", "--no-offload-new-driver", "test.c",
441+
"-nogpulib", "-nogpuinc"};
442442
EXPECT_NE(extractCC1Arguments(Args), nullptr);
443443
}
444444

0 commit comments

Comments
 (0)