Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Install CUDA 10.0 and cuDNN v7.4.2 on Ubuntu 16.04

Install CUDA 10.0 and cuDNN v7.4.2 on Ubuntu 16.04

Check out this tutorial on my blog: https://matheustguimaraes.com/blog/cuda-cudnn-ubuntu-installation

Install the latest NVIDIA driver

Update package lists, download and install NVIDIA driver

sudo apt-get update
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt install nvidia-410

Reboot

Restart the computer

reboot

Testing

Lets test if all worked well

nvidia-smi

If appears something like:

Sun Jan 27 15:33:47 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.78       Driver Version: 410.78       CUDA Version: 10.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce MX130       Off  | 00000000:01:00.0 Off |                  N/A |
| N/A   49C    P5    N/A /  N/A |    495MiB /  2004MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1091      G   /usr/lib/xorg/Xorg                           285MiB |
|    0      2014      G   compiz                                       103MiB |
|    0      2263      G   ...quest-channel-token=6295865577498169014   103MiB |
+-----------------------------------------------------------------------------+

The driver was installed.

Download CUDA Toolkit

Download the CUDA Toolkit on NVIDIA official website https://developer.nvidia.com/cuda-downloads

You have to make some choices about your machine to download the file

My machine:

  • Linux
  • x86_64
  • Ubuntu
  • 16.04
  • runfile (local)

Go to the download folder

After download the file, go to the download folder:

cd Downloads

Run the file

sudo sh cuda_10.0.130_410.48_linux.run

You have to make some choices in the terminal:

  • Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81? n
  • Install the CUDA 10.0 Toolkit? y
  • Do you want to install a symbolic link at /usr/local/cuda? y
  • Install the CUDA 10.0 Samples? y

Leave the rest as default. ENTER

Testing

Let's test if everything worked well

cd /usr/local/cuda/samples
sudo make -k
./deviceQuery

If appears something like:

./deviceQuery Starting...

 CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce MX130"
  CUDA Driver Version / Runtime Version          10.0 / 10.0
  CUDA Capability Major/Minor version number:    5.0
  Total amount of global memory:                 2004 MBytes (2101870592 bytes)
  ( 3) Multiprocessors, (128) CUDA Cores/MP:     384 CUDA Cores
  GPU Max Clock rate:                            1189 MHz (1.19 GHz)
  Memory Clock rate:                             2505 Mhz
  Memory Bus Width:                              64-bit
  L2 Cache Size:                                 1048576 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
  Maximum Layered 2D Texture Size, (num) layers  2D=(16384, 16384), 2048 layers
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  2048
  Maximum number of threads per block:           1024
  Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
  Max dimension size of a grid size    (x,y,z): (2147483647, 65535, 65535)
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  Device supports Unified Addressing (UVA):      Yes
  Device supports Compute Preemption:            No
  Supports Cooperative Kernel Launch:            No
  Supports MultiDevice Co-op Kernel Launch:      No
  Device PCI Domain ID / Bus ID / location ID:   0 / 1 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.0, CUDA Runtime Version = 10.0, NumDevs = 1
Result = PASS

The library was installed!

Install cuDNN

Download cuDNN v7.4.2 (Dec 14, 2018), for CUDA 10.0

Download the cuDNN on NVIDIA official website https://developer.nvidia.com/cudnn

NOTE: You have to sign up at NVIDIA website before

Download the three packages:

  • cuDNN Runtime Library for Ubuntu16.04 (Deb)
  • cuDNN Developer Library for Ubuntu16.04 (Deb)
  • cuDNN Code Samples and User Guide for Ubuntu16.04 (Deb)

Go to downloads folder

cd Downloads

Install the .deb packages

sudo dpkg -i libcudnn7_7.4.2.24-1+cuda10.0_amd64.deb
sudo dpkg -i libcudnn7-dev_7.4.2.24-1+cuda10.0_amd64.deb 
sudo dpkg -i libcudnn7-doc_7.4.2.24-1+cuda10.0_amd64.deb

Export CUDA path

export LD_LIBRARY_PATH=/usr/local/cuda-10.0/lib64:$LD_LIBRARY_PATH
export PATH=/usr/local/cuda-10.0/bin:$PATH

Reload bash

source ~/.bashrc

Testing

Go in your /usr/src and copy the 'cudnn_samples_v7' to any folder you want, to test if all worked well. In my case, I paste it in 'Desktop' folder.

cd Desktop/cudnn_samples_v7/mnistCUDNN/
make clean && make
./mnistCUDNN

If appears something like:

cudnnGetVersion() : 7402 , CUDNN_VERSION from cudnn.h : 7402 (7.4.2)
Host compiler version : GCC 5.4.0
There are 1 CUDA capable devices on your machine :
device 0 : sms  3  Capabilities 5.0, SmClock 1189.0 Mhz, MemSize (Mb) 2004, MemClock 2505.0 Mhz, Ecc=0, boardGroupID=0
Using device 0

Testing single precision
Loading image data/one_28x28.pgm
Performing forward propagation ...
Testing cudnnGetConvolutionForwardAlgorithm ...
Fastest algorithm is Algo 1
Testing cudnnFindConvolutionForwardAlgorithm ...
^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.034528 time requiring 0 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.038624 time requiring 3464 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.040992 time requiring 57600 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 4: 0.174656 time requiring 207360 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.440832 time requiring 2057744 memory
Resulting weights from Softmax:
0.0000000 0.9999399 0.0000000 0.0000000 0.0000561 0.0000000 0.0000012 0.0000017 0.0000010 0.0000000 
Loading image data/three_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000000 0.0000000 0.9999288 0.0000000 0.0000711 0.0000000 0.0000000 0.0000000 0.0000000 
Loading image data/five_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 0.9999820 0.0000154 0.0000000 0.0000012 0.0000006 

Result of classification: 1 3 5

Test passed!

Testing half precision (math in single precision)
Loading image data/one_28x28.pgm
Performing forward propagation ...
Testing cudnnGetConvolutionForwardAlgorithm ...
Fastest algorithm is Algo 1
Testing cudnnFindConvolutionForwardAlgorithm ...
^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.036960 time requiring 0 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.051584 time requiring 3464 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.066176 time requiring 28800 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 4: 0.199936 time requiring 207360 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.516160 time requiring 2057744 memory
Resulting weights from Softmax:
0.0000001 1.0000000 0.0000001 0.0000000 0.0000563 0.0000001 0.0000012 0.0000017 0.0000010 0.0000001 
Loading image data/three_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000714 0.0000000 0.0000000 0.0000000 0.0000000 
Loading image data/five_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 1.0000000 0.0000154 0.0000000 0.0000012 0.0000006 

Result of classification: 1 3 5

Test passed!

You installed it everything with great success.

Everything is ready for you to use the GPU and do great things.

Have a nice day!

@arun-ghontale

This comment has been minimized.

Copy link

@arun-ghontale arun-ghontale commented Sep 9, 2019

It would be useful to have this line before the first line i.e. 'sudo apt-get update':
"sudo add-apt-repository ppa:graphics-drivers/ppa"

@uzairrizwan

This comment has been minimized.

Copy link

@uzairrizwan uzairrizwan commented Mar 3, 2020

After installing Cuda, I had to compile the files at /usr/local/cuda/samples/ using: sudo make -k before the Testing part.
Only then did my Testing succeeded.

@ishfaq-gist

This comment has been minimized.

Copy link

@ishfaq-gist ishfaq-gist commented Mar 16, 2020

After installing Cuda, I had to compile the files at /usr/local/cuda/samples/ using: sudo make -k before the Testing part.
Only then did my Testing succeeded.

thanks

@matheustguimaraes

This comment has been minimized.

Copy link
Owner Author

@matheustguimaraes matheustguimaraes commented Mar 19, 2020

Thanks for the tip! Just updated the gist with cd /usr/local/cuda/samples and sudo make -k

@HaxThePlanet

This comment has been minimized.

Copy link

@HaxThePlanet HaxThePlanet commented Apr 13, 2020

Thanks for this, worked well!

@matheustguimaraes

This comment has been minimized.

Copy link
Owner Author

@matheustguimaraes matheustguimaraes commented Aug 27, 2020

Good to know! I appreciate the feedback

@MuhammadAsadJaved

This comment has been minimized.

Copy link

@MuhammadAsadJaved MuhammadAsadJaved commented Oct 30, 2020

How we can check cudnn version if installed using .deb? if we installed using .run we can check using
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

@Harsha-1729

This comment has been minimized.

Copy link

@Harsha-1729 Harsha-1729 commented Dec 3, 2020

Hi
Thank you. It worked for me.

After Installing I could see 2 versions of cudnn as follows

image

image

When I have installed tensorflow-gpu==1.5 version and try to check the version, ERROR: 'Failed to load the native TensorFlow runtime' is shown. So when I have checked the reason in https://www.tensorflow.org/install/source#common_installation_problems
I could see this information:

image

So, Now I need only 1 cudnn to be on my pc. I want to uninstall cudnn 7.4.2.
How can I do that

thanks in advance
regards
harsha

@Harsha-1729

This comment has been minimized.

Copy link

@Harsha-1729 Harsha-1729 commented Dec 3, 2020

Hi
Thank you. It worked for me.

After Installing I could see 2 versions of cudnn as follows

image

image

When I have installed tensorflow-gpu==1.5 version and try to check the version, ERROR: 'Failed to load the native TensorFlow runtime' is shown. So when I have checked the reason in https://www.tensorflow.org/install/source#common_installation_problems
I could see this information:

image

So, Now I need only 1 cudnn to be on my pc. I want to uninstall cudnn 7.4.2.
How can I do that

thanks in advance
regards
harsha

uninstall command: sudo apt-get --purge remove libcudnn7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment