Ubunt16.04 build GPU graphics card driver CUDA9.0 + cuDNN7 detailed tutorial +

Red Stone Website: www.redstonewill.com

If your computer is installed Ubuntu16.04, and the computer comes with an NVIDIA GeForce GPU graphics card, then do not come running back depth learning models to shame! Online tutorials in this regard are many, but most of the good and the bad. This article taught you how to install the GPU graphics driver, CUDA9.0 and cuDNN7. Worth a try!

NOTE: Because of the different systems, different GPU CUDA and corresponding cuDNN were different, this article only Ubuntu16.04, NVIDIA GeForce GPU, CUDA9.0 and cuDNN7 example, to introduce the installation process. The process is similar to other versions, but there are nuances, the reader is based on practice.

Requirements

工欲善其事必先利其器, first determine your computer the following two conditions are met.

  • Installation Ubuntu16.04
  • Computer comes with an NVIDIA GeForce GPU graphics card

A mounting GPU graphics driver

There is a NVIDIA GPU graphics card is not enough, you also need to install GPU video card driver.

1, the first landing GeForce official website , the manual search driver , select the system for their own, noting that "Linux 64-bit". Other options default. Then, click on to start the search will automatically search your computer matches the GPU graphics driver, the search results are shown below:

Here Insert Picture Description
As shown above, the result will show GPU graphics card driver is available, determine the version you need, just click on it to download. For example, I selected version is 418.43, after downloading the file is NVIDIA-Linux-x86_64-418.43.run .

2、打开终端 Terminal,首先卸载系统之前安装的 NVIDIA 显卡驱动,以防万一。(没有安装的可以忽略这一步)

$ sudo apt-get --purge remove nvidia-*

3、打开 blacklist:

$ sudo gedit /etc/modprobe.d/blacklist.conf

在最后添加几行:

blacklist vga16fb
blacklist nouveau
blacklist rivafb
blacklist nvidiafb
blacklist rivatv

这时候在终端输入:

$ lsmod | grep nouveau

如果没有输出,可以直接进行下一步,安装驱动。如果仍有输出,则在终端输入:

$ sudo gedit /etc/modprobe.d/blacklist-nouveau.conf

直接写入:

blacklist nouveau
blacklist lbm-nouveau
options nouveau modeset=0
alias nouveau off
alias lbm-nouveau off

保存关闭,再在终端输入下面的命令验证是否没有输出了。

$ sudo update-initramfs -u
$ lsmod | grep nouveau
# 如果这样还有输出,reboot一次

到这一步,应该没有输出了,可以进行安装驱动了。

4、在正式安装驱动之前,请记住你的驱动的 .run 文件的下载路径和完整的文件名。按 Ctrl+Alt+F1 进入命令行界面,输入下面的命令:

$ sudo /etc/init.d/lightdm stop
$ sudo init 3

进入 .run 文件的下载路径,使用 chmod 命令增加 .run 文件的运行权限。

$ chmod a+x NVIDIA-Linux-x86_64-418.43.run
$ sudo ./NVIDIA-Linux-x86_64-418.43.run -no-x-check -no-nouveau-check -no-opengl-files  #这里是关闭x server,nouveau和不下载opengl文件

然后就会开始安装程序,安装完成之后,输入下面的命令:

$ nvidia-smi

如果出现与下面类似的结果,证明驱动安装成功了。

Here Insert Picture Description
最后,回到图像界面。

$ sudo /etc/init.d/lightdm start

这样,驱动就算正式安装成功了。

二、安装 CUDA9.0

1、首先,登录 CUDA 的下载网站,由于现在 CUDA 的版本已经更新到 10 了,我们需要安装 9.0 版本。因此,点击 Legacy Releases,进入之前的版本列表。

Here Insert Picture Description然后,在 CUDA 版本列表中,选择 9.0 版本。

Here Insert Picture Description
选择对应的系统等信息,就可以点击 Download 进行下载了。注意选择下载 runfile 文件。

Here Insert Picture Description
2、打开终端,进入 CUDA9.0 的下载目录,输入:

$ chmod a+x cuda_9.0.176_384.81_linux.run
$ sudo ./cuda_9.0.176_384.81_linux.run

然后就会进入安装。在安装过程中会询问你一些配置信息,一般直接选择默认选项就行。有一个必须注意的地方是会让你选择是否安装 Graphics Driver for Linux-x86_64:XXXX 版本,这个地方必须选择 no!否则会覆盖之前的驱动。

3、安装完毕之后,声明环境变量。打开 .bashrc 文件,在终端输入:

$ sudo gedit ~/.bashrc

在文件最后加上:

export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

保存退出。

$ source ~/.bashrc

4、验证 GPU 驱动版本:418.43

$ cat /proc/driver/nvidia/version

Here Insert Picture Description

Verify CUDA Version: 9.0

$$ nvcc -V

Here Insert Picture Description

5, there are problems that may be encountered is not installed gcc gcc version is too high or the need to manually downgrade, are better resolved, will not repeat them here.

Third, the installation cuDNN

1. First, go to cuDNN the download site . It is worth mentioning that, before the download is need to register an account. Version list shown in the figure below, adapted CUDA9.0 selected, the corresponding system is Linux.

Here Insert Picture Description
2, after the download is complete, extract:

$ tar -zxvf cudnn-9.0-linux-x64-v7.6.1.34.tgz

Extracting command output is as follows:

cuda/include/cudnn.h
cuda/NVIDIA_SLA_cuDNN_Support.txt
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.7
cuda/lib64/libcudnn.so.7.6.1
cuda/lib64/libcudnn_static.a

Copy the relevant files to a specified directory:

$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/

3, the local cuda path, creating soft connection, terminal type:

$ cd /usr/local/cuda/lib64
$ sudo chmod +r libcudnn.so.7.6.1
$ sudo ln -sf libcudnn.so.7.6.1 libcudnn.so.7  
$ sudo ln -sf libcudnn.so.7 libcudnn.so  
$ sudo ldconfig  

Note that this file name is the version number before referring to extract from the file name on the shining write.

4, to detect what the local path cuda:

$ cd /usr/local/cuda/lib64
$ ll

Appears cuDNN corresponding version number to prove successful installation!

lrwxrwxrwx  1 root root        13 3月  19 16:02 libcudnn.so -> libcudnn.so.7*
lrwxrwxrwx  1 root root        17 3月  19 16:02 libcudnn.so.7 -> libcudnn.so.7.6.1*
-rwxr-xr-x  1 root root 287641664 3月  19 16:00 libcudnn.so.7.6.1*

We're done! GPU graphics driver + CUDA9.0 + cuDNN7 environment configuration.

references:

Ubuntu16.04 build GTX1080 + CUDA9.0 + cuDNN7.0.5 + Tensorflow1.6.0 environment


Here Insert Picture Description

Published 251 original articles · won praise 1024 · Views 1.37 million +

Guess you like

Origin blog.csdn.net/red_stone1/article/details/98959007