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

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


当前回答

使用CUDA运行时API C++包装器编程(注意:我是作者):

auto v1 = cuda::version::maximum_supported_by_driver();
auto v2 = cuda::version::runtime();

这为您提供了一个cuda::version_t结构,您可以对其进行比较,也可以打印/流式传输,例如:

if (v2 < cuda::version_t{ 8, 0 } ) {
    std::cerr << "CUDA version " << v2 << " is insufficient." std::endl;
}

其他回答

使用CUDA运行时API C++包装器编程(注意:我是作者):

auto v1 = cuda::version::maximum_supported_by_driver();
auto v2 = cuda::version::runtime();

这为您提供了一个cuda::version_t结构,您可以对其进行比较,也可以打印/流式传输,例如:

if (v2 < cuda::version_t{ 8, 0 } ) {
    std::cerr << "CUDA version " << v2 << " is insufficient." std::endl;
}

除了上面提到的那些,CUDA安装路径(如果在安装过程中没有更改)通常包含版本号

执行哪个nvcc应该提供路径,这将为您提供版本

PS:这是一种快速而肮脏的方式,上面的答案更优雅,并将通过相当大的努力产生正确的版本

如果安装了多个CUDA,则系统中加载的CUDA是与“nvcc”关联的CUDA。因此,“nvcc--version”显示了您想要的内容。

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

import torch

print(torch.version.cuda)

使用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