ubuntu16.04下tensorflow1.0+CUDA8.0+cudnn8.0安装配置

首先简单解释一下这几个名词:

(1)ubuntu16.04:大名鼎鼎的一个linux发行版,以桌面系统的强大得到广大用户青睐(特别是刚入门的小白用户),16.04表示2016.04发布的,该系统每年4月和10月发布两个版本,即04和10,年份为偶数的版本最稳定,比如12.04,14.04,16.04等就被广泛使用。

(2)tensorflow:一个google开源的深度学习框架,封装了很多机器学习的算法即模型,我们拿来就可以用了,鉴于谷歌的影响力,tensorflow目前也是大红大紫。目前(2017-3-20)最新版本为1.0,该框架更新很快。

(3)CUDA:显卡厂商NVIDIA推出的通用并行运算平台,由于机器学习数据量很大,通常要用GPU来加速运算,而当今显卡厂商唯NVIDIA一家独大,自然要用打它家的CUDA了。

(4)cudnn:NVIDIA专门为深度学习设计的一套GPU计算加速方案。

开始安装:

  首先去NVIDIA官网下载CUDA最新版本(选择好对应的平台,我这里是ubuntu16.04),CUDA官网下载链接

  再去NVIDIA官网下载cudnn最新版本(先要注册一个NVIDIA帐号,放心吧,免费的),cudnn官网下载链接

  现在你有2个文件了:cuda_8.0.44_linux.run和cudnn-8.0-linux-x64-v5.1.tgz(当然版本不一定和我一样)

  (1)CUDA8.0安装:

//让cuda_8.0.44_linux.run 获取可执行权限
chmod 761 cuda_8.0.44_linux.run 
//运行cuda_8.0.44_linux.run 
./cuda_8.0.44_linux.run --override

安装过程出现一下信息,一路yes即可:

Logging to /tmp/cuda_install_6105.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,
Do you accept the previously read EULA?
accept/decline/quit: accept

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 367.48?
(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 ]: 

/usr/local/cuda-8.0 is not writable.
Do you wish to run the installation with 'sudo'?
(y)es/(n)o: y

Please enter your password: 
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/nights ]: /usr/local/cuda-8.0

Installing the CUDA Toolkit in /usr/local/cuda-8.0 ...
Missing recommended library: libGLU.so
Missing recommended library: libX11.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so

Installing the CUDA Samples in /usr/local/cuda-8.0 ...
Copying samples to /usr/local/cuda-8.0/NVIDIA_CUDA-8.0_Samples now...
Finished copying samples.
安装完成后出现以下信息:

===========
= Summary =
===========

Driver:   Not Selected
Toolkit:  Installed in /usr/local/cuda-8.0
Samples:  Installed in /usr/local/cuda-8.0, but missing recommended libraries

Please make sure that
 -   PATH includes /usr/local/cuda-8.0/bin
 -   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

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

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

***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.
To install the driver using this installer, run the following command, replacing <CudaInstaller> with the name of this run file:
    sudo <CudaInstaller>.run -silent -driver

Logfile is /tmp/cuda_install_6105.log

    即安装成功。如果要卸载,可以看到上面有提示信息:

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

    也就是/usr/local/cuda-8.0/bin/uninstall_cuda_8.0.pl了。

  (2)cudnn安装:

//解压cudnn-8.0-linux-x64-v5.1.tgz
tar -zxvf cudnn-8.0-linux-x64-v5.1.tgz
//进入加压出来的cuda文件夹
cd cuda
//复制文件
sudo cp include/cudnn.h /usr/local/cuda/include/
sudo cp lib64/* /usr/local/cuda/lib64/
//进入/usr/local/cuda/lib64/
cd /usr/local/cuda/lib64/
//删掉旧链接,创建新链接
sudo rm -rf libcudnn.so libcudnn.so.5
sudo ln -s libcudnn.so.5.1.5 libcudnn.so.5
sudo ln -s libcudnn.so.5 libcudnn.so
//编辑proflie,添加环境变量
sudo vim /etc/profile
//进入profile后在最后一行添加以下信息并保存:
PATH=/usr/local/cuda/bin:$PATH
export PATH
//创建cuda.conf文件
sudo vim /etc/ld.so.conf.d/cuda.conf
//在cuda.conf文件中添加以下信息并保存:
/usr/local/cuda/lib64
//重新加载配置
sudo ldconfig
//验证安装是否成功,输入nvidia-smi命令:
nvidia-smi

显示如下信息则安装成功:

Mon Mar 20 23:02:56 2017       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.57                 Driver Version: 367.57                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1070    Off  | 0000:01:00.0      On |                  N/A |
| 27%   27C    P8     8W / 151W |    242MiB /  8110MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|    0       982    G   /usr/lib/xorg/Xorg                             104MiB |
|    0      1889    G   compiz                                          72MiB |
|    0      2187    G   fcitx-qimpanel                                   8MiB |
|    0      4865    G   ...s-passed-by-fd --v8-snapshot-passed-by-fd    54MiB |
+-----------------------------------------------------------------------------+

  (3)tensorflow1.0安装:

      由于tensorflow版本更新很快,安装方式也多种多样,可以参照官网给出的安装方式:tensorflow官网安装文档

总的说来目前有四种安装方式,我这里选择使用pip来安装:

首先需要有python环境和pip工具,不过ubuntu都自带了,如果没有的话,运行下面的命令来安装:

sudo apt-get install python-pip python-dev
接下来就是安装tensorflow了,可以安装自己的需求来选择版本安装:

 $ pip install tensorflow      # Python 2.7; CPU support (no GPU support)
 $ pip3 install tensorflow     # Python 3.n; CPU support (no GPU support)
 $ pip install tensorflow-gpu  # Python 2.7;  GPU support
 $ pip3 install tensorflow-gpu # Python 3.n; GPU support 
我这里选择的是毕竟有GPU嘛,前面还安装了cuda和cudnn:
$ pip install tensorflow-gpu  # Python 2.7;  GPU support

验证安装是否成功,在终端敲入命令python进入python运行环境,在导入tendorflow: import tensorflow出现如下信息则安装成功:

$python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
>>> 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值