1. GPU状态查询
在运行之前先查看GPU的使用情况:
$ nvidia-smi # 查看GPU此时的使用情况
或者
$ nvidia-smi -l # 实时返回GPU使用情况
1.1 安装包下载地址
https://developer.nvidia.com/rdp/cudnn-archive#a-collapse712-9
2. 搭建GPU--TensorFlow环境配置
2.1 方法一(较笨,且容易出错)
conda install cudatoolkit=8.0
(1)到网站https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html查看自己系统GPU驱动对应的版本
(2)安装对应的版本
conda install cudatoolkit=10.1
(3)conda install tensorflow-gpu==2.0
conda install tensorflow-gpu==1.7
pip install tensorflow-gpu==2.0
pip install tensorflow==2.0
pip install tensorflow==1.7
pip install tensorflow-gpu==1.9
conda install tensorflow-gpu==1.12.0
2.2 方法二(容易成功)
(1)确保当前环境没有cudnn、cudatoolkit、tensorflow、tensorflow-gpu,若有则卸载。
conda uninstall cudnn
conda uninstall cudatoolkit
conda uninstall tensorflow
(2)直接用命令conda install tensorflow-gpu安装,不要指定版本。
image.png
(3)可以看出,上面安装包cudnn的版本和方法一要求的一致。
3. 测试是否安装成功
tf.test.is_gpu_available()
4.问题解决
4.1 cudnn当前版本为7.3.1 ,而需要时7.0
2019-10-09 15:53:41.825290: E T:\src\github\tensorflow\tensorflow\stream_executor\cuda\cuda_dnn.cc:396] Loaded runtime CuDNN library: 7301 (compatibility version 7300) but source was compiled with 7003 (compatibility version 7000). If using a binary install, upgrade your CuDNN library to match. If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.
2019-10-09 15:53:41.826549: F T:\src\github\tensorflow\tensorflow\core\kernels\conv_ops.cc:712] Check failed: stream->parent()->GetConvolveAlgorithms( conv_parameters.ShouldIncludeWinogradNonfusedAlgo<T>(), &algorithms)
conda install cudnn==7.0 (没找到对应版本)
pip install cudnn==7.0
conda install cudnn==7.3.1
conda install cudnn==7.0.3 (没找到对应版本)
conda install cudnn==7.0.5
但是试图下载cudnn==7.0 版本时,找不到,所以只有把tensorflow-gpu==1.7升级tensorflow-gpu==1.9,问题成功解决。
4.2
2019-10-09 19:06:36.418533: E tensorflow/stream_executor/cuda/cuda_dnn.cc:396] Loaded runtime CuDNN library: 7600 (compatibility version 7600) but source was compiled with 7102 (compatibility version 7100). If using a binary install, upgrade your CuDNN library to match. If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.
2019-10-09 19:06:36.420325: F tensorflow/core/kernels/conv_ops.cc:712] Check failed: stream->parent()->GetConvolveAlgorithms( conv_parameters.ShouldIncludeWinogradNonfusedAlgo<T>(), &algorithms)
Aborted (core dumped)
conda install cudnn==7.1.2 (有对应版本),但是并未解决版本互相冲突的问题。最后卸载重新安装了。
Press CTRL-C to abort.
4.3
Finding shortest conflict path for cudatoolkit[version='>=9.0,<9.1.0a0']
版本冲突,卸载重新安装,详见3.2。
参考资料
使用
[1] 用GPU进行TensorFlow计算加速
[2] tensorflow gpu使用说明
[3] tensorflow(GPU)使用
[4] TensorFlow使用GPU
搭建环境
[1] 【Linux】tensorflow GPU版本的正确配置过程 很好,方法对的
[2] Linux+Anaconda+tensorflow-gpu环境配置很好,方法对的
[3] Tensorflow不同版本要求与CUDA及CUDNN版本对应关系
网友评论