Linux查看CUDAcuDNN版本

  1. # 查看CUDA版本
  2. nvcc -version
  3. nvcc -V
  4. cat /usr/local/cuda/version.txt
  5. # 查看cuDNN版本
  6. cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

使用 PyTorch 查看 CUDA cuDNN 版本

  1. import torch
  2. print(torch.__version__)
  3. print(torch.version.cuda)
  4. print(torch.backends.cudnn.version())

nvidia驱动和cuda版本依赖

https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
CUDA Toolkit and Corresponding Driver Versions

CUDA Toolkit Toolkit Driver Version
Linux x86_64 Driver Version Windows x86_64 Driver Version
CUDA 11.4 Update 1 >=470.57.02 >=471.41
CUDA 11.4.0 GA >=470.42.01 >=471.11
CUDA 11.3.1 Update 1 >=465.19.01 >=465.89
CUDA 11.3.0 GA >=465.19.01 >=465.89
CUDA 11.2.2 Update 2 >=460.32.03 >=461.33
CUDA 11.2.1 Update 1 >=460.32.03 >=461.09
CUDA 11.2.0 GA >=460.27.03 >=460.82
CUDA 11.1.1 Update 1 >=455.32 >=456.81
CUDA 11.1 GA >=455.23 >=456.38
CUDA 11.0.3 Update 1 >= 450.51.06 >= 451.82
CUDA 11.0.2 GA >= 450.51.05 >= 451.48
CUDA 11.0.1 RC >= 450.36.06 >= 451.22
CUDA 10.2.89 >= 440.33 >= 441.22
CUDA 10.1 (10.1.105 general release, and updates) >= 418.39 >= 418.96
CUDA 10.0.130 >= 410.48 >= 411.31
CUDA 9.2 (9.2.148 Update 1) >= 396.37 >= 398.26
CUDA 9.2 (9.2.88) >= 396.26 >= 397.44
CUDA 9.1 (9.1.85) >= 390.46 >= 391.29
CUDA 9.0 (9.0.76) >= 384.81 >= 385.54
CUDA 8.0 (8.0.61 GA2) >= 375.26 >= 376.51
CUDA 8.0 (8.0.44) >= 367.48 >= 369.30
CUDA 7.5 (7.5.16) >= 352.31 >= 353.66
CUDA 7.0 (7.0.28) >= 346.46 >= 347.62

Tensorflow、Cuda、CuDNN版本依赖

GPU:https://tensorflow.google.cn/install/source#tensorflow_2x

版本 Python 版本 编译器 构建工具 cuDNN CUDA
tensorflow-2.6.0 3.6-3.9 GCC 7.3.1 Bazel 3.7.2 8.1 11.2
tensorflow-2.5.0 3.6-3.9 GCC 7.3.1 Bazel 3.7.2 8.1 11.2
tensorflow-2.4.0 3.6-3.8 GCC 7.3.1 Bazel 3.1.0 8.0 11.0
tensorflow-2.3.0 3.5-3.8 GCC 7.3.1 Bazel 3.1.0 7.6 10.1
tensorflow-2.2.0 3.5-3.8 GCC 7.3.1 Bazel 2.0.0 7.6 10.1
tensorflow-2.1.0 2.7、3.5-3.7 GCC 7.3.1 Bazel 0.27.1 7.6 10.1
tensorflow-2.0.0 2.7、3.3-3.7 GCC 7.3.1 Bazel 0.26.1 7.4 10.0
tensorflow_gpu-1.15.0 2.7、3.3-3.7 GCC 7.3.1 Bazel 0.26.1 7.4 10.0
tensorflow_gpu-1.14.0 2.7、3.3-3.7 GCC 4.8 Bazel 0.24.1 7.4 10.0
tensorflow_gpu-1.13.1 2.7、3.3-3.7 GCC 4.8 Bazel 0.19.2 7.4 10.0
tensorflow_gpu-1.12.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.15.0 7 9
tensorflow_gpu-1.11.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.15.0 7 9
tensorflow_gpu-1.10.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.15.0 7 9
tensorflow_gpu-1.9.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.11.0 7 9
tensorflow_gpu-1.8.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.10.0 7 9
tensorflow_gpu-1.7.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.9.0 7 9
tensorflow_gpu-1.6.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.9.0 7 9
tensorflow_gpu-1.5.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.8.0 7 9
tensorflow_gpu-1.4.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.5.4 6 8
tensorflow_gpu-1.3.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.5 6 8
tensorflow_gpu-1.2.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.5 5.1 8
tensorflow_gpu-1.1.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.2 5.1 8
tensorflow_gpu-1.0.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.2 5.1 8

测试GPU可用行的demo
tensorflow 1.x

  1. ####################################### 1.x
  2. from tensorflow.python.client import device_lib
  3. import tensorflow as tf
  4. #检测tensorflow的能使用设备情况:
  5. # print(device_lib.list_local_devices())
  6. #判断CUDA是否可用,如不能用,需要在安装cuda时配置cuda相关环境变量
  7. print(tf.test.is_built_with_cuda())
  8. #判断GPU是否可用:
  9. tf.test.is_gpu_available(
  10. cuda_only=False,
  11. min_cuda_compute_capability=None
  12. )
  13. # 指定gpu设备分别测试,如机器总共有4块gpu,分别为0,1,2,3
  14. # import os
  15. # os.environ["CUDA_VISIBLE_DEVICES"] = "1"
  16. # 执行简单运算,查看gpu报错
  17. import tensorflow as tf
  18. a = tf.constant([1.0, 2.0, 3.0], shape=[3], name='a')
  19. b = tf.constant([1.0, 2.0, 3.0], shape=[3], name='b')
  20. c = a + b
  21. sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
  22. print(sess.run(c))

tensorflow 2.x

  1. ####################################### 2.x
  2. # 判断GPU是否可用
  3. tf.config.list_physical_devices('GPU')
  4. ## out: [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
  5. # 简单的计算 y = wx ,其中 w=2.0, x=5 计算 y
  6. import tensorflow as tf
  7. w = tf.Variable(2.0, dtype=tf.float32)
  8. x = tf.Variable(5.0, dtype=tf.float32)
  9. wx = tf.multiply(w,x) # 乘法
  10. print('Out y tensor:%s'%(wx))
  11. print('Out y numpy value:{yV}'.format(yV=wx.numpy()))
  12. #Out y tensor:tf.Tensor(10.0, shape=(), dtype=float32)
  13. #Out y numpy value:10.0