TensorFlow我爱编程

Ubuntu16.04 && CUDA &

2017-07-31  本文已影响103人  wolegeyun

0、安装Anaconda3

下载Anaconda3-4.3.1-Linux-x86_64.sh

chmod a+x Anaconda3-4.3.1-Linux-x86_64.sh

./Anaconda3-4.3.1-Linux-x86_64.sh(默认安装到~目录,同时会替换原有的python2)

vim ~/.bashrc

export PATH=~/anaconda3/bin/:$PATH

一、下载Nvidia驱动

去该地址下载驱动:www.nvidia.com/Download/index.aspx

使用lspci确认显卡型号:lspci  | grep NVIDIA

01:00.0 VGA compatible controller: NVIDIA Corporation GM107 [GeForce GTX 745] (rev a2)

NVIDIA Driver

下载即可,在~/Downloads/NVIDIA-Linux-x86_64-384.59.run可以找到下载的文件。

1、关闭x-server, sudo service lightdm stop

(提示:会关闭图形界面,请使用ssh或者ctrl+alt+F1,我使用SSH)

2、cd ~/Downloads/ && sudo ./NVIDIA-Linux-x86_64-384.59.run

3、各种yes,然后安装成功。

4、sudo service lightdm start 打开图形界面。

5、执行nvidia-setting可以查看相关信息。

三、Q&A

1、注意图形化界面,使用sudo service lightdm stop/start

2、nouveau驱动问题:有的使用modprobe的blacklist,我试了没成功,所以直接使用nvidia驱动替换。即 sudo apt-get install nvidia-current,然后重启,发现nouveau驱动不再加载。

四、下载CUDA

去该地址https://developer.nvidia.com/cuda-downloads下载安装即可。

CUDA

我选deb(network)因为linux下载使用浏览器比较慢(我ssh的机器系统是Kali)。

在~/Downloads/cuda-repo-ubuntu1604_8.0.61-1_amd64.deb,执行上图中的1,2,3即可安装。

下面就是等待出错了。。。(很不幸没有出错,但是调用deviceQuery出错了。。。。)

安装的目录一般是/usr/local/cuda,在cuda/extras/demo_suite/下sudo  ./deviceQuery 提示如下:

./deviceQuery

./deviceQuery Starting...

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

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 745"

CUDA Driver Version / Runtime Version          8.0 / 8.0

CUDA Capability Major/Minor version number:    5.0

Total amount of global memory:                4041 MBytes (4237164544 bytes)

( 3) Multiprocessors, (128) CUDA Cores/MP:    384 CUDA Cores

GPU Max Clock rate:                            1032 MHz (1.03 GHz)

Memory Clock rate:                            900 Mhz

Memory Bus Width:                              128-bit

L2 Cache Size:                                2097152 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 = 8.0, CUDA Runtime Version = 8.0, NumDevs = 1, Device0 = GeForce GTX 745

Result = PASS


五、Q&A

执行deviceQuery出现(心都碎了,这是第二次装一堆问题,第一次的时候6的不行):

./deviceQueryStarting...

CUDADeviceQuery(RuntimeAPI)version(CUDARTstaticlinking)

FATAL:Modulenvidia_uvmnotfound.

cudaGetDeviceCount returned30

->unknown error

Result=FAIL

果断谷歌:发现应该是nvidia-uvm.ko的问题,dmesg提示的问题如下。

nvidia_uvm: Unknown symbol nvUvmInterfaceGetBigPageSize (err 0)

解决方法:sudo update-alternatives--config x86_64-linux-gnu_gl_conf

执行上面的命令,选在一个。我的如图:(估计是install nvidia-current引入的)

选择的0

然后sudo modprobe nivdia-uvm提示ok,在执行deviceQuery就OK了。

六 、CUDA编程

以下链接是共享的百度网盘,随便网上找的CUDA编程的一点资料。

链接: http://pan.baidu.com/s/1slBazlN 密码: rsmm

七、安装cudnn    (装了6.0不好用。。。。。)

下载:cudnn-8.0-linux-x64-v5.1.tgz

cd /usr/local

sudo tar -zxvf /tmp/cudnn-8.0-linux-x64-v5.1.tgz 

八、环境变量设置

vim ~/.bashrc,添加如下

export CUDA_HOME=/usr/local/cuda-8.0

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

export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:/usr/local/cuda-8.0/extras/CUPTI/lib64:$LD_LIBRARY_PATH

九安装Tensorflow(在线安装)

sudo apt-get install libcupti-dev

Installing with Anaconda

Take the following steps to install TensorFlow in an Anaconda environment:

Follow the instructions on theAnaconda download siteto download and install Anaconda.

Create a conda environment namedtensorflowto run a version    of Python by invoking the following command:

$conda create -n tensorflow

Activate the conda environment by issuing the following command:

$source activate tensorflow(tensorflow)$  # Your prompt should change

Issue a command of the following format to install

TensorFlow inside your conda environment:

(tensorflow)$pip install --ignore-installed --upgradetfBinaryURL

wheretfBinaryURLis theURL of the TensorFlow Python package. For example, the following command installs the CPU-only version of TensorFlow for Python 2.7:

(tensorflow)$pip install --ignore-installed --upgrade \

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.2.1-cp34-cp34m-linux_x86_64.w

我的是python3.6所以tfBinaryURL:https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.2.1-cp36-cp36m-linux_x86_64.whl

所以执行pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.2.1-cp36-cp36m-linux_x86_64.whl

等到执行结束即可。

十、测试

执行ipython,输入以下:

import  tensorflow as tf

hello=tf.constant('Hello, TensorFlow!')

sess=tf.Session()

print(sess.run(hello))

If the system outputs the following, then you are ready to begin writing TensorFlow programs:

Hello, TensorFlow!

十一、安装成功。

第一次写东西,文笔low了点。。。。。。

上一篇 下一篇

猜你喜欢

热点阅读