ubuntu 18.04 installation of GPU driver and CUDA+cuDNN

Install GPU driver and CUDA+cuDNN (for Ubuntu 18.04)

1, Video card driver installation:

1. Detect video card

First, examine the model of your NVIDIA graphics card and recommended drivers. Execute command:

$ ubuntu-drivers devices

The output result is:

== /sys/devices/pci0000:00/0000:00:02.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001B82sv00007377sd000011DCbc03sc00i00
vendor   : NVIDIA Corporation
model    : GP104 [GeForce GTX 1070 Ti]
driver   : nvidia-driver-390 - distro non-free recommended
driver   : xserver-xorg-video-nouveau - distro free builtin

As you can see, here is a GTX 1070Ti device, and the corresponding driver is nvidia-390 (recommended). Sometimes there are several options for different drivers at different times. It is recommended to choose the one recommended.

2. Installing the drive

You can choose to install all the recommended drivers as follows

$ sudo ubuntu-drivers autoinstall

You can choose to install all the recommended drivers as follows

$ sudo apt install nvidia-driver-390

OK driver installation is completed, restart, check the system configuration = = > details = = > about whether the graphics processing corresponds to its own independent graphics card.

2, Install CUDA (for 18.04)

To install CUDA, please note that CUDA usually corresponds to the version of cudnn.

First of all, select CUDA, or the old version (circled in red), official website address:

https://developer.nvidia.com/cuda-downloads

Note that some versions have patches to download as well.

To start the installation, take cuda9.0 as an example:

1. GCC degradation

Since CUDA 9.0 only supports GCC 6.0 and below, Ubuntu 18.04 pre installs GCC version 7.3,

Therefore, manual degradation:

sudo apt-get install gcc-4.8
sudo apt-get install g++-4.8

Enter / usr/bin directory after installation

  $ls -l gcc* 

The following results are displayed

lrwxrwxrwx 1 root root 7th May 16 18:16 /usr/bin/gcc -> gcc-7.3

It is found that GCC is linked to gcc-7.0. You need to change it to link to gcc-4.8 as follows:

sudo mv gcc gcc.bak #backups
sudo ln -s gcc-4.8 gcc #re-link

Similarly, the same changes are made to g + +

 

ls -l g++*

lrwxrwxrwx 1 root root 7th May 15:17 g++ -> g++-7.3

You need to change the g + + link to g++-4.8:

sudo mv g++ g++.bak
sudo ln -s g++-4.8 g++

Then look at the gcc and g + + version numbers:

gcc -v g++ -v

gcc version 4.8 is displayed, indicating that gcc 4.8 is installed successfully.

2 install cuda and its patches

Enter the command to install the Base Installer:

sudo sh cuda_9.1.85_387.26_linux.run

It should be noted that the video card driver has been installed before, so when you ask if you want to install the video card driver, you can select no, and other options are the default path or yes.

Then, continue to install the 3 patch es as follows:

sudo sh cuda_9.1.85.1_linux.run
sudo sh cuda_9.1.85.2_linux.run
sudo sh cuda_9.1.85.3_linux.run

After installation, add the following two to the. bashrc file

sudo vim ~/.bashrc

export PATH=/usr/local/cuda-9.1/bin${PATH:+:$PATH}}      #Note that depending on your version, modify cuda-9.2/9.0
export LD_LIBRARY_PATH=/usr/local/cuda-9.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} #Note that depending on your version, modify cuda-9.2/9.0

OK, so, at this stage, cuda is installed

 

3, Install cuDNN (for 18.04)

The installation of cuDNN is to copy the files in cuDNN package to cuda folder.

cuDNN needs to be installed after CUDA is installed.

Official website address: https://developer.nvidia.com/rdp/cudnn-archive

So the version of cuDNN is as follows

Select the corresponding cudnn version to download according to CUDA.

According to the fourth point, the version of cuDNN we need to download is

cuDNN v7.0.0 library for liunx,Download address (registration required to download)

After downloading, switch to the default Downloads folder, and you can see the cudnn-9.1-linux-x64-v7.tgz compressed package

Extract it first, and then copy the contents to the CUDA installation folder

Copy cuDNN content to cuda related folder

# Note that the name of the extracted folder is cuda. Copy the corresponding file to cuda in / usr/local
sudo cp cuda/include/cudnn.h    /usr/local/cuda/include      
sudo cp cuda/lib64/libcudnn*    /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h   /usr/local/cuda/lib64/libcudnn*

This is where the installation of is complete.

Published 32 original articles, won praise 3, visited 8985
Private letter follow

Tags: sudo Ubuntu vim Linux

Posted on Wed, 11 Mar 2020 04:04:01 -0400 by pk-uk