Skip to content

[HIP] Move HIP to the new driver by default #123359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4360,14 +4360,9 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,

handleArguments(C, Args, Inputs, Actions);

bool UseNewOffloadingDriver =
C.isOffloadingHostKind(Action::OFK_OpenMP) ||
C.isOffloadingHostKind(Action::OFK_SYCL) ||
Args.hasFlag(options::OPT_foffload_via_llvm,
options::OPT_fno_offload_via_llvm, false) ||
Args.hasFlag(options::OPT_offload_new_driver,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda));
bool UseNewOffloadingDriver = Args.hasFlag(
options::OPT_offload_new_driver, options::OPT_no_offload_new_driver,
C.getActiveOffloadKinds() != Action::OFK_None);

// Builder to be used to build offloading actions.
std::unique_ptr<OffloadingActionBuilder> OffloadBuilder =
Expand Down Expand Up @@ -5124,7 +5119,8 @@ Action *Driver::ConstructPhaseAction(
(TargetDeviceOffloadKind == Action::OFK_HIP &&
!Args.hasFlag(options::OPT_offload_new_driver,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda))))
C.getActiveOffloadKinds() !=
Action::OFK_None)))
? types::TY_LLVM_IR
: types::TY_LLVM_BC;
return C.MakeAction<BackendJobAction>(Input, Output);
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5073,7 +5073,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
(JA.isHostOffloading(C.getActiveOffloadKinds()) &&
Args.hasFlag(options::OPT_offload_new_driver,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda)));
C.getActiveOffloadKinds() != Action::OFK_None));

bool IsRDCMode =
Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
Expand Down Expand Up @@ -5429,7 +5429,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (IsDeviceOffloadAction && !JA.isDeviceOffloading(Action::OFK_OpenMP) &&
!Args.hasFlag(options::OPT_offload_new_driver,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda)) &&
C.getActiveOffloadKinds() != Action::OFK_None) &&
!Triple.isAMDGPU()) {
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< Args.getLastArg(options::OPT_foffload_lto,
Expand Down Expand Up @@ -6907,7 +6907,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.append({"--offload-new-driver", "-foffload-via-llvm"});
} else if (Args.hasFlag(options::OPT_offload_new_driver,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda))) {
C.getActiveOffloadKinds() != Action::OFK_None)) {
CmdArgs.push_back("--offload-new-driver");
}

Expand Down
5 changes: 2 additions & 3 deletions clang/test/Driver/cl-offload.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
// CUDA-SAME: "-Weverything"
// CUDA: link

// HIP: "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" "-aux-triple" "amdgcn-amd-amdhsa"
// HIP-SAME: "-Weverything"
// HIP: "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-pc-windows-msvc"
// HIP-SAME: "-Weverything"
// HIP: {{lld.* "-flavor" "gnu" "-m" "elf64_amdgpu"}}
// HIP: "-cc1" "-triple" "x86_64-pc-windows-msvc{{.*}}" "-aux-triple" "amdgcn-amd-amdhsa"
// HIP-SAME: "-Weverything"
// HIP: {{link.* "amdhip64.lib"}}

// CMake uses this option when finding packages for HIP, so
Expand Down
15 changes: 9 additions & 6 deletions clang/test/Driver/hip-gz-options.hip
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

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

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

// CHECK-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
// CHECK-DAG: {{".*lld" .* "--compress-debug-sections=zlib"}}
// CHECK-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
// CHECK: "--compress-debug-sections=zlib"
// NORDC-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
// NORDC-DAG: {{".*lld" .* "--compress-debug-sections=zlib"}}
// NORDC-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}

// RDC-DAG: {{".*clang.*" .* "--compress-debug-sections=zlib"}}
// RDC-DAG: {{".*clang-linker-wrapper" .* "--device-linker=--compress-debug-sections=zlib"}}
4 changes: 2 additions & 2 deletions clang/test/Driver/hip-invalid-target-id.hip
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// RUN: --rocm-path=%S/Inputs/rocm \
// RUN: %s 2>&1 | FileCheck -check-prefix=NOPLUS %s

// NOPLUS: error: invalid target ID 'gfx908xnack'
// NOPLUS: error: unsupported HIP gpu architecture: gfx908xnack

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

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

// RUN: not %clang -### --target=x86_64-linux-gnu \
// RUN: -x hip --offload-arch=gfx908 \
Expand Down
3 changes: 0 additions & 3 deletions clang/test/Driver/hip-macros.hip
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@
// RUN: %clang -E -dM --offload-arch=gfx940 --cuda-device-only -nogpuinc -nogpulib \
// RUN: %s 2>&1 | FileCheck --check-prefixes=NOPTS %s
// PTS-DAG: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__ 1
// PTS-DAG: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__ 1
// PTS-DAG: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1
// PTS-DAG: #define HIP_API_PER_THREAD_DEFAULT_STREAM 1
// NOPTS-NOT: #define __HIP_API_PER_THREAD_DEFAULT_STREAM__
// NOPTS-NOT: #define HIP_API_PER_THREAD_DEFAULT_STREAM
Expand All @@ -85,4 +83,3 @@
// RUN: %s 2>&1 | FileCheck --check-prefix=APPROX %s
// NOAPPROX-NOT: #define __CLANG_GPU_APPROX_TRANSCENDENTALS__
// APPROX: #define __CLANG_GPU_APPROX_TRANSCENDENTALS__ 1
// APPROX: #define __CLANG_GPU_APPROX_TRANSCENDENTALS__ 1
4 changes: 2 additions & 2 deletions clang/test/Driver/hip-offload-arch.hip
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
// RUN: -nogpuinc -nogpulib \
// RUN: %s 2>&1 | FileCheck %s

// CHECK: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx1030"}}
// CHECK: {{"[^"]*clang[^"]*".* "-target-cpu" "gfx1031"}}
// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-target-cpu" "gfx1030"
// CHECK: "-cc1" "-triple" "amdgcn-amd-amdhsa"{{.*}}"-target-cpu" "gfx1031"
6 changes: 1 addition & 5 deletions clang/test/Driver/hip-options.hip
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@
// RUN: --cuda-gpu-arch=gfx906 -foffload-lto=thin -fwhole-program-vtables %s 2>&1 \
// RUN: | FileCheck -check-prefix=HIPTHINLTO %s

// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
// RUN: --cuda-gpu-arch=gfx906 -fgpu-rdc -foffload-lto=thin -fwhole-program-vtables %s 2>&1 \
// RUN: | FileCheck -check-prefix=HIPTHINLTO %s

// Ensure we don't error about -fwhole-program-vtables for the non-device offload compile.
// HIPTHINLTO-NOT: error: invalid argument '-fwhole-program-vtables' only allowed with '-flto'
// HIPTHINLTO-NOT: "-cc1"{{.*}} "-triple" "x86_64-unknown-linux-gnu" {{.*}} "-flto-unit"
Expand Down Expand Up @@ -122,7 +118,7 @@

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

// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib --no-offload-new-driver \
// RUN: --cuda-gpu-arch=gfx906 -fgpu-rdc -Xoffload-linker --build-id=md5 %s 2>&1 \
// RUN: | FileCheck -check-prefix=OFL-LINK %s
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -nogpuinc -nogpulib \
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/hip-sanitize-options.hip
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
// NORDC-NOT: {{"[^"]*lld(\.exe){0,1}".*}} "[[OUT]]" {{".*asanrtl.bc" ".*hip.bc"}}
// NORDC: {{"[^"]*clang[^"]*".* "-triple" "x86_64-unknown-linux-gnu".* "-fsanitize=address"}}

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

// FAIL: AMDGPU address sanitizer runtime library (asanrtl) is not found. Please install ROCm device library which supports address sanitizer
Expand Down
12 changes: 6 additions & 6 deletions clang/test/Driver/hip-save-temps.hip
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// -fno-gpu-rdc without -o with -c
// RUN: %clang -### --target=x86_64-linux-gnu -nogpulib -save-temps \
// RUN: -nogpuinc --offload-arch=gfx900 -c %s 2>&1 | \
// RUN: --no-offload-new-driver -nogpuinc --offload-arch=gfx900 -c %s 2>&1 | \
// RUN: FileCheck -check-prefixes=CHECK,NORDC %s

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

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

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

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

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

// -fgpu-rdc host object path
Expand Down
4 changes: 0 additions & 4 deletions clang/test/Driver/hip-toolchain-device-only.hip
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,3 @@

// CHECK: [[LLD]] "-flavor" "gnu" "-m" "elf64_amdgpu" "--no-undefined" "-shared"
// CHECK-SAME: "-o" "[[IMG_DEV_A_900:.*out]]" [[OBJ_DEV_A_900]]

// CHECK: [[BUNDLER:".*clang-offload-bundler"]] "-type=o"
// CHECK-SAME: "-targets={{.*}},hip{{.*}}-amdgcn-amd-amdhsa--gfx803,hip{{.*}}-amdgcn-amd-amdhsa--gfx900"
// CHECK-SAME: "-input={{.*}}" "-input=[[IMG_DEV_A_803]]" "-input=[[IMG_DEV_A_900]]" "-output=[[BUNDLE_A:.*hipfb]]"
2 changes: 0 additions & 2 deletions clang/test/Driver/hip-toolchain-mllvm.hip
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@
// CHECK-SAME: "-aux-triple" "x86_64-unknown-linux-gnu"
// CHECK-SAME: {{.*}} "-target-cpu" "gfx803"
// CHECK-SAME: {{.*}} "-mllvm" "-unroll-count=10" {{.*}}
// CHECK: [[LLD:".*lld.*"]] {{.*}}"-m" "elf64_amdgpu"{{.*}} "-plugin-opt=-unroll-count=10"{{.*}} "-plugin-opt=-inline-threshold=100"

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

// NEG-NOT: {{".*opt"}}
// NEG-NOT: {{".*llc"}}
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/hip-toolchain-no-rdc.hip
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
// RUN: %t/a.o %t/b.o \
// RUN: 2>&1 | FileCheck -check-prefixes=LKONLY %s

// RUN: %clang -### --target=x86_64-linux-gnu \
// RUN: %clang -### --target=x86_64-linux-gnu --no-offload-new-driver \
// RUN: --offload-arch=amdgcnspirv --offload-arch=gfx900 \
// RUN: %s -nogpuinc -nogpulib \
// RUN: 2>&1 | FileCheck -check-prefixes=AMDGCNSPIRV %s
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/invalid-offload-options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
// RUN: --offload=amdgcn-amd-amdhsa --offload-arch=gfx900 %s \
// RUN: 2>&1 | FileCheck --check-prefix=OFFLOAD-ARCH-MIX %s

// OFFLOAD-ARCH-MIX: error: option '--offload-arch' cannot be specified with '--offload'
// OFFLOAD-ARCH-MIX: error: option '--offload' cannot be specified with '--offload-arch'
6 changes: 3 additions & 3 deletions clang/unittests/Tooling/ToolingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ TEST_F(CommandLineExtractorTest, AcceptOffloadingCompile) {
TEST_F(CommandLineExtractorTest, AcceptOffloadingSyntaxOnly) {
addFile("test.c", "int main() {}\n");
const char *Args[] = {
"clang", "-target", "arm64-apple-macosx11.0.0",
"-fsyntax-only", "-x", "hip",
"test.c", "-nogpulib", "-nogpuinc"};
"clang", "-target", "arm64-apple-macosx11.0.0", "-fsyntax-only",
"-x", "hip", "--no-offload-new-driver", "test.c",
"-nogpulib", "-nogpuinc"};
EXPECT_NE(extractCC1Arguments(Args), nullptr);
}

Expand Down
Loading