Ubuntu16.04+GTX 1080Ti+CUDA 8.0+cuDNN+Tesnorflow1.0深度學習服務器安裝之路


0.安裝背景


  • 系統:ubuntu 16.04
  • 內核:4.4.0-140-generic
  • GPU:GTX 1080Ti
  • nvidia驅動版本: 384.111
  • cuda: CUDA 8.0
  • 深度學習庫cuDNN: cuDNN5.1
  • tensorflow:1.0.1

1.安裝nvdia顯卡驅動


下載nvidia顯卡驅動

nvidia官網查詢顯卡對應的驅動,並下載。這里的顯卡驅動下載鏈接:Download,密碼:mfxh
下載的時候要注意,顯卡驅動與ubuntu內核版本對應。對應表來自nvidia官網如下:

Distribution Kernel* GCC GLIBC
Ubuntu 18.10 4.18.0 8.2.0 2.28
Ubuntu 18.04.1 (**) 4.15.0 7.3.0 2.27
Ubuntu 16.04.5 (**) 4.4 5.4.0 2.23
Ubuntu 14.04.5 (**) 3.13 4.8.4 2.19

刪除以前nvidia顯卡驅動版本

$ sudo apt-get install --purge nvidia*

關閉自帶nouveau顯卡驅動

$ sudo gedit /etc/modprobe.d/blacklist.conf

在文末添加:blacklist nouveau
執行命令

$ sudo update-initramfs -u

然后重啟機器。執行如下命令,確認一下是否關閉。如果什么都沒顯示,表示已經刪除。

$  lsmod | grep nouveau

安裝nvidia顯卡驅動

ctrl+alt+F1進入tty1控制台,輸入命令:

$ sudo service lightdm stop     //關閉桌面服務
$ cd Downloads/                     //進入下載的驅動所在路徑

/*  安裝顯卡驅動,參數解釋
 *  -no-x-check         關閉x服務器
 *  -no-nouveau-check 關閉自帶顯卡驅動
 *  -no-opengl-files   關閉OpenGl服務,否則會出現重復登錄的情況
 */
$ sudo ./NVIDIA-Linux-x86_64-384.111.run -no-x-check -no-nouveau-check -no-opengl-files 

接下來進入安裝界面,首先要accept證書,后面的選項選擇默認的就好。
查看是否安裝成功:

$ nvidia-smi

如果安裝成功,應該如圖1:

圖1:nvidia驅動安裝成功
###遇到的問題 **1.building kernel moduel** 出現錯誤: ERROR: An error occurred while performing the step: "Building kernel modules". See /var/log/nvidia-installer.log for details. 這是由於ubuntu的內核與nvidia驅動版本不對應,原本我的機器是4.15 安裝 384顯卡驅動,每次都會出現build 的錯誤,后來將內核降為4.4的,並將4.4的內核設置為系統默認內核,於是安裝成功。 **2.重復登錄** 安裝驅動的時候得把opengl關掉,如前文安裝驅動時候的命令。 還有個原因與問題一答案一致,ubuntu的內核與nvidia驅動版本不對應。所以建議安裝驅動后,將ubuntu內核版本自動更新關閉掉,否則內核自動更新了,nvidia並沒有自動更新,會導致ubuntu系統重復登錄。

2.安裝cuda


版本對應

版本 Python版本 編譯器 CUDA最低版本 cuDNN最低版本
tensorflow_gpu-1.13.0 2.7、 3.3~3.6 4.8 10.0 7.4
tensorflow_gpu-1.5.0 ~1.12.0 2.7、 3.3~3.6 4.8 9 7
tensorflow_gpu-1.3.0 ~1.3.0 2.7、 3.3~3.6 4.8 8 6
tensorflow_gpu-1.0.0 ~1.2.0 2.7、 3.3~3.6 4.8 8 5.1

下載cuda toolkit 8.0

進入官網下載cuda toolkit 8.0(或者直接google cuda 8.0可以直接進入),選擇電腦配置對應的版本,選擇runfile類型的文件,如圖2。

圖2:cuda下載

下載成功后,執行命令:

$ sudo sh cuda_8.0.61_375.26_linux.run 

然后進入安裝,一開始出現的一大堆文字都是End User License Agreement,可以ctrl+c跳過,在隨后的協議選擇accept協議。注意,在Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?選擇no,因為我們已經安裝過nvidia驅動了。
具體選項如下:

Logging to /tmp/cuda_install_32359.log
Using more to view the EULA.
End User License Agreement
--------------------------


Preface
-------

The following contains specific license terms and conditions
for four separate NVIDIA products. By accepting this
agreement, you agree to comply with all the terms and
conditions applicable to the specific product(s) included
herein.


NVIDIA CUDA Toolkit


Description

The NVIDIA CUDA Toolkit provides command-line and graphical
tools for building, debugging and optimizing the performance
of applications accelerated by NVIDIA GPUs, runtime and math
libraries, and documentation including programming guides,
--More--(0%)

Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
(y)es/(n)o/(q)uit: n

Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y

Enter Toolkit Location
 [ default is /usr/local/cuda-8.0 ]: 

Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y

Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y

Enter CUDA Samples Location
 [ default is /home/ai]: 

Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...

Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/ai ...

Copying samples to /home/kinny/NVIDIA_CUDA-8.0_Samples now...

Finished copying samples.

配置環境

在~/.bashrc 的最后添加:

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

添加完一定要更新一下,否則會出現安裝成功但是無法使用gpu的情況。

$ source ~/.bashrc

3.安裝cudnn


進入官網下載cuda toolkit 5.1,需要注冊才能使用。下載對應的文件,我這里的下載選項為Download cuDNN v5.1 (Jan 20, 2017), for CUDA 8.0,下載下來的文件名為cudnn-8.0-linux-x64-v5.1.tgz。
解壓文件

$ tar xvzf cudnn-8.0-linux-x64-v5.1.tgz

然后將庫和頭文件copy到cuda目錄(一定是你自己安裝的目錄如/usr/local/cuda-8.0):

$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64

接下來修改文件的訪問權限

$ sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

4.安裝tensorflow-gpu


下載tensorflow-gpu

這里安裝的是tensorflow1.0.1-gpu,下載鏈接:Download

下載pip

$ sudo apt-get install python-pip python-dev

使用pip安裝tensorflow

$ sudo pip install --upgrade ttensorflow_gpu-1.0.1-cp27-none-linux_x86_64.whl

遇到的問題

1.tensorflow import error

圖3:Import Error
這里是由於沒有配置上文cuda環境導致的。 #參考 [1] https://blog.ailemon.me/2017/06/06/install-tensorflow-gpu-on-ubuntu-linux/ [2] https://blog.csdn.net/weiguangbanmo/article/details/83386715


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM