summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticDriverKinds.td1
-rw-r--r--clang/include/clang/Driver/Options.td2
-rw-r--r--clang/include/clang/Driver/Types.h3
-rw-r--r--clang/lib/Driver/Driver.cpp42
-rw-r--r--clang/lib/Driver/Types.cpp10
-rw-r--r--clang/test/Driver/Inputs/hip_multiple_inputs/a.cu0
-rw-r--r--clang/test/Driver/Inputs/hip_multiple_inputs/b.hip0
-rw-r--r--clang/test/Driver/hip-inputs.hip23
8 files changed, 71 insertions, 10 deletions
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 1b94b2dc9c5..003450d951e 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -41,6 +41,7 @@ def err_drv_cuda_version_unsupported : Error<
"install, pass a different GPU arch with --cuda-gpu-arch, or pass "
"--no-cuda-version-check.">;
def err_drv_cuda_host_arch : Error<"unsupported architecture '%0' for host compilation.">;
+def err_drv_mix_cuda_hip : Error<"Mixed Cuda and HIP compilation is not supported.">;
def err_drv_invalid_thread_model_for_target : Error<
"invalid thread model '%0' in '%1' for this target">;
def err_drv_invalid_linker_name : Error<
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 8d03da31a33..0919f97665b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -557,6 +557,8 @@ def no_cuda_include_ptx_EQ : Joined<["--"], "no-cuda-include-ptx=">, Flags<[Driv
HelpText<"Do not include PTX for the follwing GPU architecture (e.g. sm_35) or 'all'. May be specified more than once.">;
def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, Flags<[DriverOption]>,
HelpText<"CUDA GPU architecture (e.g. sm_35). May be specified more than once.">;
+def hip_link : Flag<["--"], "hip-link">,
+ HelpText<"Link clang-offload-bundler bundles for HIP">;
def no_cuda_gpu_arch_EQ : Joined<["--"], "no-cuda-gpu-arch=">, Flags<[DriverOption]>,
HelpText<"Remove GPU architecture (e.g. sm_35) from the list of GPUs to compile for. "
"'all' resets the list to its default value.">;
diff --git a/clang/include/clang/Driver/Types.h b/clang/include/clang/Driver/Types.h
index 22a26ae46a0..5bc6668a0d1 100644
--- a/clang/include/clang/Driver/Types.h
+++ b/clang/include/clang/Driver/Types.h
@@ -77,6 +77,9 @@ namespace types {
/// isCuda - Is this a CUDA input.
bool isCuda(ID Id);
+ /// isHIP - Is this a HIP input.
+ bool isHIP(ID Id);
+
/// isObjC - Is this an "ObjC" input (Obj-C and Obj-C++ sources and headers).
bool isObjC(ID Id);
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1f4dbeb240c..8ca40bc923d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -538,24 +538,46 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
InputList &Inputs) {
//
- // CUDA
+ // CUDA/HIP
//
- // We need to generate a CUDA toolchain if any of the inputs has a CUDA type.
- if (llvm::any_of(Inputs, [](std::pair<types::ID, const llvm::opt::Arg *> &I) {
+ // We need to generate a CUDA toolchain if any of the inputs has a CUDA
+ // or HIP type. However, mixed CUDA/HIP compilation is not supported.
+ bool IsCuda =
+ llvm::any_of(Inputs, [](std::pair<types::ID, const llvm::opt::Arg *> &I) {
return types::isCuda(I.first);
- })) {
+ });
+ bool IsHIP =
+ llvm::any_of(Inputs,
+ [](std::pair<types::ID, const llvm::opt::Arg *> &I) {
+ return types::isHIP(I.first);
+ }) ||
+ C.getInputArgs().hasArg(options::OPT_hip_link);
+ if (IsCuda && IsHIP) {
+ Diag(clang::diag::err_drv_mix_cuda_hip);
+ return;
+ }
+ if (IsCuda || IsHIP) {
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>();
const llvm::Triple &HostTriple = HostTC->getTriple();
- llvm::Triple CudaTriple(HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda"
- : "nvptx-nvidia-cuda");
- // Use the CUDA and host triples as the key into the ToolChains map, because
- // the device toolchain we create depends on both.
+ StringRef DeviceTripleStr;
+ auto OFK = IsHIP ? Action::OFK_HIP : Action::OFK_Cuda;
+ if (IsHIP) {
+ // HIP is only supported on amdgcn.
+ DeviceTripleStr = "amdgcn-amd-amdhsa";
+ } else {
+ // CUDA is only supported on nvptx.
+ DeviceTripleStr = HostTriple.isArch64Bit() ? "nvptx64-nvidia-cuda"
+ : "nvptx-nvidia-cuda";
+ }
+ llvm::Triple CudaTriple(DeviceTripleStr);
+ // Use the CUDA/HIP and host triples as the key into the ToolChains map,
+ // because the device toolchain we create depends on both.
auto &CudaTC = ToolChains[CudaTriple.str() + "/" + HostTriple.str()];
if (!CudaTC) {
CudaTC = llvm::make_unique<toolchains::CudaToolChain>(
- *this, CudaTriple, *HostTC, C.getInputArgs(), Action::OFK_Cuda);
+ *this, CudaTriple, *HostTC, C.getInputArgs(), OFK);
}
- C.addOffloadDeviceToolChain(CudaTC.get(), Action::OFK_Cuda);
+ C.addOffloadDeviceToolChain(CudaTC.get(), OFK);
}
//
diff --git a/clang/lib/Driver/Types.cpp b/clang/lib/Driver/Types.cpp
index bcb35b1e0f4..45bb699cfb8 100644
--- a/clang/lib/Driver/Types.cpp
+++ b/clang/lib/Driver/Types.cpp
@@ -172,6 +172,15 @@ bool types::isCuda(ID Id) {
case TY_CUDA:
case TY_PP_CUDA:
case TY_CUDA_DEVICE:
+ return true;
+ }
+}
+
+bool types::isHIP(ID Id) {
+ switch (Id) {
+ default:
+ return false;
+
case TY_HIP:
case TY_PP_HIP:
case TY_HIP_DEVICE:
@@ -230,6 +239,7 @@ types::ID types::lookupTypeForExtension(llvm::StringRef Ext) {
.Case("fpp", TY_Fortran)
.Case("FPP", TY_Fortran)
.Case("gch", TY_PCH)
+ .Case("hip", TY_HIP)
.Case("hpp", TY_CXXHeader)
.Case("iim", TY_PP_CXXModule)
.Case("lib", TY_Object)
diff --git a/clang/test/Driver/Inputs/hip_multiple_inputs/a.cu b/clang/test/Driver/Inputs/hip_multiple_inputs/a.cu
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Driver/Inputs/hip_multiple_inputs/a.cu
diff --git a/clang/test/Driver/Inputs/hip_multiple_inputs/b.hip b/clang/test/Driver/Inputs/hip_multiple_inputs/b.hip
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Driver/Inputs/hip_multiple_inputs/b.hip
diff --git a/clang/test/Driver/hip-inputs.hip b/clang/test/Driver/hip-inputs.hip
new file mode 100644
index 00000000000..2febe2039ec
--- /dev/null
+++ b/clang/test/Driver/hip-inputs.hip
@@ -0,0 +1,23 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -ccc-print-phases -target x86_64-linux-gnu \
+// RUN: -x hip --cuda-gpu-arch=gfx803 -c \
+// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip 2>&1 \
+// RUN: | FileCheck %s
+
+// RUN: not %clang -ccc-print-phases -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx803 -c \
+// RUN: %S/Inputs/hip_multiple_inputs/a.cu \
+// RUN: %S/Inputs/hip_multiple_inputs/b.hip 2>&1 \
+// RUN: | FileCheck -check-prefix=MIX %s
+
+// RUN: not %clang -ccc-print-phases -target x86_64-linux-gnu \
+// RUN: --cuda-gpu-arch=gfx803 -c \
+// RUN: --hip-link %S/Inputs/hip_multiple_inputs/a.cu 2>&1 \
+// RUN: | FileCheck -check-prefix=MIX %s
+
+// CHECK-NOT: error: Mixed Cuda and HIP compilation is not supported.
+// MIX: error: Mixed Cuda and HIP compilation is not supported.
OpenPOWER on IntegriCloud