[PATCH] D55269: [CUDA][OpenMP] Fix nvidia-cuda-toolkit detection on Debian/Ubuntu

Joel E. Denny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 4 07:15:58 PST 2018


jdenny created this revision.
jdenny added reviewers: ABataev, Hahnfeld, tra, sylvestre.ledru.
Herald added a subscriber: guansong.

D40453 <https://reviews.llvm.org/D40453> (r319317) was meant to handle nvidia-cuda-toolkit's split CUDA
installation in Debian.  This patch addresses two issues left
unresolved by D40453 <https://reviews.llvm.org/D40453>, at least on my Ubuntu 18.04.1 installation:

1. IsDebian() doesn't include IsUbuntu(), so D40453 <https://reviews.llvm.org/D40453> doesn't help me.

2. When `--cuda-path=/usr` is meant to find the nvidia-cuda-toolkit installation, the split installation isn't handled.

Issue 2 occurs when I follow step 4 in the following guide to rebuild
the OpenMP runtime with clang to build bitcode libraries:

https://www.hahnjo.de/blog/2018/10/08/clang-7.0-openmp-offloading-nvidia.html

The reason is that
`libomptarget/cmake/Modules/LibomptargetNVPTXBitcodeLibrary.cmake`
then specifies `--cuda-path=/usr` when testing clang, but it would
need to leave `--cuda-path` unspecified to trigger D40453 <https://reviews.llvm.org/D40453>'s fix.
Perhaps that cmake file could be adjusted instead, but the fix in this
patch is more general.

Obviously, this isn't the first time this issue has been discussed,
but googling didn't reveal to me a definitive answer on the path
forward.  Proposing this patch seems like the easiest way to ask.


Repository:
  rC Clang

https://reviews.llvm.org/D55269

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp


Index: clang/lib/Driver/ToolChains/Cuda.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -80,9 +80,19 @@
   // In decreasing order so we prefer newer versions to older versions.
   std::initializer_list<const char *> Versions = {"8.0", "7.5", "7.0"};
 
+  // Special case for Debian to have nvidia-cuda-toolkit work
+  // out of the box. More info on http://bugs.debian.org/882505
+  const char *NvidiaCudaToolkit =
+      (Distro(D.getVFS()).IsDebian() || Distro(D.getVFS()).IsUbuntu())
+          ? "/usr/lib/cuda"
+          : nullptr;
+
   if (Args.hasArg(clang::driver::options::OPT_cuda_path_EQ)) {
-    Candidates.emplace_back(
-        Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str());
+    std::string CudaPath =
+        Args.getLastArgValue(clang::driver::options::OPT_cuda_path_EQ).str();
+    Candidates.emplace_back(CudaPath);
+    if (NvidiaCudaToolkit && CudaPath == "/usr")
+      Candidates.emplace_back(D.SysRoot + NvidiaCudaToolkit);
   } else if (HostTriple.isOSWindows()) {
     for (const char *Ver : Versions)
       Candidates.emplace_back(
@@ -114,10 +124,8 @@
     for (const char *Ver : Versions)
       Candidates.emplace_back(D.SysRoot + "/usr/local/cuda-" + Ver);
 
-    if (Distro(D.getVFS()).IsDebian())
-      // Special case for Debian to have nvidia-cuda-toolkit work
-      // out of the box. More info on http://bugs.debian.org/882505
-      Candidates.emplace_back(D.SysRoot + "/usr/lib/cuda");
+    if (NvidiaCudaToolkit)
+      Candidates.emplace_back(D.SysRoot + NvidiaCudaToolkit);
   }
 
   bool NoCudaLib = Args.hasArg(options::OPT_nocudalib);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55269.176630.patch
Type: text/x-patch
Size: 1718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181204/decd6caf/attachment-0001.bin>


More information about the cfe-commits mailing list