tensorflow识别不了gpu rtx3080解决方式
用2年前的rtx3080电脑运行深度学习代码,配置:驱动nVidia11.1,cuda11.1.1, cudann=8.0.4, tensorflow=2.4.1,keras=2.4.3.
换了一台3080电脑,运行发现cpu用了100%,但是不用gpu,于是开始排查
step1:判断是否能识别gpu
import tensorflow as tf
print(tf.test.is_gpu_available())
运行结果:
WARNING:tensorflow:From C:\Users\Adimin\.spyder-py3\temp.py:9: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
False
按照提示再来一遍
import tensorflow as tf
print(tf.test.is_gpu_available())
print(tf.config.list_physical_devices('GPU'))
运行结果:
False
[]
经过仔细排查,发现新机器nVidia版本导致和之前运行的机器驱动版本不一样,新机器原始版本11.5,但是cuda,cudann,tf,keras版本没有匹配。开始自动更新驱动29-6-2022版nVidia驱动,经查看nvidia面板应该配cuda11.8,但是最新的cuda是11.7,cudann-2.4.0, tensorflow=2.6.0,但是代码适用的tf版本有限。这个版本运行不了代码。
于是安装nVidia-456.38对应cuda11.1
官网只能显示最近10个,于是按Fn+f12,点console,输入下面代码:
SystemScanner.prototype.DriverSearch = function(psid, pfid, osID, langCode, whql, beta, dltype, numresults ) {numresults=50;this.scannerStatusUpdate(GFE_SERVER_CONNECTING);theScanner.scannedDevice.downloadInfo=new Object();var parameters=‘psid=’+psid;parameters+=’&pfid=’+pfid;parameters+=’&osID=’+osID;parameters+=’&languageCode=’+langCode;parameters+=’&beta=’+beta;parameters+=’&isWHQL=’+whql;parameters+="&dltype="+dltype;parameters+="&sort1=0";parameters+="&numberOfResults="+numresults;var requestUrl=thi
点运行,找到后运行,但是新机器的windows与nVidia不兼容
重新配置新的驱动版本。
后面下载对应的cuda和cudann
https://developer.nvidia.com/rdp/cudnn-downloadhttps://developer.nvidia.com/rdp/cudnn-download
随便找一篇cuda和补丁cudann的安装教程,如下,
https://blog.csdn.net/m0_45447650/article/details/123704930
下面配置tensorflow_gpu
经过千辛万苦,找到了一个可以识别rtx3080并且匹配cuda的版本,python版本3.8以上。
pip install --user tf_nightly_gpu
pip install keras==2.3.0
运行代码:
import tensorflow as tf
import os
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
tf.test.is_built_with_gpu_support()
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
结果:
Num GPUs Available: 1
成功了!
更多推荐
所有评论(0)