[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    [PATCH] D139045: [HIP] use detected GPU in --offload-arch
From:       Yaxun Liu via Phabricator via cfe-commits <cfe-commits () lists ! llvm ! org>
Date:       2022-11-30 22:41:46
Message-ID: RM4ki8sQSNW2xs8aPwy-6g () geopod-ismtpd-1-6
[Download RAW message or body]

yaxunl created this revision.
yaxunl added a reviewer: tra.
Herald added subscribers: kosarev, kerbowa, jvesely.
Herald added a project: All.
yaxunl requested review of this revision.
Herald added a subscriber: MaskRay.

Currently HIP uses gfx803 as offload arch if not
specified. This is not convenient for command
line users.

This patch detects system GPU and use them
in --offload-arch if not specified. If system GPU
cannot be detected clang will fall back to gfx893.


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
@@ -107,6 +107,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;
@@ -126,8 +129,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
@@ -3095,13 +3095,22 @@
       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;
+          if (!TC->detectSystemGPUs(Args, GPUs)) {
+            for (auto GPU : GPUs)
+              GpuArchList.push_back(Args.MakeArgString(GPU));
+          } else
+            GpuArchList.push_back(DefaultCudaArch);
+        } else
           GpuArchList.push_back(DefaultCudaArch);
       }
 



["D139045.479071.patch" (D139045.479071.patch)]

Index: clang/lib/Driver/ToolChains/AMDGPU.h
===================================================================
--- clang/lib/Driver/ToolChains/AMDGPU.h
+++ clang/lib/Driver/ToolChains/AMDGPU.h
@@ -107,6 +107,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;
@@ -126,8 +129,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
@@ -3095,13 +3095,22 @@
       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;
+          if (!TC->detectSystemGPUs(Args, GPUs)) {
+            for (auto GPU : GPUs)
+              GpuArchList.push_back(Args.MakeArgString(GPU));
+          } else
+            GpuArchList.push_back(DefaultCudaArch);
+        } else
           GpuArchList.push_back(DefaultCudaArch);
       }
 

[Attachment #4 (text/plain)]

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic