[PATCH] D89752: [CUDA] Improve clang's ability to detect recent CUDA versions.

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 19 17:06:13 PDT 2020


tra updated this revision to Diff 299223.
tra edited the summary of this revision.
tra added a comment.

Added a test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D89752/new/

https://reviews.llvm.org/D89752

Files:
  clang/lib/Driver/ToolChains/Cuda.cpp
  clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/bin/.keep
  clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/include/.keep
  clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib/.keep
  clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib64/.keep
  clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/nvvm/libdevice/libdevice.10.bc
  clang/test/Driver/cuda-version-check.cu


Index: clang/test/Driver/cuda-version-check.cu
===================================================================
--- clang/test/Driver/cuda-version-check.cu
+++ clang/test/Driver/cuda-version-check.cu
@@ -10,6 +10,10 @@
 // RUN:    FileCheck %s --check-prefix=OK
 // RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA-unknown/usr/local/cuda 2>&1 %s | \
 // RUN:    FileCheck %s --check-prefix=UNKNOWN_VERSION
+// CUDA-11.1 does not carry version.txt file. Make sure we still detect it as a
+// new version and handle it the same as we handle other new CUDA versions.
+// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA_111/usr/local/cuda 2>&1 %s | \
+// RUN:    FileCheck %s --check-prefix=UNKNOWN_VERSION
 // Make sure that we don't warn about CUDA version during C++ compilation.
 // RUN: %clang --target=x86_64-linux -v -### -x c++ --cuda-gpu-arch=sm_60 \
 // RUN:    --cuda-path=%S/Inputs/CUDA-unknown/usr/local/cuda 2>&1 %s | \
@@ -65,5 +69,5 @@
 // ERR_SM61: error: GPU arch sm_61 {{.*}}
 // ERR_SM61-NOT: error: GPU arch sm_61
 
-// UNKNOWN_VERSION: Unknown CUDA version 999.999. Assuming the latest supported version
+// UNKNOWN_VERSION: Unknown CUDA version{{.*}}. Assuming the latest supported version
 // UNKNOWN_VERSION_CXX-NOT: Unknown CUDA version
Index: clang/lib/Driver/ToolChains/Cuda.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -155,9 +155,14 @@
     llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
         FS.getBufferForFile(InstallPath + "/version.txt");
     if (!VersionFile) {
-      // CUDA 7.0 doesn't have a version.txt, so guess that's our version if
-      // version.txt isn't present.
-      Version = CudaVersion::CUDA_70;
+      // CUDA 7.0 and CUDA 11.1+ do not have version.txt file.
+      // Use libdevice file to distinguish 7.0 from the new versions.
+      if (FS.exists(LibDevicePath + "/libdevice.10.bc")) {
+        Version = CudaVersion::LATEST;
+        DetectedVersionIsNotSupported = Version > CudaVersion::LATEST_SUPPORTED;
+      } else {
+        Version = CudaVersion::CUDA_70;
+      }
     } else {
       ParseCudaVersionFile((*VersionFile)->getBuffer());
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89752.299223.patch
Type: text/x-patch
Size: 2333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201020/fc766a5a/attachment.bin>


More information about the cfe-commits mailing list