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. 【linux系列】linux防火墙的关闭开启

    即时生效 开启:service iptables start 关闭:service iptables stop 重启后生效 开启:chkconfig iptables on 关闭:chkconfig ...

  2. Android Runtime.getRuntime().exec

    try { // Executes the command. Process process = Runtime.getRuntime().exec(cmd); // NOTE: You can wr ...

  3. Ubuntu16.04安装Nessus和MSF

    一.Nessus篇: 1.参考文献:https://www.cnblogs.com/shamojituan/p/6511208.html 2.下载地址:https://downloads.nessus ...

  4. TDD中的单元测试写多少才够?

    测试驱动开发(TDD)已经是耳熟能详的名词,既然是测试驱动,那么测试用例代码就要写在开发代码的前面.但是如何写测试用例?写多少测试用例才够?我想大家在实际的操作过程都会产生这样的疑问. 3月15日,我 ...

  5. javascript飞机大战-----009游戏结束

    /* 游戏引擎 */ var Engine = { //刚开始的游戏状态 gameStatus:false, //所以敌机 enemy:{}, //子弹 bullet:{}, //得分 scroe:0 ...

  6. Code Forces 18D Seller Bob(简单DP)

    D. Seller Bob time limit per test 2 seconds memory limit per test 128 megabytes input standard input ...

  7. CodeForeces 25E (kmp)

    E. Test time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputst ...

  8. scrapy爬虫系列之开头--scrapy知识点

    介绍:Scrapy是一个为了爬取网站数据.提取结构性数据而编写的应用框架,我们只需要实现少量的代码,就能够快速抓取.Scrapy使用了Twisted异步网络框架,可以加快我们的下载速度. 0.说明: ...

  9. stark - 增、删、改

    一.效果图 二.增.删.改 知识点: 1.解决代码重用 {% include 'form.html' %} 2.自定制配置modelform 每张表,就可自定义配置 labels , widges.. ...

  10. 服务器为什么这么慢?耗尽了CPU、RAM和磁盘I/O资源

    机器运行缓慢通常是由于消耗了太多系统特定的资源.系统的主要资源包括CPU.RAM.磁盘I/O以及网络.过度使用这些资源的任何一种都会让系统陷入困境.不过,如果能登录到系统之中,可以借助大量工具确定问题 ...