<div dir="ltr">I'm looking into it. Can you reproduce it on linux?<div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 23, 2015 at 4:43 PM, Rui Ueyama <span dir="ltr"><<a href="mailto:ruiu@google.com" target="_blank">ruiu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="h5"><div class="gmail_extra">On Wed, Sep 23, 2015 at 2:49 PM, Artem Belevich via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: tra<br>
Date: Wed Sep 23 16:49:39 2015<br>
New Revision: 248433<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=248433&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=248433&view=rev</a><br>
Log:<br>
[CUDA] Added CUDA installation detector class.<br>
<br>
Added new option --cuda-path=<path> which allows<br>
overriding default search paths.<br>
If it's not specified we look for CUDA installation in<br>
/usr/include/cuda and /usr/include/cuda-7.0.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D12989" rel="noreferrer" target="_blank">http://reviews.llvm.org/D12989</a><br>
<br>
Added:<br>
    cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/include/.keep<br>
    cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/lib/.keep<br>
    cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/lib64/.keep<br>
    cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/nvvm/libdevice/.keep<br>
    cfe/trunk/test/Driver/<a href="http://cuda-detect.cu" rel="noreferrer" target="_blank">cuda-detect.cu</a><br>
Modified:<br>
    cfe/trunk/include/clang/Driver/Options.td<br>
    cfe/trunk/lib/Driver/ToolChains.cpp<br>
    cfe/trunk/lib/Driver/ToolChains.h<br>
<br>
Modified: cfe/trunk/include/clang/Driver/Options.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=248433&r1=248432&r2=248433&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=248433&r1=248432&r2=248433&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Driver/Options.td (original)<br>
+++ cfe/trunk/include/clang/Driver/Options.td Wed Sep 23 16:49:39 2015<br>
@@ -359,6 +359,8 @@ def cuda_gpu_arch_EQ : Joined<["--"], "c<br>
   Flags<[DriverOption, HelpHidden]>, HelpText<"CUDA GPU architecture">;<br>
 def cuda_host_only : Flag<["--"], "cuda-host-only">,<br>
   HelpText<"Do host-side CUDA compilation only">;<br>
+def cuda_path_EQ : Joined<["--"], "cuda-path=">, Group<i_Group>,<br>
+  HelpText<"CUDA installation path">;<br>
 def dA : Flag<["-"], "dA">, Group<d_Group>;<br>
 def dD : Flag<["-"], "dD">, Group<d_Group>, Flags<[CC1Option]>,<br>
   HelpText<"Print macro definitions in -E mode in addition to normal output">;<br>
<br>
Modified: cfe/trunk/lib/Driver/ToolChains.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=248433&r1=248432&r2=248433&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=248433&r1=248432&r2=248433&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)<br>
+++ cfe/trunk/lib/Driver/ToolChains.cpp Wed Sep 23 16:49:39 2015<br>
@@ -1482,6 +1482,48 @@ bool Generic_GCC::GCCInstallationDetecto<br>
     BiarchTripleAliases.push_back(BiarchTriple.str());<br>
 }<br>
<br>
+// \brief -- try common CUDA installation paths looking for files we need for<br>
+// CUDA compilation.<br>
+<br>
+void<br>
+Generic_GCC::CudaInstallationDetector::init(const Driver &D,<br>
+                                            const llvm::Triple &TargetTriple,<br>
+                                            const llvm::opt::ArgList &Args) {<br>
+  SmallVector<StringRef, 4> CudaPathCandidates;<br>
+<br>
+  if (Args.hasArg(options::OPT_cuda_path_EQ))<br>
+    CudaPathCandidates.push_back(<br>
+        Args.getLastArgValue(options::OPT_cuda_path_EQ));<br>
+  else {<br>
+    CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda");<br>
+    CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0");<br>
+  }<br>
+<br>
+  for (const auto CudaPath : CudaPathCandidates) {<br>
+    if (CudaPath.empty() || !llvm::sys::fs::exists(CudaPath))<br>
+      continue;<br>
+<br>
+    CudaInstallPath = CudaPath;<br>
+    CudaIncludePath = CudaInstallPath + "/include";<br>
+    CudaLibDevicePath = CudaInstallPath + "/nvvm/libdevice";<br>
+    CudaLibPath =<br>
+        CudaInstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib");<br>
+<br>
+    if (!(llvm::sys::fs::exists(CudaIncludePath) &&<br>
+          llvm::sys::fs::exists(CudaLibPath) &&<br>
+          llvm::sys::fs::exists(CudaLibDevicePath)))<br>
+      continue;<br>
+<br>
+    IsValid = true;<br>
+    break;<br>
+  }<br>
+}<br>
+<br>
+void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const {<br>
+  if (isValid())<br>
+    OS << "Found CUDA installation: " << CudaInstallPath << "\n";<br>
+}<br>
+<br>
 namespace {<br>
 // Filter to remove Multilibs that don't exist as a suffix to Path<br>
 class FilterNonExistent {<br>
@@ -2053,7 +2095,7 @@ void Generic_GCC::GCCInstallationDetecto<br>
<br>
 Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple,<br>
                          const ArgList &Args)<br>
-    : ToolChain(D, Triple, Args), GCCInstallation() {<br>
+    : ToolChain(D, Triple, Args), GCCInstallation(), CudaInstallation() {<br>
   getProgramPaths().push_back(getDriver().getInstalledDir());<br>
   if (getDriver().getInstalledDir() != getDriver().Dir)<br>
     getProgramPaths().push_back(getDriver().Dir);<br>
@@ -2085,6 +2127,7 @@ Tool *Generic_GCC::buildLinker() const {<br>
 void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {<br>
   // Print the information about how we detected the GCC installation.<br>
   GCCInstallation.print(OS);<br>
+  CudaInstallation.print(OS);<br>
 }<br>
<br>
 bool Generic_GCC::IsUnwindTablesDefault() const {<br>
@@ -3261,6 +3304,7 @@ static StringRef getOSLibDir(const llvm:<br>
 Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)<br>
     : Generic_ELF(D, Triple, Args) {<br>
   GCCInstallation.init(D, Triple, Args);<br>
+  CudaInstallation.init(D, Triple, Args);<br>
   Multilibs = GCCInstallation.getMultilibs();<br>
   llvm::Triple::ArchType Arch = Triple.getArch();<br>
   std::string SysRoot = computeSysRoot();<br>
<br>
Modified: cfe/trunk/lib/Driver/ToolChains.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=248433&r1=248432&r2=248433&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=248433&r1=248432&r2=248433&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Driver/ToolChains.h (original)<br>
+++ cfe/trunk/lib/Driver/ToolChains.h Wed Sep 23 16:49:39 2015<br>
@@ -157,6 +157,38 @@ public:<br>
 protected:<br>
   GCCInstallationDetector GCCInstallation;<br>
<br>
+  // \brief A class to find a viable CUDA installation<br>
+<br>
+  class CudaInstallationDetector {<br>
+    bool IsValid;<br>
+    std::string CudaInstallPath;<br>
+    std::string CudaLibPath;<br>
+    std::string CudaLibDevicePath;<br>
+    std::string CudaIncludePath;<br>
+<br>
+  public:<br>
+    CudaInstallationDetector() : IsValid(false) {}<br>
+    void init(const Driver &D, const llvm::Triple &TargetTriple,<br>
+              const llvm::opt::ArgList &Args);<br>
+<br>
+    /// \brief Check whether we detected a valid Cuda install.<br>
+    bool isValid() const { return IsValid; }<br>
+    /// \brief Print information about the detected CUDA installation.<br>
+    void print(raw_ostream &OS) const;<br>
+<br>
+    /// \brief Get the detected Cuda installation path.<br>
+    StringRef getInstallPath() const { return CudaInstallPath; }<br>
+    /// \brief Get the detected Cuda Include path.<br>
+    StringRef getIncludePath() const { return CudaIncludePath; }<br>
+    /// \brief Get the detected Cuda library path.<br>
+    StringRef getLibPath() const { return CudaLibPath; }<br>
+    /// \brief Get the detected Cuda device library path.<br>
+    StringRef getLibDevicePath() const { return CudaLibDevicePath; }<br>
+    /// \brief Get libdevice file for given architecture<br>
+  };<br>
+<br>
+  CudaInstallationDetector CudaInstallation;<br>
+<br>
 public:<br>
   Generic_GCC(const Driver &D, const llvm::Triple &Triple,<br>
               const llvm::opt::ArgList &Args);<br>
<br>
Added: cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/include/.keep<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/include/.keep?rev=248433&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/include/.keep?rev=248433&view=auto</a><br>
==============================================================================<br>
    (empty)<br>
<br>
Added: cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/lib/.keep<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/lib/.keep?rev=248433&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/lib/.keep?rev=248433&view=auto</a><br>
==============================================================================<br>
    (empty)<br>
<br>
Added: cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/lib64/.keep<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/lib64/.keep?rev=248433&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/lib64/.keep?rev=248433&view=auto</a><br>
==============================================================================<br>
    (empty)<br>
<br>
Added: cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/nvvm/libdevice/.keep<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/nvvm/libdevice/.keep?rev=248433&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/Inputs/CUDA/usr/local/cuda/nvvm/libdevice/.keep?rev=248433&view=auto</a><br>
==============================================================================<br>
    (empty)<br>
<br>
Added: cfe/trunk/test/Driver/<a href="http://cuda-detect.cu" rel="noreferrer" target="_blank">cuda-detect.cu</a><br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-detect.cu?rev=248433&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-detect.cu?rev=248433&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Driver/<a href="http://cuda-detect.cu" rel="noreferrer" target="_blank">cuda-detect.cu</a> (added)<br>
+++ cfe/trunk/test/Driver/<a href="http://cuda-detect.cu" rel="noreferrer" target="_blank">cuda-detect.cu</a> Wed Sep 23 16:49:39 2015<br>
@@ -0,0 +1,12 @@<br>
+// REQUIRES: clang-driver<br>
+// REQUIRES: x86-registered-target<br>
+//<br>
+// RUN: %clang -v --target=i386-unknown-linux \<br>
+// RUN:   --sysroot=/tmp/no-cuda-there 2>&1 | FileCheck %s -check-prefix NOCUDA<br>
+// RUN: %clang -v --target=i386-unknown-linux \<br>
+// RUN:   --sysroot=%S/Inputs/CUDA 2>&1 | FileCheck %s<br>
+// RUN: %clang -v --target=i386-unknown-linux \<br>
+// RUN:   --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 | FileCheck %s<br>
+<br>
+// CHECK: Found CUDA installation: {{.*}}/Inputs/CUDA/usr/local/cuda<br>
+// NOCUDA-NOT: Found CUDA installation:<br></blockquote><div><br></div></div></div><div>This test seems to fail on Linux if the full path to Inputs directory is very long because it fails to detect the cuda installation path. Can you take a look?</div></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">--Artem Belevich</div></div>
</div>