[OpenMP] Provide a default GPU arch that is supported by
authorGheorghe-Teodor Bercea <gheorghe-teod.bercea@ibm.com>
Thu, 10 Aug 2017 05:01:42 +0000 (05:01 +0000)
committerGheorghe-Teodor Bercea <gheorghe-teod.bercea@ibm.com>
Thu, 10 Aug 2017 05:01:42 +0000 (05:01 +0000)
the underlying hardware.

This fixes a bug triggered by diff: D29660

llvm-svn: 310549

clang/lib/Driver/ToolChains/Cuda.cpp
clang/lib/Driver/ToolChains/Cuda.h

index 41185ed..a0bbd52 100644 (file)
@@ -533,10 +533,14 @@ CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
     }
 
     StringRef Arch = DAL->getLastArgValue(options::OPT_march_EQ);
-    if (Arch.empty())
-      // Default compute capability for CUDA toolchain is sm_20.
+    if (Arch.empty()) {
+      // Default compute capability for CUDA toolchain is the
+      // lowest compute capability supported by the installed
+      // CUDA version.
       DAL->AddJoinedArg(nullptr,
-          Opts.getOption(options::OPT_march_EQ), "sm_20");
+          Opts.getOption(options::OPT_march_EQ),
+          CudaInstallation.getLowestExistingArch());
+    }
 
     return DAL;
   }
index 1e30aa7..9b3d6d7 100644 (file)
@@ -76,6 +76,17 @@ public:
   std::string getLibDeviceFile(StringRef Gpu) const {
     return LibDeviceMap.lookup(Gpu);
   }
+  /// \brief Get lowest available compute capability
+  /// for which a libdevice library exists.
+  std::string getLowestExistingArch() const {
+    std::string LibDeviceFile;
+    for (auto key : LibDeviceMap.keys()) {
+      LibDeviceFile = LibDeviceMap.lookup(key);
+      if (!LibDeviceFile.empty())
+        return key;
+    }
+    llvm_unreachable("no libdevice exists.");
+  }
 };
 
 namespace tools {