Install CUDA and cuDNN on Ubuntu 16.04


foreword

The premise is that the graphics driver has been installed. You can refer to Ubuntu16.04 to install the NVIDIA graphics card driver .
The code environment that the author wants to reproduce is ubuntu16.04, Python2.7, and TensorFlow-GPU will be installed later.
References:
[1] Clarify the relationship between GPU, CUDA, CUDA Toolkit, cuDNN and download and install
[2] The relationship between graphics card driver and cuda, the relationship between cudnn and cuda
[3] The requirements of different versions of Tensorflow and the corresponding relationship between CUDA and CUDNN versions
[4] CUDA Tookit Notes
[5] Ubuntu18.04+RTX 2080Ti+CUDA 10.0 +cuDNN+PyTorch to build a deep learning environment
When the terminal is running nvidia-smi, it can be seen from the picture that the computing power of the graphics card is 460.67, and the maximum version 11.2 of CUDA can be installed.

insert image description here

Therefore, according to the TensorFlow official website and your own needs, choose Ubuntu 16.04 to download CUDA10.1 and cuDNN7.6.

insert image description here

1. CUDA installation

1. View the number of ubuntu system digits

Enter the following command in the terminal to obtain the digit information of the ubuntu system for use.

sudo uname --m

insert image description here

2. Download CUDA

Find the CUDA you need in CUDA Toolkit Archive , and I choose CUDA10.1 update2 version.

insert image description here
Select the corresponding conditions, and the author uses the .run file to install.

insert image description here
The second box on the web page is download related information, as shown in the figure below, copy the link in the red box to the browser to open, that is, download the corresponding .run file, and put it in the Home folder of the ubuntu system for use.

insert image description here

3. Install CUDA

Open the terminal, run the command in the blue box above, a very long agreement appears, and finally enter accept to continue.

insert image description here
Enter the picture below, enter to select, remove the X in front of the driver, move to install with the up and down keys, and enter to select to install.
insert image description here
The installation is complete, as shown in the figure below.

insert image description here

4. Configure the environment

After the installation is complete, you need to add the CUDA path to the current user's configuration file.

Execute the following command on the terminal to open the .bachrc file.

sudo gedit ~/.bashrc

There are two installation paths after "Please make sure that" in the previous picture. Add two lines of installation paths at the end of the .bachrc file.

export PATH="/usr/local/cuda-10.1/bin${PATH:+:${PATH}}"
export LD_LIBRARY_PATH="/usr/local/cuda10.1/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"

As shown below.

insert image description here
After saving, close the window and run the following command in the terminal to make the added path take effect.

source ~/.bashrc

At this time, run nvcc --versionor nvcc -Vcheck whether CUDA is successful, as shown in the figure below, if the version information appears, it means that the installation is successful.

insert image description here

  • Example test
    Switch to the default installation path of CUDA 10.1 Samples (/home/user/NVIDIA_CUDA-10.1_Samples) to run the example, and enter in the terminal:
cd NVIDIA_CUDA-10.1_Samples
sudo make all -j4

Getting "Finished building CUDA samples" in the last line in the figure below can also prove that CUDA is installed successfully.

insert image description here

  • Check the CUDA driver and running version
    Run the following two commands:
cd bin/x86_64/linux/release
./deviceQuery

The result is shown in the figure below.

insert image description here
From this, the CUDA driver version is 11.2, and the running version is 10.1.
The author's understanding : CUDA has two APIs, namely the driver API and the runtime API, the so-called Driver API and Runtime API. The driver API means the highest version of CUDA that can be installed on the graphics card, and the runtime API means the currently used CUDA version, and the version does not exceed the driver API version.

Two, cuDNN installation

1. Download cuDNN

To download cuDNN, you need to register an account on the NVIDIA official website with your email address, and you can download it. Find the cuDNN version to download
in cuDNN Archive , and note that the downloaded version is cuDNN for Linux. The author chooses to download cuDNN7.6.5.
insert image description here
The file I downloaded is cudnn-10.1-linux-x64-v7.6.5.32.tgz.

2. Install cuDNN

Unzip the downloaded .tgz file, right-click the file and select "Extract to Here" or use the following command to extract.

tar -zxvf cudnn-10.1-linux-x64-v7.6.5.32.tgz

After decompression, you can see a cuda folder, right-click in the blank space of the current directory, select "Open in Terminal", copy the library and header files in this folder to the CUDA installation path and modify the file access permissions:

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 
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*

Check the cuDNN version to test whether the installation is successful:

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

The cudnn version shown in the figure below shows that the installation is successful.

insert image description here

3. Related records

① Install CUDA8.0 under ubuntu16.04+CUDA8.0
Ubuntu

② Switch between multiple versions of cuda
Install Ubuntu and switch between multiple versions of cuda

③ Install multiple versions of cuda and cudnn
a. Install multiple versions of cuda and cudnn under Ubuntu16.04
b. Install multiple versions of cuda and cudnn under Ubuntu16.04
c. Install CUDA11.0 on Ubuntu18.04 Installation failed. See log at /var/log/cuda-installer.log for details.

Guess you like

Origin blog.csdn.net/dreaming_song/article/details/115967335