From a659943306066743700eb177b3eae5cb300ddc11 Mon Sep 17 00:00:00 2001 From: Gheorghe-Teodor Bercea Date: Thu, 10 Aug 2017 05:01:42 +0000 Subject: [PATCH] [OpenMP] Provide a default GPU arch that is supported by the underlying hardware. This fixes a bug triggered by diff: D29660 llvm-svn: 310549 --- clang/lib/Driver/ToolChains/Cuda.cpp | 10 +++++++--- clang/lib/Driver/ToolChains/Cuda.h | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp index 41185ed..a0bbd52 100644 --- a/clang/lib/Driver/ToolChains/Cuda.cpp +++ b/clang/lib/Driver/ToolChains/Cuda.cpp @@ -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; } diff --git a/clang/lib/Driver/ToolChains/Cuda.h b/clang/lib/Driver/ToolChains/Cuda.h index 1e30aa7..9b3d6d7 100644 --- a/clang/lib/Driver/ToolChains/Cuda.h +++ b/clang/lib/Driver/ToolChains/Cuda.h @@ -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 { -- 2.7.4