Deep Learning Environment on Ubuntu 18.04 LTS

Nvidia Driver

Install

1
2
3
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
sudo apt install nvidia-driver-(newest version)

Nvidia Newest Driver Version

Uninstall

1
2
3
4
sudo apt purge nvidia-*

sudo apt autoremove
sudo add-apt-repository --remove ppa:graphics-drivers/ppa

CUDA 10.1

CUDA

And then click “Legacy Releases”, select CUDA Toolkit 10.1 update2 (Check support for TensorFlow and PyTorch first)

1
2
wget http://developer.download.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.243_418.87.00_linux.run
sudo sh cuda_10.1.243_418.87.00_linux.run

Un-select the Nvidia Driver, and Install CUDA. First time might just fail (Log file indicate that ubuntu default nouveau driver is disabled), just reboot the computer and install again.

CUDA Version:

1
2
3
nvidia-smi
nvcc --version
cat /usr/local/cuda/version.txt

cuDNN

Install

  1. Register NVIDIA Developer
  2. Download at cuDNN
  3. Select Download cuDNN v7.6.5 (November 5th, 2019), for CUDA 10.1
  4. Download cuDNN Library for Linux
  5. Refer to installation guide
1
2
3
4
5
6
7
Navigate to your <cudnnpath> directory containing the cuDNN Tar file.
Unzip the cuDNN package.
$ tar -xzvf cudnn-10.2-linux-x64-v7.6.5.32.tgz
Copy the following files into the CUDA Toolkit directory, and change the file 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 /usr/local/cuda/lib64/libcudnn*

Testing

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

Search cudnn_samples_v7 on GitHub.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
git clone https://github.com/mmmn143/cudnn_samples_v7

Verifying The cuDNN Install On Linux
To verify that cuDNN is installed and is running properly, compile the mnistCUDNN sample located in the /usr/src/cudnn_samples_v7 directory in the debian file.

Copy the cuDNN sample to a writable path.
$cp -r /usr/src/cudnn_samples_v7/ $HOME
Go to the writable path.
$ cd  $HOME/cudnn_samples_v7/mnistCUDNN
Compile the mnistCUDNN sample.
$make clean && make
Run the mnistCUDNN sample.
$ ./mnistCUDNN
If cuDNN is properly installed and running on your Linux system, you will see a message similar to the following:
Test passed!

Testing using PyTorch:

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
import torch
# 静默
 
a = torch.tensor(1.)
# 静默
 
a.cuda()
# tensor(1., device='cuda:0')
 
from torch.backends import cudnn
# 静默
 
cudnn.is_available()
# True
 
cudnn.is_acceptable(a.cuda()) 
# True


In [1]: import torch
 
In [2]: torch.cuda.current_device()
Out[2]: 0
 
In [3]: torch.cuda.device(0)
Out[3]: <torch.cuda.device at 0x7efce0b03be0>
 
In [4]: torch.cuda.device_count()
Out[4]: 1
 
In [5]: torch.cuda.get_device_name(0)
Out[5]: 'GeForce GTX 950M'