Ubuntu 16.06 Tensorflow 1.4 GPU版本傻瓜安裝教程

Tensorflow 1.4 GPU版本安裝

系統環境

  1. Ubuntu 16.04
  2. NVIDIA GF 660

安裝流程

  1. 安裝 CUDA 8
  2. 安裝 cuDNN 6
  3. 安裝 Tensorflow GPU版本

安裝 CUDA 8

不要安裝 CUDA 9
不要安裝 CUDA 9
不要安裝 CUDA 9
目前Tensorfllow 1.4版本還不支持使用CUDA 9, 應該1.5 版本之後才支持

官方安裝文檔是安裝CUDA 9的,不過對CUDA 8適用

1. 檢查自己GPU是否支持CUDA

$ lspci | grep -i nvidia

01:00.0 VGA compatible controller: NVIDIA Corporation GK106 [GeForce GTX 660] (rev a1)
01:00.1 Audio device: NVIDIA Corporation GK106 HDMI Audio Controller (rev a1)

這裏 查看自己的GPU是否支持CUDA, 基本上 GF 5xx 以後都是支持的

2. 下載 CUDA 8

CUDA Toolkit 8.0 - Feb 2017
這裏寫圖片描述

3. 安裝 CUDA 8

  1. sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-ga2_8.0.61-1_amd64.deb
  2. sudo apt-get update
  3. sudo apt-get install cuda
  4. sudo dpkg -i cuda-repo-ubuntu1604-8-0-local-cublas-performance-update_8.0.61-1_amd64.deb
  5. sudo apt-get update
  6. sudo apt-get upgrade

4. 驗證 CUDA 8 是否安裝成功

  1. $ cd /usr/local/cuda-8.0/samples
  2. $ sudo make
  3. $ cd bin/x86_64/linux/release/
  4. $ ./deviceQuery
    輸出下面內容
./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 660"
  CUDA Driver Version / Runtime Version          9.0 / 8.0
  CUDA Capability Major/Minor version number:    3.0
  Total amount of global memory:                 1998 MBytes (2094923776 bytes)
  ( 5) Multiprocessors, (192) CUDA Cores/MP:     960 CUDA Cores
  GPU Max Clock rate:                            1032 MHz (1.03 GHz)
  Memory Clock rate:                             3004 Mhz
  Memory Bus Width:                              192-bit
  L2 Cache Size:                                 393216 bytes
  Maximum Texture Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536), 3D=(4096, 4096, 4096)
  Maximum Layered 1D Texture Size, (num) layers  1D=(16384), 2048 layers
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 9.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 660
Result = PASS

重點看: Device 0: "GeForce GTX 660" 這是是否正確, 還有最後一行 Result = PASS

5. 設置環境變量

  1. $ gedit ~/.bashrc
  2. 添加 export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
  3. 如果是64位系統添加

    export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64\
                         ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  4. 如果是32位系統添加

    export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib\
                         ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
  5. $ source ~/.bashrc

安裝 cuDNN 6

地址: https://developer.nvidia.com/deep-learning
1. 需要註冊一個賬號(免費) 登錄賬號
2. 下載地址 https://developer.nvidia.com/rdp/cudnn-download
3. 同意協議
4. 選擇下面
這裏寫圖片描述

  1. $ sudo dpkg -i libcudnn6_6.0.21-1+cuda8.0_amd64.deb
  2. $ sudo dpkg -i libcudnn6-dev_6.0.21-1+cuda8.0_amd64.deb

安裝 Tensorflow

$ pip3 install tensorflow-gpu

驗證Tensorflow安裝成功

# Python3
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章