[clang] e8fd998 - [HIP] support --offload-arch=native
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 13 07:10:56 PST 2022
Author: Yaxun (Sam) Liu
Date: 2022-12-13T10:09:33-05:00
New Revision: e8fd998e6194d8749b83b30813e3cb74e5261770
URL: https://github.com/llvm/llvm-project/commit/e8fd998e6194d8749b83b30813e3cb74e5261770
DIFF: https://github.com/llvm/llvm-project/commit/e8fd998e6194d8749b83b30813e3cb74e5261770.diff
LOG: [HIP] support --offload-arch=native
This patch detects system GPU and use them
in --offload-arch if 'native' is specified. If system GPU
cannot be detected clang will fall back to the default GPU arch.
Reviewed by: Artem Belevich
Differential Revision: https://reviews.llvm.org/D139045
Added:
Modified:
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/AMDGPU.h
Removed:
################################################################################
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 969d38560018b..c7efe60b23359 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3067,6 +3067,17 @@ class OffloadingActionBuilder final {
if (A->getOption().matches(options::OPT_no_offload_arch_EQ) &&
ArchStr == "all") {
GpuArchs.clear();
+ } else if (ArchStr == "native" &&
+ ToolChains.front()->getTriple().isAMDGPU()) {
+ auto *TC = static_cast<const toolchains::HIPAMDToolChain *>(
+ ToolChains.front());
+ SmallVector<std::string, 1> GPUs;
+ auto Err = TC->detectSystemGPUs(Args, GPUs);
+ if (!Err) {
+ for (auto GPU : GPUs)
+ GpuArchs.insert(Args.MakeArgString(GPU));
+ } else
+ llvm::consumeError(std::move(Err));
} else {
ArchStr = getCanonicalOffloadArch(ArchStr);
if (ArchStr.empty()) {
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h
index 0ac13ecaa6345..3f5461a1c5696 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -107,6 +107,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
llvm::Error getSystemGPUArch(const llvm::opt::ArgList &Args,
std::string &GPUArch) const;
+ llvm::Error detectSystemGPUs(const llvm::opt::ArgList &Args,
+ SmallVector<std::string, 1> &GPUArchs) const;
+
protected:
/// Check and diagnose invalid target ID specified by -mcpu.
virtual void checkTargetID(const llvm::opt::ArgList &DriverArgs) const;
@@ -126,8 +129,6 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
/// Get GPU arch from -mcpu without checking.
StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const;
- llvm::Error detectSystemGPUs(const llvm::opt::ArgList &Args,
- SmallVector<std::string, 1> &GPUArchs) const;
};
class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
More information about the cfe-commits
mailing list