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

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


当前回答

安装CUDA后,可以通过以下方式检查版本:nvcc-V

我已经安装了5.0和5.5

Cuda编译工具5.5版V5.5,0

此命令适用于Windows和Ubuntu。

其他回答

通过在终端中键入以下内容,可以获得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版本。

在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

在Windows 10上,我在“C:\Program Files\nvidia Corporation\NVSMI”中找到了nvidia-smi.exe;在cd之后插入该文件夹(在我的情况下不在PATH中)和'。\它显示了nvidia smi.exe

正如Jared在命令行的评论中提到的:

nvcc --version

(或/usr/local/cuda/bin/nvcc-version)提供cuda编译器版本(与工具包版本匹配)。

从应用程序代码中,可以使用

cudaRuntimeGetVersion()

或驱动程序API版本

cudaDriverGetVersion()

正如Daniel所指出的那样,deviceQuery是一个SDK示例应用程序,可以查询上面的内容以及设备功能。

正如其他人所指出的,您也可以使用(例如,在Mac或Linux上)检查version.txt的内容

cat /usr/local/cuda/version.txt

但是,如果安装了CUDA工具包的另一个版本,而不是从/usr/local/CUDA符号链接的版本,则如果PATH中的另一版本早于上述版本,则可能会报告版本不准确,因此请谨慎使用。