summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Belevich <tra@google.com>2015-09-23 21:49:39 +0000
committerArtem Belevich <tra@google.com>2015-09-23 21:49:39 +0000
commit98607b6757f895f1b84ba535c334bca78114f533 (patch)
tree4eb37fec59c4d5b8fe282f1951d6775ef0e503f8
parent9f21f68bfeedd25af8be00722b47e9d5dca9de8a (diff)
downloadbcm5719-llvm-98607b6757f895f1b84ba535c334bca78114f533.tar.gz
bcm5719-llvm-98607b6757f895f1b84ba535c334bca78114f533.zip
[CUDA] Added CUDA installation detector class.
Added new option --cuda-path=<path> which allows overriding default search paths. If it's not specified we look for CUDA installation in /usr/include/cuda and /usr/include/cuda-7.0. Differential Revision: http://reviews.llvm.org/D12989 llvm-svn: 248433
-rw-r--r--clang/include/clang/Driver/Options.td2
-rw-r--r--clang/lib/Driver/ToolChains.cpp46
-rw-r--r--clang/lib/Driver/ToolChains.h32
-rw-r--r--clang/test/Driver/Inputs/CUDA/usr/local/cuda/include/.keep0
-rw-r--r--clang/test/Driver/Inputs/CUDA/usr/local/cuda/lib/.keep0
-rw-r--r--clang/test/Driver/Inputs/CUDA/usr/local/cuda/lib64/.keep0
-rw-r--r--clang/test/Driver/Inputs/CUDA/usr/local/cuda/nvvm/libdevice/.keep0
-rw-r--r--clang/test/Driver/cuda-detect.cu12
8 files changed, 91 insertions, 1 deletions
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index ebc6f3cb5ea..018855a9745 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -359,6 +359,8 @@ def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">,
Flags<[DriverOption, HelpHidden]>, HelpText<"CUDA GPU architecture">;
def cuda_host_only : Flag<["--"], "cuda-host-only">,
HelpText<"Do host-side CUDA compilation only">;
+def cuda_path_EQ : Joined<["--"], "cuda-path=">, Group<i_Group>,
+ HelpText<"CUDA installation path">;
def dA : Flag<["-"], "dA">, Group<d_Group>;
def dD : Flag<["-"], "dD">, Group<d_Group>, Flags<[CC1Option]>,
HelpText<"Print macro definitions in -E mode in addition to normal output">;
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp
index b5edcf9f5ce..8d12f2d0fb0 100644
--- a/clang/lib/Driver/ToolChains.cpp
+++ b/clang/lib/Driver/ToolChains.cpp
@@ -1482,6 +1482,48 @@ bool Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const {
BiarchTripleAliases.push_back(BiarchTriple.str());
}
+// \brief -- try common CUDA installation paths looking for files we need for
+// CUDA compilation.
+
+void
+Generic_GCC::CudaInstallationDetector::init(const Driver &D,
+ const llvm::Triple &TargetTriple,
+ const llvm::opt::ArgList &Args) {
+ SmallVector<StringRef, 4> CudaPathCandidates;
+
+ if (Args.hasArg(options::OPT_cuda_path_EQ))
+ CudaPathCandidates.push_back(
+ Args.getLastArgValue(options::OPT_cuda_path_EQ));
+ else {
+ CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda");
+ CudaPathCandidates.push_back(D.SysRoot + "/usr/local/cuda-7.0");
+ }
+
+ for (const auto CudaPath : CudaPathCandidates) {
+ if (CudaPath.empty() || !llvm::sys::fs::exists(CudaPath))
+ continue;
+
+ CudaInstallPath = CudaPath;
+ CudaIncludePath = CudaInstallPath + "/include";
+ CudaLibDevicePath = CudaInstallPath + "/nvvm/libdevice";
+ CudaLibPath =
+ CudaInstallPath + (TargetTriple.isArch64Bit() ? "/lib64" : "/lib");
+
+ if (!(llvm::sys::fs::exists(CudaIncludePath) &&
+ llvm::sys::fs::exists(CudaLibPath) &&
+ llvm::sys::fs::exists(CudaLibDevicePath)))
+ continue;
+
+ IsValid = true;
+ break;
+ }
+}
+
+void Generic_GCC::CudaInstallationDetector::print(raw_ostream &OS) const {
+ if (isValid())
+ OS << "Found CUDA installation: " << CudaInstallPath << "\n";
+}
+
namespace {
// Filter to remove Multilibs that don't exist as a suffix to Path
class FilterNonExistent {
@@ -2053,7 +2095,7 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple(
Generic_GCC::Generic_GCC(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args)
- : ToolChain(D, Triple, Args), GCCInstallation() {
+ : ToolChain(D, Triple, Args), GCCInstallation(), CudaInstallation() {
getProgramPaths().push_back(getDriver().getInstalledDir());
if (getDriver().getInstalledDir() != getDriver().Dir)
getProgramPaths().push_back(getDriver().Dir);
@@ -2085,6 +2127,7 @@ Tool *Generic_GCC::buildLinker() const { return new tools::gcc::Linker(*this); }
void Generic_GCC::printVerboseInfo(raw_ostream &OS) const {
// Print the information about how we detected the GCC installation.
GCCInstallation.print(OS);
+ CudaInstallation.print(OS);
}
bool Generic_GCC::IsUnwindTablesDefault() const {
@@ -3261,6 +3304,7 @@ static StringRef getOSLibDir(const llvm::Triple &Triple, const ArgList &Args) {
Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
: Generic_ELF(D, Triple, Args) {
GCCInstallation.init(D, Triple, Args);
+ CudaInstallation.init(D, Triple, Args);
Multilibs = GCCInstallation.getMultilibs();
llvm::Triple::ArchType Arch = Triple.getArch();
std::string SysRoot = computeSysRoot();
diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h
index f14fc3e78e5..e63f3363d17 100644
--- a/clang/lib/Driver/ToolChains.h
+++ b/clang/lib/Driver/ToolChains.h
@@ -157,6 +157,38 @@ public:
protected:
GCCInstallationDetector GCCInstallation;
+ // \brief A class to find a viable CUDA installation
+
+ class CudaInstallationDetector {
+ bool IsValid;
+ std::string CudaInstallPath;
+ std::string CudaLibPath;
+ std::string CudaLibDevicePath;
+ std::string CudaIncludePath;
+
+ public:
+ CudaInstallationDetector() : IsValid(false) {}
+ void init(const Driver &D, const llvm::Triple &TargetTriple,
+ const llvm::opt::ArgList &Args);
+
+ /// \brief Check whether we detected a valid Cuda install.
+ bool isValid() const { return IsValid; }
+ /// \brief Print information about the detected CUDA installation.
+ void print(raw_ostream &OS) const;
+
+ /// \brief Get the detected Cuda installation path.
+ StringRef getInstallPath() const { return CudaInstallPath; }
+ /// \brief Get the detected Cuda Include path.
+ StringRef getIncludePath() const { return CudaIncludePath; }
+ /// \brief Get the detected Cuda library path.
+ StringRef getLibPath() const { return CudaLibPath; }
+ /// \brief Get the detected Cuda device library path.
+ StringRef getLibDevicePath() const { return CudaLibDevicePath; }
+ /// \brief Get libdevice file for given architecture
+ };
+
+ CudaInstallationDetector CudaInstallation;
+
public:
Generic_GCC(const Driver &D, const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);
diff --git a/clang/test/Driver/Inputs/CUDA/usr/local/cuda/include/.keep b/clang/test/Driver/Inputs/CUDA/usr/local/cuda/include/.keep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Driver/Inputs/CUDA/usr/local/cuda/include/.keep
diff --git a/clang/test/Driver/Inputs/CUDA/usr/local/cuda/lib/.keep b/clang/test/Driver/Inputs/CUDA/usr/local/cuda/lib/.keep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Driver/Inputs/CUDA/usr/local/cuda/lib/.keep
diff --git a/clang/test/Driver/Inputs/CUDA/usr/local/cuda/lib64/.keep b/clang/test/Driver/Inputs/CUDA/usr/local/cuda/lib64/.keep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Driver/Inputs/CUDA/usr/local/cuda/lib64/.keep
diff --git a/clang/test/Driver/Inputs/CUDA/usr/local/cuda/nvvm/libdevice/.keep b/clang/test/Driver/Inputs/CUDA/usr/local/cuda/nvvm/libdevice/.keep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/clang/test/Driver/Inputs/CUDA/usr/local/cuda/nvvm/libdevice/.keep
diff --git a/clang/test/Driver/cuda-detect.cu b/clang/test/Driver/cuda-detect.cu
new file mode 100644
index 00000000000..d71b577a803
--- /dev/null
+++ b/clang/test/Driver/cuda-detect.cu
@@ -0,0 +1,12 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+//
+// RUN: %clang -v --target=i386-unknown-linux \
+// RUN: --sysroot=/tmp/no-cuda-there 2>&1 | FileCheck %s -check-prefix NOCUDA
+// RUN: %clang -v --target=i386-unknown-linux \
+// RUN: --sysroot=%S/Inputs/CUDA 2>&1 | FileCheck %s
+// RUN: %clang -v --target=i386-unknown-linux \
+// RUN: --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 | FileCheck %s
+
+// CHECK: Found CUDA installation: {{.*}}/Inputs/CUDA/usr/local/cuda
+// NOCUDA-NOT: Found CUDA installation:
OpenPOWER on IntegriCloud