[PATCH] D139045: [HIP] use detected GPU in --offload-arch

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 1 11:09:51 PST 2022


yaxunl updated this revision to Diff 479365.
yaxunl added a comment.

fix error handling


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139045/new/

https://reviews.llvm.org/D139045

Files:
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/AMDGPU.h


Index: clang/lib/Driver/ToolChains/AMDGPU.h
===================================================================
--- clang/lib/Driver/ToolChains/AMDGPU.h
+++ clang/lib/Driver/ToolChains/AMDGPU.h
@@ -118,6 +118,9 @@
   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;
@@ -137,8 +140,6 @@
   /// 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 {
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -3312,13 +3312,25 @@
       for (auto Arch : GpuArchs)
         GpuArchList.push_back(Arch.data());
 
-      // Default to sm_20 which is the lowest common denominator for
+      // CUDA defaults to sm_20 which is the lowest common denominator for
       // supported GPUs.  sm_20 code should work correctly, if
       // suboptimally, on all newer GPUs.
       if (GpuArchList.empty()) {
         if (ToolChains.front()->getTriple().isSPIRV())
           GpuArchList.push_back(CudaArch::Generic);
-        else
+        else if (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)
+              GpuArchList.push_back(Args.MakeArgString(GPU));
+          } else {
+            llvm::consumeError(std::move(Err));
+            GpuArchList.push_back(DefaultCudaArch);
+          }
+        } else
           GpuArchList.push_back(DefaultCudaArch);
       }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139045.479365.patch
Type: text/x-patch
Size: 2285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221201/70ef8170/attachment.bin>


More information about the cfe-commits mailing list