Ubuntu16.04 && CUDA && tensorflow

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了点。。。。。。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,491评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,856评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,745评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,196评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,073评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,112评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,531评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,215评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,485评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,578评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,356评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,215评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,583评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,898评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,174评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,497评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,697评论 2 335

推荐阅读更多精彩内容