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

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


当前回答

如果您安装了PyTorch,只需在IDE中运行以下代码:

import torch

print(torch.version.cuda)

其他回答

如果您已安装CUDA SDK,则可以运行“deviceQuery”查看CUDA的版本

如果nvcc--版本不适合您,请使用cat/usr/local/cuda/version.txt

使用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和nvidia-smi之间存在版本不匹配,则使用不同版本的cuda作为驱动程序和运行时环境。

为了确保使用相同版本的CUDA驱动程序,您需要做的是在系统路径上获取CUDA。

首先运行cuda所在的位置,找到cuda驱动程序的位置。

然后转到.bashrc并修改路径变量,并使用变量“LD_LIBRARY_path”设置搜索的目录优先顺序。

例如

$ whereis cuda
cuda: /usr/lib/cuda /usr/include/cuda.h /usr/local/cuda

CUDA安装在/usr/local/CUDA,现在我们需要将路径变量添加到.bashrc,如下所示:

vim  ~/.bashrc
export PATH="/usr/local/cuda/bin:${PATH}"

在该行之后,将目录搜索路径设置为:

export LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}"

然后保存.bashrc文件。并将其刷新为:

$ source ~/.bashrc

这将确保您有nvcc-V和nvidia-smi使用相同版本的驱动程序。

我们有三种方法来检查版本:在我的案例中,以下是输出:-方式1:-

cat /usr/local/cuda/version.txt

输出:-

CUDA Version 10.1.243

途径2:-

nvcc --version

输出:-

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

途径3:-

/usr/local/cuda/bin/nvcc --version

输出:-

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Sun_Jul_28_19:07:16_PDT_2019
Cuda compilation tools, release 10.1, V10.1.243

途径4:-

nvidia-smi
NVIDIA-SMI 450.36.06    Driver Version: 450.36.06    CUDA Version: 11.0

输出不相同。不知道为什么会这样。