1. 程式人生 > >【解決】Centos7 安裝NVDIA GPU+TensorFlow-gpu1.5.0

【解決】Centos7 安裝NVDIA GPU+TensorFlow-gpu1.5.0

由於專案需要,需要安裝tensorflow-gpu1.5.0到Centos環境下。

環境介紹:
Centos7
gcc-4.8.5
python3.5

我用的GPU的種類是:GeForce GTX1080 Ti,是英偉達的GeForce系列10的產品。

安裝TensorFlow-GPU版本需要先安裝後GPU。之前的同事已經將gpu安裝完畢,但gpu的驅動和cuda版本都不符合tensorflow-gpu的要求,所以要先解除安裝掉gpu環境。同事安裝的環境是:cuda driver 387,cuda8.0,cudnn6.0

注:TensorFlow-gpu需要cuda9.0,cudnn-7.0版本(本人測試7.1版本不行),並且安裝最新的cuda驅動(至於為什麼要裝最新的,我也不知道)。

背景介紹差不多了,下面開始安裝。

1.解除安裝環境

[[email protected] ~]# pip show tensorflow-gpu
Name: tensorflow-gpu
Version: 1.4.0
Summary: TensorFlow helps the tensors flow
Home-page: https://www.tensorflow.org/
Author: Google Inc.
Author-email: [email protected].com
License: Apache 2.0
Location: /usr/local/lib/python3.5
/site-packages Requires: tensorflow-tensorboard, enum34, wheel, protobuf, numpy, six 解除安裝TensorFlow-gpu [[email protected] ~]# pip3 uninstall tensorflow-gpu 解除安裝cuda8 [[email protected] drive]# /usr/local/cuda-8.0/bin/uninstall_cuda_8.0.pl 解除安裝驅動 [[email protected] drive]# /usr/bin/nvidia-uninstall

2.下載好相應的cuda驅動包,cuda包等:
NVIDIA-Linux-x86_64-390.67.run
下載連結在:https://www.nvidia.cn/Download/index.aspx?lang=cn

cuda_9.2.148_396.37_linux.run
下載連結在:
https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=CentOS&target_version=7&target_type=runfilelocal

cudnn-9.0-linux-x64-v7.solitairetheme8
下載連結在:
https://developer.nvidia.com/rdp/cudnn-archive

3.安裝NVIDI

[root@hadoop1 drive]# ./NVIDIA-Linux-x86_64-390.67.run

4.安裝cuda9

[root@hadoop1 drive]# sh cuda_9.0.176_384.81_linux.run

在安裝的時候會提示需不需要安裝驅動,選no,因為上一步已經安裝了。

安裝完畢後配置環境變數:

export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64\
                                                   ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

5.安裝cudnn9.0

[root@hadoop1 drive]# cp cudnn-9.0-linux-x64-v7.solitairetheme8 cudnn-9.0-linux-x64-v7.tgz
[root@hadoop1 drive]# tar -zxf cudnn-9.0-linux-x64-v7.tgz
[root@hadoop1 cuda]#  cp ./include/* /usr/local/cuda/include
[root@hadoop1 cuda]# cp ./lib64/* /usr/local/cuda/lib64
[root@hadoop1 cuda]# 
chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

筆者一開始裝的是cudnn9.1,裝完後看不出什麼問題,後來執行一個cnn網路的時候,報瞭如下錯誤:

Check failed: 
stream->parent()->GetConvolveAlgorithms( conv_parameters.ShouldIncludeWinogradNonfusedAlgo<T>(), &algorithms)

後來查了一些部落格說是版本問題,就換回來了。

5.安裝TensorFlow-gpu

[root@hadoop1 drive]# 
pip3 install tensorflow_gpu-1.5.0-cp35-cp35m-manylinux1_x86_64.whl

筆者是在離線的情況下裝TensorFlow-gpu的,所以執行這一步的時候,會報缺少依賴的錯誤,這時候就需要我們自己去網上下載相應的依賴並安裝後,之後才來執行這一句命令。

缺少的依賴有:

版本>=absl-py.0.1.6>=tensorflow-tensorboard.1.5.0;>=futures.¬3.1.1

讀者可以自己去網上找,實在找不到的話可以私聊我。有其他問題也可以私聊我。


執行到這一步,TensorFlow-gpu就全部裝好了。接下來就可以利用gpu來跑深度學習的程式碼了。

在裝cuda的時候,是需要關閉nouveau和X服務的,但這裡就不寫出命令了,讀者可以去看其他的部落格,或者看下面的參考文獻。

參考文獻:

【解決】Ubuntu安裝NVIDIA驅動(諮詢NVIDIA工程師的解決方案)
https://blog.csdn.net/u012759136/article/details/53355781