根据显卡型号选择CUDA和cuDNN进行TensorFlow GPU版本安装

37 篇文章 1 订阅

此文章默认显卡支持CUDA和已安装显卡驱动,貌似目前只有英伟达的显卡支持CUDA。

本人显卡为GTX1660,需要的CUDA和cuDNN已打包好(hyfi),其余请自行下载

绿色软件 GPU-Z 可直接检测显卡,下载链接(os41)




查看显卡支持的 CUDA 版本

  1. 先在官网查显卡的算力(Compute Capability),如 RTX 3060 为 8.6
  2. 再查该算力支持的 CUDA SDK,如 8.6 支持的 CUDA SDK 为 11.1 - 11.4(建议 RTX 3060 装 11.1)




一、显卡型号

桌面右键→NVIDIA控制面板→帮助→系统信息

在这里插入图片描述
显卡型号为GTX 1660

若桌面右键无NVIDIA控制面板,查看参考文献




二、CUDA

  1. 查找显卡对应的CUDA版本:接着上一步→组件
    在这里插入图片描述
    显卡GTX 1660对应的CUDA版本为CUDA 10.1,可以选低一个版本,如CUDA 10.0

  2. 下载CUDA Toolkit
    在这里插入图片描述

  3. 安装,环境变量自动配上
    在这里插入图片描述

  4. 命令行输入nvcc -V
    在这里插入图片描述




三、cuDNN

  1. 根据CUDA版本下载cuDNN(需登录),关键是CUDA版本,cuDNN版本选新的
    在这里插入图片描述
  2. 下载得到压缩包,解压后将三个文件夹粘贴到CUDA
    在这里插入图片描述




四、tensorflow-gpu

  1. 查看版本右上角Language设为English,拉到最下面
    CUDA 10.0+cuDNN 7.6.1,装tensorflow-gpu 1.14.0
    在这里插入图片描述
  2. 安装
pip install tensorflow-gpu==1.14.0
  1. 测试代码
import tensorflow as tf

a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print(sess.run(c))

出现此结果证明使用的是GPU运行

a: (Const): /job:localhost/replica:0/task:0/device:GPU:0
b: (Const): /job:localhost/replica:0/task:0/device:GPU:0
[[22. 28.]
 [49. 64.]]

若为tensorflow2,测试代码

import tensorflow as tf

try:
    with tf.device('/device:GPU:0'):
        v = tf.Variable(tf.zeros([10, 10]))
        print(v)
except:
    print('no gpu')




五、查看显卡利用率

  1. 配置环境变量Path:C:\Program Files\NVIDIA Corporation\NVSMI\
    在这里插入图片描述
  2. 查看显卡利用率
    简单查看:nvidia-smi
    每秒刷新:nvidia-smi -l 1




Linux系统

默认已安装 CUDA 和 cuDNN

1. 查看显卡型号

nvidia-smi


2. 查看CUDA版本

cat /usr/local/cuda/version.txt


3. 查看cuDNN版本

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2


4. 选择对应版本安装

pip install tensorflow-gpu==2.3.0




Linux下Anaconda

在 Linux 下基本没有 root 权限,通过 conda 命令安装不同版本的 CUDA 和 cuDNN

1. 查看显卡驱动版本

cat /proc/driver/nvidia/version


根据 CUDA和最低要求驱动 最高可安装 CUDA 10.1

2. 创建虚拟环境

conda create -n deep2 python=3.6

3. 激活虚拟环境

conda activate deep2

4. 安装CUDA

conda install cudatoolkit=10.1

5. 安装cuDNN

conda install -c conda-forge cudnn

6. 查看CUDA版本

conda list cudatoolkit

7. 查看cuDNN版本

conda list cudnn

8. 选择对应版本安装

pip install tensorflow-gpu==2.3.0




参考文献

  1. 如何检查显卡支持哪个版本的CUDA
  2. NVIDIA-SMI系列命令总结
  3. tensorflow各个版本的CUDA以及Cudnn版本对应关系
  4. WIN10 + GTX1660Ti配置TensorFlow GPU版本
  5. TensorFlow2.0教程-Variables
  6. Linux 和 Windows 查看 CUDA 和 cuDNN 版本
  7. Ubuntu安装cuda和cudnn及测试方法
  8. Cudnn :: Anaconda.org
  9. CUDA - Wikipedia
  10. CUDA GPUs - Compute Capability
  11. CUDA Compatibility :: NVIDIA Data Center GPU Driver Documentation
### 回答1: 下面是CUDATensorFlow版本之间的对应关系: | TensorFlow版本 | CUDA支持的版本 | |----------------|---------------| | 2.5.x | 11.2 | | 2.4.x | 11.0 | | 2.3.x | 10.1 | | 2.2.x | 10.1 | | 2.1.x | 10.0 | | 2.0.x | 10.0 | | 1.15.x | 10.0 | | 1.14.x | 10.0 | | 1.13.x | 9.0 | | 1.12.x | 9.0 | | 1.11.x | 9.0 | | 1.10.x | 9.0 | | 1.9.x | 9.0 | | 1.8.x | 9.0 | 需要注意的是,除了CUDA版本外,还需要安装与所选TensorFlow版本相对应的cuDNN版本。在选择TensorFlow版本之前,请先确认您的CUDA版本和系统支持的CUDA版本是否匹配。 ### 回答2: CUDATensorFlow是两个不同的软件,但它们有一些关联和依赖。CUDA是由NVIDIA开发的一种并行计算平台和编程模型,可用于利用GPU进行高性能计算。而TensorFlow则是一个由Google开发的开源机器学习框架,可以用于深度学习和其他机器学习应用。 为了让TensorFlow能够最大化地使用GPU计算能力,需要安装CUDA相应版本兼容的TensorFlow。这是因为TensorFlow使用CUDA作为GPU的计算平台,并且需要与CUDA相应版本匹配的CUDA Toolkit和cuDNN库。如果TensorFlowCUDA版本不兼容,将导致无法运行代码或者GPU性能不佳。 查看TensorFlowCUDA版本兼容性,可以在TensorFlow官网上找到相关信息。例如,TensorFlow 2.6版本可以与CUDA 11.2和cuDNN 8.1.0配合使用。这意味着,为了在机器上成功运行TensorFlow 2.6,需要先安装CUDA 11.2和cuDNN 8.1.0。其他TensorFlow版本可能需要与其他版本CUDAcuDNN兼容,可参考TensorFlow官网或者TensorFlow安装文档中的版本兼容性列表。 总之,为了确保良好的TensorFlow性能和可靠性,需要安装TensorFlow版本相应的CUDAcuDNN。在安装前,应该先了解TensorFlowCUDA版本的兼容性,以便正确选择CUDAcuDNN版本。 ### 回答3: CUDATensorFlow版本是密切相关的。CUDA是一种由NVIDIA开发的基于GPU的并行计算平台和编程模型,而TensorFlow则是由谷歌开发的机器学习框架,能够实现深度学习任务。 当使用TensorFlow进行深度学习训练时,需要考虑安装与操作系统和GPU兼容的版本CUDAcuDNN软件包。这是因为TensorFlow使用GPU加速来更快地进行数学运算,而CUDAcuDNN是实现GPU加速的必备软件包。 TensorFlow版本CUDA版本的对应关系如下: TensorFlow 1.x版本: - TensorFlow 1.15支持CUDA 10.0/cuDNN 7.4.1 - TensorFlow 1.14支持CUDA 10.0/cuDNN 7.4 - TensorFlow 1.13支持CUDA 10.0/cuDNN 7.3 - TensorFlow 1.12支持CUDA 9.0/cuDNN 7.1.4 - TensorFlow 1.11支持CUDA 9.0/cuDNN 7.1.4 - TensorFlow 1.10支持CUDA 9.0 - TensorFlow 1.9支持CUDA 9.0 - TensorFlow 1.8支持CUDA 9.0 - TensorFlow 1.7支持CUDA 9.0 - TensorFlow 1.6支持CUDA 9.0 TensorFlow2.x版本: - TensorFlow 2.2支持CUDA 10.1/cuDNN 7.6 - TensorFlow 2.1支持CUDA 10.1/cuDNN 7.6 - TensorFlow 2.0支持CUDA 10.0 需要注意的是,不同版本CUDATensorFlow可能会导致不同的兼容性问题,因此确保选择兼容版本非常重要。同时,也需要确保安装CUDAcuDNN版本安装显卡类型和操作系统版本相匹配。如果不确定如何安装选择正确的版本,请查看相关文档或咨询相关的技术支持人员。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XerCis

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值