Skip to content

Commit d50044e

Browse files
Artem-Btstellar
authored andcommitted
[CUDA] Improve clang's ability to detect recent CUDA versions.
CUDA-11.1 does not carry version.txt which causes clang to assume that it's CUDA-7.0, which used to be the only CUDA version w/o version.txt. In order to tell CUDA-7.0 apart from the new versions, clang now probes for the presence of libdevice.10.bc which is not present in the old CUDA versions. This should keep Clang working for CUDA-11.1. PR47332: https://bugs.llvm.org/show_bug.cgi?id=47332 Differential Revision: https://reviews.llvm.org/D89752 (cherry picked from commit 65d2064)
1 parent 0874e7e commit d50044e

File tree

7 files changed

+14
-4
lines changed

7 files changed

+14
-4
lines changed

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,14 @@ CudaInstallationDetector::CudaInstallationDetector(
155155
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> VersionFile =
156156
FS.getBufferForFile(InstallPath + "/version.txt");
157157
if (!VersionFile) {
158-
// CUDA 7.0 doesn't have a version.txt, so guess that's our version if
159-
// version.txt isn't present.
160-
Version = CudaVersion::CUDA_70;
158+
// CUDA 7.0 and CUDA 11.1+ do not have version.txt file.
159+
// Use libdevice file to distinguish 7.0 from the new versions.
160+
if (FS.exists(LibDevicePath + "/libdevice.10.bc")) {
161+
Version = CudaVersion::LATEST;
162+
DetectedVersionIsNotSupported = Version > CudaVersion::LATEST_SUPPORTED;
163+
} else {
164+
Version = CudaVersion::CUDA_70;
165+
}
161166
} else {
162167
ParseCudaVersionFile((*VersionFile)->getBuffer());
163168
}

clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/bin/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/include/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/lib64/.keep

Whitespace-only changes.

clang/test/Driver/Inputs/CUDA_111/usr/local/cuda/nvvm/libdevice/libdevice.10.bc

Whitespace-only changes.

clang/test/Driver/cuda-version-check.cu

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
// RUN: FileCheck %s --check-prefix=OK
1111
// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA-unknown/usr/local/cuda 2>&1 %s | \
1212
// RUN: FileCheck %s --check-prefix=UNKNOWN_VERSION
13+
// CUDA versions after 11.0 (update 1) do not carry version.txt file. Make sure
14+
// we still detect them as a new version and handle them the same as we handle
15+
// other new CUDA versions.
16+
// RUN: %clang --target=x86_64-linux -v -### --cuda-gpu-arch=sm_60 --cuda-path=%S/Inputs/CUDA_111/usr/local/cuda 2>&1 %s | \
17+
// RUN: FileCheck %s --check-prefix=UNKNOWN_VERSION
1318
// Make sure that we don't warn about CUDA version during C++ compilation.
1419
// RUN: %clang --target=x86_64-linux -v -### -x c++ --cuda-gpu-arch=sm_60 \
1520
// RUN: --cuda-path=%S/Inputs/CUDA-unknown/usr/local/cuda 2>&1 %s | \
@@ -65,5 +70,5 @@
6570
// ERR_SM61: error: GPU arch sm_61 {{.*}}
6671
// ERR_SM61-NOT: error: GPU arch sm_61
6772

68-
// UNKNOWN_VERSION: Unknown CUDA version 999.999. Assuming the latest supported version
73+
// UNKNOWN_VERSION: Unknown CUDA version {{.*}}. Assuming the latest supported version
6974
// UNKNOWN_VERSION_CXX-NOT: Unknown CUDA version

0 commit comments

Comments
 (0)