Ubuntu 16.04安装配置TensorFlow GPU

requirements

  • Ubuntu 16.04
  • python 2.7
  • Flask
  • tensorflow GPU 版本

安装nvidia driver

经过不断踩坑的安装,终于google到了靠谱的方法,首先检查你的NVIDIA VGA card model

sudo lshw -numeric -C display

NVIDIA-DISPLAYCARD
可以看到你的显卡信息,比如我的就是 product: GM107M [GeForce GTX 950M] [10DE:139A],然后去NVDIA driver search page搜索你的显卡需要的驱动型号,页面如下: 
gtx-search

下面是我的电脑对应的驱动版本

 
  1. LINUX X64 (AMD64/EM64T) DISPLAY DRIVER

  2.  
  3. Version: 375.20

  4. Release Date: 2016.11.18

  5. Operating System: Linux 64-bit

  6. Language: English (US)

  7. File Size: 72.37 MB

从搜索的结果页面看到,我的驱动版本应该是375.20,为了再次确认一遍,你还可以使用这个命令查看你可以使用的驱动:

ubuntu-drivers devices

结果显示和搜索到的驱动版本一样,推荐也是375

 
  1. == /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==

  2. vendor : NVIDIA Corporation

  3. model : GM107M [GeForce GTX 950M]

  4. modalias : pci:v000010DEd0000139Asv000017AAsd0000380Bbc03sc02i00

  5. driver : nvidia-367 - third-party free

  6. driver : nvidia-375 - third-party free recommended

  7. driver : nvidia-364 - third-party free

  8. driver : nvidia-358 - third-party free

  9. driver : xserver-xorg-video-nouveau - distro free builtin

  10. driver : nvidia-370 - third-party free

  11.  
  12. == cpu-microcode.py ==

  13. driver : intel-microcode - distro non-free

好了,终于可以安装对应的驱动了,使用以下命令

 
  1. version: 375

  2. sudo apt-get install nvidia-375

  3. //你自己的版本

  4. //version : xxx

  5. //sudo apt-get install nvidia-xxx

什么,安装很慢,找不到包?更换一下软件源,这个自己google怎么更换,最简单的就是图形界面里面找到System->settings->Software&Updates,然后换一下源,比如阿里云或者中科大(我突然不能链接中科大镜像了,真实坑),然后再执行一下命令

 
  1. sudo apt-get install mesa-common-dev

  2. sudo apt-get install freeglut3-dev

安装完成之后,重启电脑,驱动应该就完成了!你可以在dashboard上搜索nvidia,看到像 NVIDIA X Server Settings的东西,就说明安装驱动成功了,接下来就是安装cuda8了 
NVIDIA-DashBoard
NVIDIA X Server Settings

安装cuda8

首先也是去下载cuda toolkit 8.0,可以自己注册一个账号。 
CUDA8
一定要选择runfile.下载完成之后,执行

sudo sh cuda_8.0.44_linux.run --override

然后就进入安装过程,开始都是End User License Agreement,你可以CTRL +C 跳过,然后accept,下面就是安装的交互界面,开始的Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?选择n,因为你已经安装驱动了。

 
  1. Using more to view the EULA.

  2. End User License Agreement

  3. --------------------------

  4.  
  5.  
  6. Preface

  7. -------

  8.  
  9. The following contains specific license terms and conditions

  10. for four separate NVIDIA products. By accepting this

  11. agreement, you agree to comply with all the terms and

  12. conditions applicable to the specific product(s) included

  13. herein.

  14.  
  15.  
  16. NVIDIA CUDA Toolkit

  17.  
  18.  
  19. Description

  20.  
  21. The NVIDIA CUDA Toolkit provides command-line and graphical

  22. tools for building, debugging and optimizing the performance

  23. of applications accelerated by NVIDIA GPUs, runtime and math

  24. libraries, and documentation including programming guides,

  25. user manuals, and API references. The NVIDIA CUDA Toolkit

  26. License Agreement is available in Chapter 1.

  27.  
  28.  
  29. Default Install Location of CUDA Toolkit

  30.  
  31. Windows platform:

  32.  
  33. Do you accept the previously read EULA?

  34. accept/decline/quit: accept

  35.  
  36. Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?

  37. (y)es/(n)o/(q)uit: n

  38.  
  39. Install the CUDA 8.0 Toolkit?

  40. (y)es/(n)o/(q)uit: y

  41.  
  42. Enter Toolkit Location

  43. [ default is /usr/local/cuda-8.0 ]:

  44.  
  45. Do you want to install a symbolic link at /usr/local/cuda?

  46. (y)es/(n)o/(q)uit: y

  47.  
  48. Install the CUDA 8.0 Samples?

  49. (y)es/(n)o/(q)uit: y

  50.  
  51. Enter CUDA Samples Location

  52. [ default is /home/kinny ]:

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

  55. Missing recommended library: libXmu.so

  56.  
  57. Installing the CUDA Samples in /home/kinny ...

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

  59. Finished copying samples.

  60.  
  61. ===========

  62. = Summary =

  63. ===========

  64. https://www.douban.com/photos/album/1674185687/
  65. https://www.douban.com/photos/album/1674185687/
  66. Driver: Not Selected

  67. Toolkit: Installed in /usr/local/cuda-8.0

  68. Samples: Installed in /home/kinny, but missing recommended libraries

  69.  
  70. Please make sure that

  71. - PATH includes /usr/local/cuda-8.0/bin

  72. - LD_LIBRARY_PATH includes /usr/local/cuda-8.0/lib64, or, add /usr/local/cuda-8.0/lib64 to /etc/ld.so.conf and run ldconfig as root

  73.  
  74. To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-8.0/bin

  75.  
  76. Please see CUDA_Installation_Guide_Linux.pdf in /usr/local/cuda-8.0/doc/pdf for detailed information on setting up CUDA.

  77.  
  78. ***WARNING: Incomplete installation! This installation did not install the CUDA Driver. A driver of version at least 361.00 is required for CUDA 8.0 functionality to work.

  79. To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:

  80. sudo <CudaInstaller>.run -silent -driver

  81.  
  82. Logfile is /tmp/cuda_install_17494.log

配置cuda环境变量

 
  1. export PATH="$PATH:/usr/local/cuda-8.0/bin"

  2. export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64"

  3.  
  4. nvidia-smi

结果出现以下输出,说明配置成功 
nvidia-smi

安装深��学习库cuDNN

首先下载cuDNN5.1,直接下载是非常慢的,必须走代理,我用的是终端下载的方法,注意前提是你已经注册为开发者了!

 
  1. proxychains wget https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v5.1/prod/8.0/cudnn-8.0-linux-x64-v5.1-tgz

  2. 这个会被forbidden,因为没有认证,开发者需要认证才能下载,你先用chrome下载,然后到show all里面去copy真实的下载地址

  3. proxychains wget http://developer.download.nvidia.com/compute/machine-learning/cudnn/secure/v5.1/prod/8.0/cudnn-8.0-linux-x64-v5.1.tgz?autho=1479703345_7fbb517b03361780b45a2c43277bb9ac&file=cudnn-8.0-linux-x64-v5.1.tgz

  4. 这次成功了!!速度还可以!不过下载下来的文件名字有问题,修改成cudnn-8.0-linux-x64-v5.1.tgz就可以了

  5.  
  6. 然后是解压

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

  8. 然后将库和头文件copy到cuda目录(一定是你自己安装的目录如/usr/local/cuda-8.0),不过正确安装的话,ubuntu一般就会有软链接/usr/local/cuda -> /usr/local/cuda-8.0/

  9. sudo cp cuda/include/cudnn.h /usr/local/cuda/include

  10. sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64

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

安装tensorflow gpu enable python 2.7 版本,详见官网

 
  1. export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl

  2. sudo pip install --upgrade $TF_BINARY_URL

  3.  
  4. 验证

  5. $python

  6. Python 2.7.12 (default, Jul 1 2016, 15:12:24)

  7. [GCC 5.4.0 20160609] on linux2

  8. Type "help", "copyright", "credits" or "license" for more information.

  9. >>> import tensorflow

  10. https://www.douban.com/photos/album/1674185792/

  11. https://www.douban.com/photos/album/1674185792/

  12. I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally

  13. I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally

  14. I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally

  15. I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally

  16. I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally

  17. >>> quit()

  18.  

猜你喜欢

转载自blog.csdn.net/qq_38459897/article/details/81479658