]> granicus.if.org Git - clang/commitdiff
[CUDA] Print an error if you try to compile with < sm_30 on CUDA 9.
authorJustin Lebar <jlebar@google.com>
Wed, 25 Oct 2017 21:32:06 +0000 (21:32 +0000)
committerJustin Lebar <jlebar@google.com>
Wed, 25 Oct 2017 21:32:06 +0000 (21:32 +0000)
Summary:
CUDA 9's minimum sm is sm_30.

Ideally we should also make sm_30 the default when compiling with CUDA
9, but that seems harder than it should be.

Subscribers: sanjoy

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

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

12 files changed:
include/clang/Basic/Cuda.h
include/clang/Basic/DiagnosticDriverKinds.td
lib/Basic/Cuda.cpp
lib/Driver/ToolChains/Cuda.cpp
lib/Driver/ToolChains/Cuda.h
test/Driver/Inputs/CUDA_90/usr/local/cuda/bin/.keep [new file with mode: 0644]
test/Driver/Inputs/CUDA_90/usr/local/cuda/include/.keep [new file with mode: 0644]
test/Driver/Inputs/CUDA_90/usr/local/cuda/lib/.keep [new file with mode: 0644]
test/Driver/Inputs/CUDA_90/usr/local/cuda/lib64/.keep [new file with mode: 0644]
test/Driver/Inputs/CUDA_90/usr/local/cuda/nvvm/libdevice/libdevice.10.bc [new file with mode: 0644]
test/Driver/Inputs/CUDA_90/usr/local/cuda/version.txt [new file with mode: 0644]
test/Driver/cuda-bad-arch.cu

index b273365975d3f37bef0901ca365478722c73110d..1a0731c37a35fd8021684100a1be9ca82e0f7526 100644 (file)
@@ -22,6 +22,7 @@ enum class CudaVersion {
   CUDA_75,
   CUDA_80,
   CUDA_90,
+  LATEST = CUDA_90,
 };
 const char *CudaVersionToString(CudaVersion V);
 
@@ -75,6 +76,9 @@ CudaVirtualArch VirtualArchForCudaArch(CudaArch A);
 /// Get the earliest CudaVersion that supports the given CudaArch.
 CudaVersion MinVersionForCudaArch(CudaArch A);
 
+/// Get the latest CudaVersion that supports the given CudaArch.
+CudaVersion MaxVersionForCudaArch(CudaArch A);
+
 } // namespace clang
 
 #endif
index 67472a59643e7c74f68dbfe737b5632c4e87d222..dd72c958d131d8654f683224ea68f2aea84a9b77 100644 (file)
@@ -29,9 +29,10 @@ def err_drv_no_cuda_installation : Error<
 def err_drv_no_cuda_libdevice : Error<
   "cannot find libdevice for %0. Provide path to different CUDA installation "
   "via --cuda-path, or pass -nocudalib to build without linking with libdevice.">;
-def err_drv_cuda_version_too_low : Error<
-  "GPU arch %1 requires CUDA version at least %3, but installation at %0 is %2. "
-  "Use --cuda-path to specify a different CUDA install, or pass "
+def err_drv_cuda_version_unsupported : Error<
+  "GPU arch %0 is supported by CUDA versions between %1 and %2 (inclusive), "
+  "but installation at %3 is %4.  Use --cuda-path to specify a different CUDA "
+  "install, pass a different GPU arch with --cuda-gpu-arch, or pass "
   "--no-cuda-version-check.">;
 def err_drv_cuda_nvptx_host : Error<"unsupported use of NVPTX for host compilation.">;
 def err_drv_invalid_thread_model_for_target : Error<
index 3a5297b0c6432100be01aa75354cb5dbf1994c0e..58b99a3b58cbee610f6415db3542041148cd3c7b 100644 (file)
@@ -180,4 +180,16 @@ CudaVersion MinVersionForCudaArch(CudaArch A) {
   llvm_unreachable("invalid enum");
 }
 
+CudaVersion MaxVersionForCudaArch(CudaArch A) {
+  switch (A) {
+  case CudaArch::UNKNOWN:
+    return CudaVersion::UNKNOWN;
+  case CudaArch::SM_20:
+  case CudaArch::SM_21:
+    return CudaVersion::CUDA_80;
+  default:
+    return CudaVersion::LATEST;
+  }
+}
+
 } // namespace clang
index 4f740fc9525f6e6501dcdb151f86af8f9c8880ea..44ec16e8b86dca1a3a1f878c0aae0966cbc2f5f0 100644 (file)
@@ -205,15 +205,17 @@ void CudaInstallationDetector::AddCudaIncludeArgs(
 void CudaInstallationDetector::CheckCudaVersionSupportsArch(
     CudaArch Arch) const {
   if (Arch == CudaArch::UNKNOWN || Version == CudaVersion::UNKNOWN ||
-      ArchsWithVersionTooLowErrors.count(Arch) > 0)
+      ArchsWithBadVersion.count(Arch) > 0)
     return;
 
-  auto RequiredVersion = MinVersionForCudaArch(Arch);
-  if (Version < RequiredVersion) {
-    ArchsWithVersionTooLowErrors.insert(Arch);
-    D.Diag(diag::err_drv_cuda_version_too_low)
-        << InstallPath << CudaArchToString(Arch) << CudaVersionToString(Version)
-        << CudaVersionToString(RequiredVersion);
+  auto MinVersion = MinVersionForCudaArch(Arch);
+  auto MaxVersion = MaxVersionForCudaArch(Arch);
+  if (Version < MinVersion || Version > MaxVersion) {
+    ArchsWithBadVersion.insert(Arch);
+    D.Diag(diag::err_drv_cuda_version_unsupported)
+        << CudaArchToString(Arch) << CudaVersionToString(MinVersion)
+        << CudaVersionToString(MaxVersion) << InstallPath
+        << CudaVersionToString(Version);
   }
 }
 
index 1e30aa72702a7b2b062d192e7c3b79123d3a1811..414c9445c7926c21e13f0c1bf607ca4e294efbcb 100644 (file)
@@ -40,7 +40,7 @@ private:
 
   // CUDA architectures for which we have raised an error in
   // CheckCudaVersionSupportsArch.
-  mutable llvm::SmallSet<CudaArch, 4> ArchsWithVersionTooLowErrors;
+  mutable llvm::SmallSet<CudaArch, 4> ArchsWithBadVersion;
 
 public:
   CudaInstallationDetector(const Driver &D, const llvm::Triple &HostTriple,
diff --git a/test/Driver/Inputs/CUDA_90/usr/local/cuda/bin/.keep b/test/Driver/Inputs/CUDA_90/usr/local/cuda/bin/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/CUDA_90/usr/local/cuda/include/.keep b/test/Driver/Inputs/CUDA_90/usr/local/cuda/include/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/CUDA_90/usr/local/cuda/lib/.keep b/test/Driver/Inputs/CUDA_90/usr/local/cuda/lib/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/CUDA_90/usr/local/cuda/lib64/.keep b/test/Driver/Inputs/CUDA_90/usr/local/cuda/lib64/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/CUDA_90/usr/local/cuda/nvvm/libdevice/libdevice.10.bc b/test/Driver/Inputs/CUDA_90/usr/local/cuda/nvvm/libdevice/libdevice.10.bc
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/test/Driver/Inputs/CUDA_90/usr/local/cuda/version.txt b/test/Driver/Inputs/CUDA_90/usr/local/cuda/version.txt
new file mode 100644 (file)
index 0000000..24e1fd4
--- /dev/null
@@ -0,0 +1 @@
+CUDA Version 9.0.103
index cbc2d11f90e61666f22c5f913eaca7be3f8688ac..a6559b0c781060aa7acf31b6dd65233b1b89f9b0 100644 (file)
 
 // BAD: error: Unsupported CUDA gpu architecture
 
+// RUN: %clang -### -v --target=x86_64-linux-gnu --cuda-gpu-arch=sm_21 \
+// RUN:   --cuda-path=%S/Inputs/CUDA_90/usr/local/cuda %s 2>&1 \
+// RUN: | FileCheck -check-prefix BAD_CUDA9 %s
+
+// BAD_CUDA9: GPU arch sm_21 is supported by CUDA versions between 7.0 and 8.0
+
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_20 -c %s 2>&1 \
 // RUN: | FileCheck -check-prefix OK %s
 // RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_52 -c %s 2>&1 \