CUDA Deep Neural Network (cuDNN) is a library from NVIDIA that provides the GPU-accelerated primitives for deep learning such as convolution, pooling, normalization, activation layers, tensor transformation. With cuDNN, a machine learning researcher or developer can spend less time writing the implementation for low-level GPU performance tuning. The cuDNN library powers major deep learning frameworks such as Caffe, Caffe 2, Tensor Flow, Cognitive Toolkit and PyTorch.
This post summarizes the steps to install cuDNN 7 for Cuda Toolkit 9.1 on Ubuntu 16.04. Installation for different version of cuDNN and Cuda Toolkit may require additional tweak or different steps that are not covered in this post.
1. Verify that Cuda Toolkit has been installed
To check if Cuda Toolkit has been installed we run this command.
$ nvcc --version
The command should output the information about the Cuda toolkit installed on the system. If the error message “bash: nvcc: command not found” is shown upon invoking the command, we need to install Cuda Toolkit. The installation guide for Cuda Toolkit 9.1 is elaborated in this post.
2. Download the cuDNN library
The cuDNN library is available for download from the cuDNN section of NVIDIA developer portal (URL: https://developer.nvidia.com/cudnn). Download is available only for those with NVIDIA developer accounts. If you do not have a developer account yet, you can simply sign up and have the account created for you.
On the download page, we will be shown with several versions of cuDNN library packages that are available for download. For Cuda Toolkit 9.1, we choose the newest version of cuDNN 7 packages as exemplified in the picture below (newer version may be available in the future). The minimum is to download the “Runtime Library” and “Developer Library” packages.
Note: The developer library contains cuDNN header files that are required when developing a deep learning implementation on the Ubuntu machine. If you will not use the machine to compile any deep learning implementation and only use it for running some deep learning implementation, the “Runtime Library” should suffice.
3. Check previous installation of cuDNN
As NVIDIA constantly updates the cuDNN library, we may have previously installed an older version of the library and perform an installation to update to a newer library. To check if the existing installation of cuDNN, we run this command from the shell
$ dpkg -l | grep cudnn
ii libcudnn7 184.108.40.206-1+cuda9.1 amd64 cuDNN runtime libraries ii libcudnn7-dev 220.127.116.11-1+cuda9.1 amd64 cuDNN development libraries and headers
From the sample output, we have cuDNN runtime library (libcudnn7) and developer library (libcudnn7-dev) installed (the install status code: ii) on the machine. We need to remove those libraries first before installing a newer ones.
To remove the library, we simply use dpkg command again, but with different flag.
– Removing the developer library
$ sudo dpkg -r libcudnn7-dev
– Removing the runtime library
$ sudo dpkg -r libcudnn7
Note: the order of removal matters due to the dependency
After going through the pre-installation steps, we now proceed with the installation as follows.
1. Go to the cuDNN packages download directory
2. Install the package files
From the download page screenshot above, if we download the runtime library and developer library we will have the following files: libcudnn7_18.104.22.168-1+cuda9.1_amd64.deb (runtime) and libcudnn7-dev_22.214.171.124-1+cuda9.1_amd64.deb (dev). We install both library packages with the following command.
$ sudo dpkg -i libcudnn7_126.96.36.199-1+cuda9.1_amd64.deb $ sudo dpkg -i libcudnn7-dev_188.8.131.52-1+cuda9.1_amd64.deb $ sudo ldconfig
3. Verify the installation
We will perform the verification in two steps. First, we check if the library and header file have been copied to the designated folders. Finally, we check both libraries install statuses via dpkg.
– Update the database for locations of files and directories
$ sudo updatedb
– Check if the runtime library file has been copied to /usr/lib directory
$ locate libcudnn
– Check if cuDNN header file has been copied to
$ locate cudnn.h
– Recheck the library install statuses via dpkg
$ dpkg -l | grep cudnn
We should see the output similar with the snippet below.
ii libcudnn7 184.108.40.206-1+cuda9.1 amd64 cuDNN runtime libraries ii libcudnn7-dev 220.127.116.11-1+cuda9.1 amd64 cuDNN development libraries and headers
Installing cuDNN should be straightforward if we have properly installed CUDA toolkit. If you have issues with your cuDNN installation, simply write the elaboration in the comment section.