From ae2ecba319e91dbefe5096943ca96afe4d7572a7 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Wed, 25 Oct 2017 21:32:06 +0000 Subject: [PATCH] [CUDA] Print an error if you try to compile with < sm_30 on CUDA 9. 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 --- include/clang/Basic/Cuda.h | 4 ++++ include/clang/Basic/DiagnosticDriverKinds.td | 7 ++++--- lib/Basic/Cuda.cpp | 12 ++++++++++++ lib/Driver/ToolChains/Cuda.cpp | 16 +++++++++------- lib/Driver/ToolChains/Cuda.h | 2 +- .../Inputs/CUDA_90/usr/local/cuda/bin/.keep | 0 .../Inputs/CUDA_90/usr/local/cuda/include/.keep | 0 .../Inputs/CUDA_90/usr/local/cuda/lib/.keep | 0 .../Inputs/CUDA_90/usr/local/cuda/lib64/.keep | 0 .../local/cuda/nvvm/libdevice/libdevice.10.bc | 0 .../Inputs/CUDA_90/usr/local/cuda/version.txt | 1 + test/Driver/cuda-bad-arch.cu | 6 ++++++ 12 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 test/Driver/Inputs/CUDA_90/usr/local/cuda/bin/.keep create mode 100644 test/Driver/Inputs/CUDA_90/usr/local/cuda/include/.keep create mode 100644 test/Driver/Inputs/CUDA_90/usr/local/cuda/lib/.keep create mode 100644 test/Driver/Inputs/CUDA_90/usr/local/cuda/lib64/.keep create mode 100644 test/Driver/Inputs/CUDA_90/usr/local/cuda/nvvm/libdevice/libdevice.10.bc create mode 100644 test/Driver/Inputs/CUDA_90/usr/local/cuda/version.txt diff --git a/include/clang/Basic/Cuda.h b/include/clang/Basic/Cuda.h index b273365975..1a0731c37a 100644 --- a/include/clang/Basic/Cuda.h +++ b/include/clang/Basic/Cuda.h @@ -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 diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 67472a5964..dd72c958d1 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -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< diff --git a/lib/Basic/Cuda.cpp b/lib/Basic/Cuda.cpp index 3a5297b0c6..58b99a3b58 100644 --- a/lib/Basic/Cuda.cpp +++ b/lib/Basic/Cuda.cpp @@ -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 diff --git a/lib/Driver/ToolChains/Cuda.cpp b/lib/Driver/ToolChains/Cuda.cpp index 4f740fc952..44ec16e8b8 100644 --- a/lib/Driver/ToolChains/Cuda.cpp +++ b/lib/Driver/ToolChains/Cuda.cpp @@ -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); } } diff --git a/lib/Driver/ToolChains/Cuda.h b/lib/Driver/ToolChains/Cuda.h index 1e30aa7270..414c9445c7 100644 --- a/lib/Driver/ToolChains/Cuda.h +++ b/lib/Driver/ToolChains/Cuda.h @@ -40,7 +40,7 @@ private: // CUDA architectures for which we have raised an error in // CheckCudaVersionSupportsArch. - mutable llvm::SmallSet ArchsWithVersionTooLowErrors; + mutable llvm::SmallSet 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 index 0000000000..e69de29bb2 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 index 0000000000..e69de29bb2 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 index 0000000000..e69de29bb2 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 index 0000000000..e69de29bb2 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 index 0000000000..e69de29bb2 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 index 0000000000..24e1fd4ece --- /dev/null +++ b/test/Driver/Inputs/CUDA_90/usr/local/cuda/version.txt @@ -0,0 +1 @@ +CUDA Version 9.0.103 diff --git a/test/Driver/cuda-bad-arch.cu b/test/Driver/cuda-bad-arch.cu index cbc2d11f90..a6559b0c78 100644 --- a/test/Driver/cuda-bad-arch.cu +++ b/test/Driver/cuda-bad-arch.cu @@ -12,6 +12,12 @@ // 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 \ -- 2.40.0