]> granicus.if.org Git - clang/commitdiff
[CUDA] Require libdevice only if needed
authorJonas Hahnfeld <hahnjo@hahnjo.de>
Mon, 16 Oct 2017 13:31:30 +0000 (13:31 +0000)
committerJonas Hahnfeld <hahnjo@hahnjo.de>
Mon, 16 Oct 2017 13:31:30 +0000 (13:31 +0000)
If the user passes -nocudalib, we can live without it being present.
Simplify the code by just checking whether LibDeviceMap is empty.

Differential Revision: https://reviews.llvm.org/D38901

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315902 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/Cuda.cpp
test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/bin/.keep [new file with mode: 0644]
test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/include/.keep [new file with mode: 0644]
test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/lib/.keep [new file with mode: 0644]
test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/lib64/.keep [new file with mode: 0644]
test/Driver/cuda-detect.cu

index 349f9e4f51a91181cdcd98471d673566a313e462..4d040a204dd304f3265de702794749179ebbbd01 100644 (file)
@@ -87,8 +87,7 @@ CudaInstallationDetector::CudaInstallationDetector(
     LibDevicePath = InstallPath + "/nvvm/libdevice";
 
     auto &FS = D.getVFS();
-    if (!(FS.exists(IncludePath) && FS.exists(BinPath) &&
-          FS.exists(LibDevicePath)))
+    if (!(FS.exists(IncludePath) && FS.exists(BinPath)))
       continue;
 
     // On Linux, we have both lib and lib64 directories, and we need to choose
@@ -167,17 +166,9 @@ CudaInstallationDetector::CudaInstallationDetector(
       }
     }
 
-    // This code prevents IsValid from being set when
-    // no libdevice has been found.
-    bool allEmpty = true;
-    std::string LibDeviceFile;
-    for (auto key : LibDeviceMap.keys()) {
-      LibDeviceFile = LibDeviceMap.lookup(key);
-      if (!LibDeviceFile.empty())
-        allEmpty = false;
-    }
-
-    if (allEmpty)
+    // Check that we have found at least one libdevice that we can link in if
+    // -nocudalib hasn't been specified.
+    if (LibDeviceMap.empty() && !Args.hasArg(options::OPT_nocudalib))
       continue;
 
     IsValid = true;
diff --git a/test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/bin/.keep b/test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/bin/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/include/.keep b/test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/include/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/lib/.keep b/test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/lib/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/lib64/.keep b/test/Driver/Inputs/CUDA-nolibdevice/usr/local/cuda/lib64/.keep
new file mode 100644 (file)
index 0000000..e69de29
index aaef89ac453d17cb2afaaf86ad6c063412d9da39..1db0cfbfa3ce5a8df7398cb5977727fe66b7d807 100644 (file)
@@ -2,7 +2,7 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
 //
-// Check that we properly detect CUDA installation.
+// Check that we properly detect CUDA installation.
 // RUN: %clang -v --target=i386-unknown-linux \
 // RUN:   --sysroot=%S/no-cuda-there 2>&1 | FileCheck %s -check-prefix NOCUDA
 // RUN: %clang -v --target=i386-apple-macosx \
 // RUN: %clang -v --target=i386-apple-macosx \
 // RUN:   --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 | FileCheck %s
 
+// Check that we don't find a CUDA installation without libdevice ...
+// RUN: %clang -v --target=i386-unknown-linux \
+// RUN:   --sysroot=%S/Inputs/CUDA-nolibdevice 2>&1 | FileCheck %s -check-prefix NOCUDA
+// RUN: %clang -v --target=i386-apple-macosx \
+// RUN:   --sysroot=%S/Inputs/CUDA-nolibdevice 2>&1 | FileCheck %s -check-prefix NOCUDA
+
+// ... unless the user doesn't need libdevice
+// RUN: %clang -v --target=i386-unknown-linux -nocudalib \
+// RUN:   --sysroot=%S/Inputs/CUDA-nolibdevice 2>&1 | FileCheck %s -check-prefix NO-LIBDEVICE
+// RUN: %clang -v --target=i386-apple-macosx -nocudalib \
+// RUN:   --sysroot=%S/Inputs/CUDA-nolibdevice 2>&1 | FileCheck %s -check-prefix NO-LIBDEVICE
+
+
 // Make sure we map libdevice bitcode files to proper GPUs. These
 // tests use Inputs/CUDA_80 which has full set of libdevice files.
 // However, libdevice mapping only matches CUDA-7.x at the moment.
 // RUN: | FileCheck %s --check-prefix CHECK-CXXINCLUDE
 
 // CHECK: Found CUDA installation: {{.*}}/Inputs/CUDA/usr/local/cuda
+// NO-LIBDEVICE: Found CUDA installation: {{.*}}/Inputs/CUDA-nolibdevice/usr/local/cuda
 // NOCUDA-NOT: Found CUDA installation:
 
 // MISSINGLIBDEVICE: error: cannot find libdevice for sm_20.