ubuntu16.04 cuda cudnn tensorflow

前端之家收集整理的这篇文章主要介绍了ubuntu16.04 cuda cudnn tensorflow前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一. Pip安装:

  1. $ sudo apt-get install python-pip python-dev # for python
$ sudo apt-get install python3-pip python3-dev # for python3

二.安装英伟达显卡驱动

1查看自身版本

  1. lspci | grep -i vga
  2. lspci | grep -i nvidia

去官网上查看适合你GPU的驱动
http://www.nvidia.com/Download/index.aspx?lang=en-us


2安装

对ubuntu16 可通过 系统设置-软件和更新-附加驱动 安装


3

执行完上述后,重启reboot

安装完后再运行

nvidia-smi 来看看 如果出现了你的GPU列表,则说明驱动安装成功了。 另外也可以通过,或者输入nvidia-settings 查看

三.安装cuda

https://developer.nvidia.com/cuda-downloads据其所说方式安装

ubuntu的gcc编译器是5.4.0,然而cuda8.0不支持5.0以上的编译器,因此需要降级,把编译器版本降到4.9:

在terminal中执行


  1. sudo apt-get install gcc-4.9 gcc-5 g++-4.9 g++-5
  2.  
  3. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20
  4.  
  5. sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10
  6.  
  7. sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.9 20
  8.  
  9. sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
  10.  
  11. sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 30
  12.  
  13. sudo update-alternatives --set cc /usr/bin/gcc
  14.  
  15. sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 30
  16.  
  17. sudo update-alternatives --set c++ /usr/bin/g++


配置cuda8.0之后主要加上的一个环境变量声明,

  1. gedit ~/.bashrc

文件~/.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}}


通过命令查看CUDA安装是否成功
  1. cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
  2. sudo make
  3. ./deviceQuery


四.cudnn

https://developer.nvidia.com/cudnn tensorflow1.1 支持cudnnv5.1

下载完cudnn后

  1. cd ~/Downloads/
  2. tar zxvf cudnn-8.0-linux-x64-v5.1.tgz #解压文件
  1. # 复制头文件和lib文件
  2. sudo cp include/cudnn.h /usr/local/cuda/include/
  3. sudo cp lib64/lib* /usr/local/cuda/lib64/
  1. # 进入文件
  2. cd /usr/local/cuda/lib64/
  3. sudo rm -rf libcudnn.so libcudnn.so.5 #删除原有动态文件
  4. # 然后修改文件权限,并创建新的软连接
  5. sudo chmod u=rwx,g=rx,o=rx libcudnn.so.5.1.10 #若这里不修改权限会有如下错误
  6. sudo ln -s libcudnn.so.5.1.5 libcudnn.so.5 #生成软衔接
  7. sudo ln -s libcudnn.so.5 libcudnn.so #生成链接
  1. # 错误
  2. Traceback (most recent call last):
  3. File "<stdin>",line 1,in <module>
  4. ImportError: No module named rensorflow
  5. >>> import tensorflow
  6. Traceback (most recent call last):
  7. File "<stdin>",in <module>
  8. File "/home/yojiu/.local/lib/python2.7/site-packages/tensorflow/__init__.py",line 24,in <module>
  9. from tensorflow.python import *
  10. File "/home/yojiu/.local/lib/python2.7/site-packages/tensorflow/python/__init__.py",line 51,in <module>
  11. from tensorflow.python import pywrap_tensorflow
  12. File "/home/yojiu/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py",line 52,in <module>
  13. raise ImportError(msg)
  14. ImportError: Traceback (most recent call last):
  15. File "/home/yojiu/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow.py",line 41,in <module>
  16. from tensorflow.python.pywrap_tensorflow_internal import *
  17. File "/home/yojiu/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py",line 28,in <module>
  18. _pywrap_tensorflow_internal = swig_import_helper()
  19. File "/home/yojiu/.local/lib/python2.7/site-packages/tensorflow/python/pywrap_tensorflow_internal.py",in swig_import_helper
  20. _mod = imp.load_module('_pywrap_tensorflow_internal',fp,pathname,description)
  21. ImportError: libcudnn.so.5: cannot open shared object file: No such file or directory
  22. Failed to load the native TensorFlow runtime.
  23. See https://www.tensorflow.org/install/install_sources#common_installation_problems
  24. for some common reasons and solutions. Include the entire stack trace
  25. above this error message when asking for help.

五.安装tensorflow

直接配置URL在线 whl 进行安装:

  1. $ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.1.0rc2-cp27-none-linux_x86_64.whl
  2. #或其他网站镜像

猜你在找的Ubuntu相关文章