默认系统装的是Ubuntu 16.04,并且安装了显卡驱动。
走过很多坑,这些软件之间是互相依赖的,所以我们只安装这些固定的版本。
CUDA 9.0 cuDNN 7.0 tensorflow-gpu 1.8.0 希望以后会更容易安装些。
如果不是这篇文章写了很久,就照着这篇文章做,不要试图去安装这里涉及软件的最新版本。
第一步先安装 CUDA 9.0。这个并不是官方默认最新的。
下载地址留在这里,方便下载。
下载地址 https://developer.nvidia.com/cuda-90-download-archive
选在合适自己的CUDA
我们选择 Linux - x86_64-Ubuntu-16.04-deb(local) 的方式安装
点击下载 大概有1.2GB,后面还带有几个Patch,我先不下。
cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu1604-9-0-local_9.0.176-1_amd64.deb
sudo apt-key add /var/cuda-repo-9-0-local/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda
echo 'export PATH=/usr/local/cuda-9.0/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
sudo reboot
重启后 运行
$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176
说明cuda安装成功。
安装 cuDNN 7.0
同样去英伟达官网的cuDNN下载页面:https://developer.nvidia.com/rdp/cudnn-download,
https://developer.nvidia.com/rdp/cudnn-archive
需要注册和登录
选择点开
Download cuDNN v7.0.5 (Dec 5, 2017), for CUDA 9.0
点开
cuDNN v7.0.5 Library for Linux
下载 得到
cudnn-9.0-linux-x64-v7.tgz
然后运行
$ tar -zxvf cudnn-9.0-linux-x64-v7.tgz
$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ -d
$ sudo chmod a+r /usr/local/cuda/include/cudnn.h
$ sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
重新运行
$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176
安装tensorflow
sudo apt-get install python-pip python-dev python-virtualenv
virtualenv --system-site-packages tensorflow1.8
source tensorflow1.8/bin/activate
easy_install -U pip
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade tensorflow-gpu==1.8.0
测试tensorflow
$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
2018-08-29 18:19:14.942761: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2018-08-29 18:19:15.034882: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2018-08-29 18:19:15.035245: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties:
name: GeForce GTX 1080 Ti major: 6 minor: 1 memoryClockRate(GHz): 1.645
pciBusID: 0000:01:00.0
totalMemory: 10.91GiB freeMemory: 10.41GiB
2018-08-29 18:19:15.035259: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0
2018-08-29 18:19:15.187436: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-08-29 18:19:15.187476: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0
2018-08-29 18:19:15.187481: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N
2018-08-29 18:19:15.187688: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10077 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1)
Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1
2018-08-29 18:19:15.265767: I tensorflow/core/common_runtime/direct_session.cc:284] Device mapping:
/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0, compute capability: 6.1
>>>