ubuntu安装CUDA

因为深度学习需要用到CUDA,所以写篇博客,记录下自己安装CUDA 的过程。

1 安装前的检查

安装CUDA之前,首先要做一些事情,检查你的机器是否可以安装CUDA。

1.1 检查你的gpu是否是可以安装CUDA 的

运行如下命令:

$ lspci | grep -i nvidia
  • 1

这个是我的机器的返回结果:

01:00.0 VGA compatible controller: NVIDIA Corporation GM107 [GeForce GTX 750 Ti] (rev a2)
01:00.1 Audio device: NVIDIA Corporation Device 0fbc (rev a1)
  • 1
  • 2
  • 3

1.2 检查你的linux版本是否支持CUDA

运行如下命令:

 uname -m && cat /etc/*release
  • 1

我的机器返回结果如下:

x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.2 LTS"
NAME="Ubuntu"
VERSION="14.04.2 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.2 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
DISTRIB_ID=Ubuntu Kylin
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu Kylin 14.04"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

x86_64代表你的机器是64位的,剩下的是解释的linux发行版信息。

如果是红帽,可能是这样的信息:

x86_64
Red Hat Enterprise Linux Workstation release 6.0 (Santiago)
  • 1
  • 2
  • 3

CUDA只支持一些特定的linux发行版,有Fedora,OpenSuSE,RHEL,CentOS,SLES,Ubuntu.

1.3 验证操作系统是否安装了gcc

在使用CUDA Tookit 开发的时候,gcc是需要的,但是运行CUDA程序的时候不需要。

gcc -v
  • 1

我的结果是:

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-12ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --enable-objc-gc --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-12ubuntu1)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

1.4 验证linux内核是否有正确的系统头文件

输入:

uname -r
  • 1

结果为:

3.16.0-53-generic
  • 1
  • 2

如果没有出现结果,就需要如下命令进行安装:

sudo apt-get install linux-headers-$(uname -r)
  • 1

2 安装CUDA-Toolkit

点击官网链接:CUDA-Toolkit ,在Select Target Platform里,点击linux,86_64,Ubuntu,14.04,deb[network],之后网页会自动弹出来安装指令:

Installation Instructions:
`sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb
`
`sudo apt-get update`
`sudo apt-get install cuda`
  • 1
  • 2
  • 3
  • 4
  • 5

deb[network]和deb[local]的区别就是,local是把完整的安装文件一次下载下来后安装,而network是在线下载。依次运行这三个命令,可以将CUDA安装成功。

我在执行第一步的时候,出现了这个错误:

ws@ws-Lenovo:/media/ws/000F9A5700006688/Downloads$ sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb
1404-8-0-local-ga2_8.0.61-1_amd64.deb
(Reading database ... 280787 files and directories currently installed.)
Preparing to unpack cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb ...
Unpacking cuda-repo-ubuntu1404-8-0-local-ga2 (8.0.61-1) over (8.0.61-1) ...
Setting up cuda-repo-ubuntu1404-8-0-local-ga2 (8.0.61-1) ...
run-parts: failed to stat component /etc/apt/trusted.gpg.d/wps-office-archive-keyring.gpg: No such file or directory
OK
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

之后我把wps-office给卸载了就没有问题了,应该是wps软连接的问题吧。以下是成功的信息:

ws@ws-Lenovo:/media/ws/000F9A5700006688/Downloads$ sudo dpkg -i cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb
(Reading database ... 279398 files and directories currently installed.)
Preparing to unpack cuda-repo-ubuntu1404-8-0-local-ga2_8.0.61-1_amd64.deb ...
Unpacking cuda-repo-ubuntu1404-8-0-local-ga2 (8.0.61-1) over (8.0.61-1) ...
Setting up cuda-repo-ubuntu1404-8-0-local-ga2 (8.0.61-1) ...
OK
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

3 安装之后要做的事

在安装之后,我们还需要做一些工作,才能真正完成CUDA的安装。

3.1 必须要做的事

添加CUDA的bin目录到PATH环境变量:

export PATH=/usr/local/cuda-8.0/bin${PATH:+:${PATH}}
  • 1

之后在控制台输入nvcc –version,可以得到如下信息:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Tue_Jan_10_13:22:03_CST_2017
Cuda compilation tools, release 8.0, V8.0.61
  • 1
  • 2
  • 3
  • 4
  • 5

3.2 建议要做的事

之后我们可以安装一些官方的CUDA例子,来检验我们是否安装成功了。

进入CUDA目录/usr/local/cuda-8.0/bin,会发现在这个目录下,有一个名为cuda-install-samples-8.0.sh的文件,在控制台使用命令:

sudo  sh  cuda-install-samples-8.0.sh  "例子被创建的目录"
  • 1

我使用的是/home目录。在我的/home目录下,有一个NVIDIA_CUDA-8.0_Samples 文件夹,里面就是官方的例子,进入这个目录,输入make进行编译。

sudo make
  • 1

需要相当长一段时间才能编译完成。我在编译第三个sample的时候,遇到了一个错误

/usr/bin/ld: cannot find -lnvcuvid
  • 1

刚开始以为是安装出错了,因为之前安装失败过一次,又手动把CUDA给卸载了。结果发现,是英伟达显卡驱动版本不同导致的.在NVIDIA_CUDA-7.0_Samples/3_Imaging/cudaDecodeGL/findgllib.mk文件中,

UBUNTU_PKG_NAME = "nvidia-367"
  • 1
  • 2

而我的英伟达驱动是375,于是只要把这行代码改成

UBUNTU_PKG_NAME = "nvidia-375"
  • 1
  • 2

就可以了,然后所有的例子都顺利的编译通过了。在编译完所有例子以后,会提示:

Finished building CUDA samples
  • 1

之后运行一些例子,编译好的二进制文件,保存在~/NVIDIA_CUDA-8.0_Samples/NVIDIA_CUDA-8.0_Samples/bin/x86_64/linux/release 中,进入这个目录,输入ls,看到很多编译好的二进制文件。先运行deviceQuery。输入

sudo  ./deviceQuery
  • 1

可以看到如下运行结果:

./deviceQuery Starting...

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

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 750 Ti"
CUDA Driver Version / Runtime Version 8.0 / 8.0
CUDA Capability Major/Minor version number: 5.0
Total amount of global memory: 2000 MBytes (2096824320 bytes)
( 5) Multiprocessors, (128) CUDA Cores/MP: 640 CUDA Cores
GPU Max Clock rate: 1189 MHz (1.19 GHz)
Memory Clock rate: 2700 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 750 Ti
Result = PASS
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42

在运行bandwidthTest

sudo  ./bandwidthTest
  • 1

可以看到结果:

[CUDA Bandwidth Test] - Starting...
Running on... Device 0: GeForce GTX 750 Ti
Quick Mode Host to Device Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 6539.7 Device to Host Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 6537.2 Device to Device Bandwidth, 1 Device(s)
PINNED Memory Transfers
Transfer Size (Bytes) Bandwidth(MB/s)
33554432 74576.4 Result = PASS NOTE: The CUDA Samples are not meant for performance measurements. Results may vary when GPU Boost is enabled.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

到此,CUDA算是已经安装完毕了。

ubuntu14.04安装CUDA8.0的更多相关文章

  1. DL服务器主机环境配置(ubuntu14.04+GTX1080+cuda8.0)解决桌面重复登录

    DL服务器主机环境配置(ubuntu14.04+GTX1080+cuda8.0)解决桌面重复登录 前面部分是自己的记录,后面方案部分是成功安装驱动+桌面的正解 问题的开始在于:登录不了桌面,停留在重复 ...

  2. ubuntu16.04安装cuda8.0试错锦集

    ubuntu16.04安装cuda8.0试错锦集 参考文献: [http://www.jianshu.com/p/35c7fde85968] [http://blog.csdn.net/sinat_1 ...

  3. ubuntu14.04 安装 tensorflow9.0

    ubuntu14.04 安装 tensorflow9.0 文章目录 ubuntu14.04 安装 tensorflow9.0 安装pip(笔者的版本为9.0) 仅使用 CPU 的版本的tensorfl ...

  4. caffe+GPU︱AWS.G2+Ubuntu14.04+GPU+CUDA8.0+cudnn8.0

    国服亚马逊的GPU实例G2.2xlarge的python+caffe的安装过程,被虐- 一周才装出来- BVLC/caffe的在AWS安装的官方教程github: https://github.com ...

  5. Ubuntu14.04安装tomcat-9.0.1的教程

    系统环境:Ubuntu14.04 Tomcat安装版本:Apache tomcat 9.0.1 下载地址:http://tomcat.apache.org/download-90.cgi 安装包:ap ...

  6. ubuntu14.04安装opencv3.0

    sudo apt-get update sudo apt-get upgrade 搭建C/C++编译环境: sudo apt-get install build-essential 安装关联库: su ...

  7. Ubuntu14.04安装CMake3.0.2

    http://blog.csdn.net/wz3118103/article/details/39826397 .去网址下载http://www.cmake.org/download/ Platfor ...

  8. ubuntu14.04安装、NVIDIA显卡驱动安装及CUDA8.0、Cudnn5.1的环境搭建

    安装环境:hp-Z440工作站.64位Ubuntu14.04(64位Ubuntu16.04).Cuda8.0.Cudnn5.1.Nvidia GeForce GT 705.Tesla K40c 本文可 ...

  9. ubuntu14.04 安装 CUDA 7.5 / CUDA 8.0

    原文转自:http://blog.csdn.net/masa_fish/article/details/51882183 CUDA7.5和CUDA8.0的安装过程是一毛一样的.所以如果安装CUDA8. ...

随机推荐

  1. java基础---->Base64算法的使用

    Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一,可用于在HTTP环境下传递较长的标识信息.详细的Base64信息,可以参见维基百科:https://en.wikipedia.org ...

  2. synchronized将任意对象作为对象监视器

    多个线程调用同一个对象中的不同名称的synchronized同步方法或synchronized(this)同步代码块时,调用的效果就是按顺序执行,也就是同步的,阻塞的.这说明synchronized同 ...

  3. WEB安全第七篇--终结篇考验逻辑思维:逻辑漏洞大汇总(越权、会话逻辑、业务逻辑、暴力破解)

    零.前言 最近做专心web安全有一段时间了,但是目测后面的活会有些复杂,涉及到更多的中间件.底层安全.漏洞研究与安全建设等越来越复杂的东东,所以在这里想写一个系列关于web安全基础以及一些讨巧的pay ...

  4. 【BZOJ4236】JOIOJI STL

    [BZOJ4236]JOIOJI Description JOIOJI桑是JOI君的叔叔.“JOIOJI”这个名字是由“J.O.I”三个字母各两个构成的. 最近,JOIOJI桑有了一个孩子.JOIOJ ...

  5. 在CentOS7下从0开始搭建docker并发布tomcat项目

    一切从0开始,我也是个小白: 1.检查你的系统是不是高于3.8的内核,如果没有请升级CentOS7或者Ubuntu 14 #uname -a 2.CentOS7下安装docker #yum -y in ...

  6. Solutions for common Android development problems with the Eclipse IDE- Tutorial

    Table of Contents 1. Solving typical Android development problems 1.1. Clean Project 1.2. android.co ...

  7. a Javascript library for training Deep Learning models

    w强化算法和数学,来迎接机器学习.神经网络. http://cs.stanford.edu/people/karpathy/convnetjs/ ConvNetJS is a Javascript l ...

  8. C# WinForm实现任务栏程序图标闪烁

    相信大家在用QQ的时候都会知道,你打开了QQ聊天窗口,如果窗口不是当前激活的窗口的话,收到QQ消息时,任务栏(不是托盘图标)上的图标会闪一下变成黄色(Win7默认主题下),用以通知用户有消息进来了,之 ...

  9. B - Network---UVA 315(无向图求割点)

        A Telephone Line Company (TLC) is establishing a new telephone cable network. They are connectin ...

  10. android(十四)四种启动模式

    standard 启动的activity会每次都重新创建一个activity放到任务栈中.这是系统默认的启动模式. singleTop启动的activity,如果任务的栈顶刚好存在当前的activit ...