是否有任何快速命令或脚本来检查安装的CUDA版本?

我在安装目录下找到了4.0的手册,但我不确定它是否是实际安装的版本。


当前回答

通过在终端中键入以下内容,可以获得cuda版本:

$ nvcc -V

# below is the result
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85

或者,可以先使用以下方法查找安装目录,手动检查版本:

$ whereis -b cuda         
cuda: /usr/local/cuda

然后cd到该目录并检查CUDA版本。

其他回答

打开终端并运行以下命令:

cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery

您可以获得CUDA驱动程序版本、CUDA运行时版本的信息,以及GPU的详细信息。我的终端输出的图像示例如下。

您可以在此处找到图像。

在Ubuntu Cuda V8上:

$ cat /usr/local/cuda/version.txt
  

您还可以了解CUDA版本的安装情况:

$ ls -l /usr/local | grep cuda

这会给你这样的东西:

lrwxrwxrwx  1 root root    9 Mar  5  2020 cuda -> cuda-10.2
drwxr-xr-x 16 root root 4096 Mar  5  2020 cuda-10.2
drwxr-xr-x 16 root root 4096 Mar  5  2020 cuda-8.0.61

给定一个正常的PATH,cuda指向的版本应该是活动版本(本例中为10.2)。

注意:只有当您愿意假设CUDA安装在/usr/local/CUDA下时,这才有效(这对于具有默认位置的独立安装程序是正确的,但对于CUDA集成为软件包的发行版则不正确)。参考:@einpoklum的评论。

使用tensorflow:

import tensorflow as tf
from tensorflow.python.platform import build_info as build
print(f"tensorflow version: {tf.__version__}")
print(f"Cuda Version: {build.build_info['cuda_version']}")
print(f"Cudnn version: {build.build_info['cudnn_version']}")

tensorflow版本:2.4.0

Cuda版本:11.0

Cudnn版本:8

您可以使用

nvcc -V

或者你可以使用

nvcc --version

或者您可以检查CUDA使用的位置

whereis cuda 

然后做

cat location/of/cuda/you/got/from/above/command

在以下时间之后找到我的:

whereis cuda

at

cuda:/usr/lib/cuda/usr/include/cuda.h

with

nvcc --version

CUDA版本9.1.85