(安装:NVIDIA-384+CUDA9.0+cuDNN7.1)
显卡(GPU)驱动:NVIDIA-384
CUDA:CUDA9.0
cuDNN:cuDNN7.1
Ubuntu 下安装CUDA需要装NVIDIA驱动,首先进入NVIDIA官网,然后查询对应NVIDIA驱动是否支持你电脑的型号。
这里我的电脑是:华硕F450J ,自带的NVIDIA GEFORCE 745。
第一步、安装NVIDIA GPU驱动
去NVIDIA官网查询是否支持我电脑的GPU如下
可以看出:GeForce 700M Series (Notebooks):
GeForce GTX 780M, GeForce GTX 770M, GeForce GTX 765M, GeForce GTX 760M, GeForce GT 755M, GeForce GT 750M, GeForce GT 745M, GeForce GT 740M, GeForce GT 735M, GeForce GT 730M, GeForce GT 720M, GeForce GT 710M, GeForce 720M, GeForce 710M, GeForce 705M
GeForce GT 745M为我电脑的型号,所以version:390.48是支持我的NVIDIAGPU驱动的。
所以第二部我们安装NVIDIA DISPLAY DRIVER version:390.48 执行如下代码:
第一部分:安装后续步骤或环境必需的依赖包
1 sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler
2
3 sudo apt-get install --no-install-recommends libboost-all-dev
4
5 sudo apt-get install libopenblas-dev liblapack-dev libatlas-base-dev
6
7 sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev
8
9 sudo apt-get install git cmake build-essential
输入以下代码输出如下信息则表示依赖环境安装成功
code:
1 sudo apt-get install git cmake build-essential
显示:
1 Reading package lists... Done
2 Building dependency tree
3 Reading state information... Done
4 build-essential is already the newest version (12.1ubuntu2).
5 cmake is already the newest version (3.5.1-1ubuntu3).
6 git is already the newest version (1:2.7.4-0ubuntu1.3).
7 0 upgraded, 0 newly installed, 0 to remove and 126 not upgraded.
表示依赖环境安装成功
第二部分:安装显示驱动
去官网下载NVIDIA的显卡(GPU)驱动然后运行。或者直接终端上运行,执行如下代码。
sudo apt-get update
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-384
sudo apt-get install mesa-common-dev
sudo apt-get install freeglut3-dev
执行结束后,重新启动系统
sudo reboot #或者sudo shutdown -r now
开机后检测是否安装显示驱动成功
nvidia-settings #或者直接点击dash开始界面输入NVIDIA查看
显示如下信息表示安装成功
配置环境变量
sudo gedit ~/.bashrc
在.bashrc中加入如下两行
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
第二步、安装NVIDIA CUDA
第一部分、先进入NVIDIA官网的CUDA Toolkit 下载界面
如下图所示,下载CUDA Toolkit
注意:这个地方的提示,要安装这个CUDA Toolkit 9.1,需要先安装至少NVIDIA DISPLAY DRIVER R390 版本3.90以上。
CUDA Toolkit
下载好CUDA Toolkit9.1后,执行如下代码进行安装(此处不需要安装OPGL),代码如下:
1 sudo sh cuda_9.0.176_384.81_linux.run --no-opengl-libs #run文件的文件名根据自己下的文件名修改,默认是我提供的文件
输出显示:
1 Do you accept the previously read EULA?
2 accept/decline/quit: accept
3 Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
4 (y)es/(n)o/(q)uit: n
5 Install the CUDA 9.0 Toolkit?
6 (y)es/(n)o/(q)uit: y
7 Enter Toolkit Location
8 [ default is /usr/local/cuda-9.0 ]:
9 Do you want to install a symbolic link at /usr/local/cuda?
10 (y)es/(n)o/(q)uit: y
11 Install the CUDA 9.0 Samples?
12 (y)es/(n)o/(q)uit: y
13 Enter CUDA Samples Location
14 [ default is /home/pertor ]:
15 Installing the CUDA Toolkit in /usr/local/cuda-9.0 ...
16 Missing recommended library: libXmu.so
添加环境变量:
sudo gedit ~/.bashrc
export PATH=/usr/local/cuda-8.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
source ~/.bashrc
验证CUDA9.0是否安装成功
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
输出如下信息表示成功安装
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 1 CUDA Capable device(s)
Device 0: "GeForce GT 740M"
CUDA Driver Version / Runtime Version 8.0 / 8.0
CUDA Capability Major/Minor version number: 3.5
Total amount of global memory: 2004 MBytes (2100953088 bytes)
( 2) Multiprocessors, (192) CUDA Cores/MP: 384 CUDA Cores
GPU Max Clock rate: 1032 MHz (1.03 GHz)
Memory Clock rate: 800 Mhz
Memory Bus Width: 64-bit
L2 Cache Size: 524288 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
第三步、安装NVIDIA cuDNN
登录官网下载cuDNN
这个需要申请账号,注册后进入官网,如下图所示
下载链接:https://developer.nvidia.com/rdp/cudnn-download,需要注册之后才能打开,这里我们选择 cuDNN v7.1.1 (Feb 28, 2018), for CUDA 9.0,然后选择 cuDNN v7.1.1 Library for Linux,如图所示:
下载下来之后解压安装,执行如下步骤:
1 tar -zxvf cudnn-9.0-linux-x64-v7.1.tgz
2 sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
3 sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ -d
4 sudo chmod a+r /usr/local/cuda/include/cudnn.h
5 sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
终端中执行nvcc -V 显示如下信息则表示成功
nvcc -V
pertor@pertor-computer:~$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176
提示:
不建议安装CUDA 9.1 ,建议安装CUDA 9.0版本。CUDA 9.1里面自带387驱动,但是一般CUDA 9.1自带的驱动一般很难安装成功的,所以建议自己去单独安装384显示驱动。并且官网提示CUDA9.1 需要的显卡驱动必须至少是390以上版本,所以安装了384显卡驱动则需要安装CUDA9.0。
为了保险起见我们应该装CUDA 9.0和 nvidia-384这个版本。