How can I install CuDNN on Ubuntu 16.04?
Solution 1
Step 0: Install cuda from the standard repositories. (See How can I install CUDA on Ubuntu 16.04?)
Step 1: Register an nvidia developer account and download cudnn here (about 80 MB)
Step 2: Check where your cuda installation is. For the installation from the repository it is /usr/lib/...
and /usr/include
. Otherwise, it will be /usr/local/cuda/
or /usr/local/cuda-<version>
. You can check it with which nvcc
or ldconfig -p | grep cuda
Step 3: Copy the files:
Repository installation:
$ cd folder/extracted/contents
$ sudo cp -P include/cudnn.h /usr/include
$ sudo cp -P lib64/libcudnn* /usr/lib/x86_64-linux-gnu/
$ sudo chmod a+r /usr/lib/x86_64-linux-gnu/libcudnn*
Runfile installation:
$ cd folder/extracted/contents
$ sudo cp include/cudnn.h /usr/local/cuda/include
$ sudo cp lib64/libcudnn* /usr/local/cuda/lib64
$ sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
Solution 2
From 5.1 onwards you can't install according to what @Martin mentioned.
Download libcudnn6_6.0.21-1+cuda8.0_amd64.deb, libcudnn6-dev_6.0.21-1+cuda8.0_amd64.deb, libcudnn6-doc_6.0.21-1+cuda8.0_amd64.deb
from nvidia site and install one by one follwing way.
sudo dpkg -i <library_name>.deb
Edit: You must first install runtime (libcudnn6_6.0.21-1+cuda8.0_amd64.deb) because dev depends on the runtime (Thanks @tinmarino)
Solution 3
- Register on NVidia's website. It may take a day, or two before they'll get your account approved. At least that used to be the case back when I registered.
-
Download and Install latest CUDA from NVidia, or the latest version that fits the software you'll be working with, if any, in this case your version of T-Flow.
Note, that installing via ubuntu's standard package manager via clicking probably won't work appropriately.
Instead, you'll probably have to follow these instructions in the terminal to install
.deb
pakage. After that you'll have to add a few lines to.bashrc
, or wherever appropriate in your case. For example, if you're configuring a server, it's probably going to be a different place, maybe somewhere prior to your app's autolaunch, as.bashrc
will probably not get executed in that case. -
I used the "Library for Linux" version, didn't have much luck with
.deb
packages. You can find where CUDA is located via
which nvcc
. Usually/usr/local/cuda/
will be a symbolic link to your currently installed version.- Open CuDNN archive and copy appropriate contents into appropriate places within CUDA installation folder (
cuda/lib64/
andcuda/include/
). I usuallysudo nautilus
and do it from there visually.
Solution 4
Fast forward 2018 and NVIDIA now provides cuDNN 7.x for download. The installation steps are still similar with those described by @GPrathap. But if you want to replace the old cuDNN version with the newer one, you need to remove it first prior to the installation.
To recap:
Step 0. Verify that you already have installed CUDA toolkit. Proceed with CUDA toolkit installation if you haven't.
Step 1. Go to NVIDIA developer portal https://developer.nvidia.com/cudnn and download cuDNN.
Step 2. If you have previously installed cuDNN, remove it
sudo dpkg -r <old-cudnn-runtime>.deb
sudo dpkg -r <old-cudnn-dev>.deb
Step 3. Install the cuDNN library (runtime, dev, doc) using dpkg
sudo dpkg -i <new-cudnn-runtime>.deb
sudo dpkg -i <new-cudnn-dev>.deb
sudo ldconfig
Step 4. If you want to find where the library was installed you can update the locate index and then find the library location.
sudo updatedb
locate libcudnn
If you are specifically installing cuDNN 7.x against CUDA toolkit 9.1, this article provides more elaboration that can be of some help: http://tech.amikelive.com/node-679/quick-tip-installing-cuda-deep-neural-network-7-cudnn-7-x-library-for-cuda-toolkit-9-1-on-ubuntu-16-04/
Solution 5
Also, you can download the deb packages for Debian based distributions.
From the NVIDIA web page, for the developer profile are available the next files :
- cuDNN v5.1 Runtime Library for Linux (Deb)
- cuDNN v5.1 Developer Library for Linux (Deb)
- cuDNN v5.1 Code Samples and User Guide Linux (Deb)
I tested this, over my machine with Debian (Stretch) and TensorFlow is working !
Related videos on Youtube
Martin Thoma
I also have a blog about Code, the Web and Cyberculture and a career profile on Stackoverflow. My interests are mainly machine-learning, neural-networks, data-analysis.
Updated on September 18, 2022Comments
-
Martin Thoma over 1 year
For TensorFlow I would like to install cuda and CuDNN. How do I do that on Ubuntu 16.04?
-
wordsforthewise about 7 yearsWarning: if you're trying to run tensorflow and need cudnn, make sure to install 5.1 and not 6.0 for now.
-
ComputerScientist over 6 years@wordsforthewise CuDNN 6.0 is now supported (for TF 1.4 at least).
-
-
Max Gordon almost 8 yearsAdding
-P
retains the symbolic links, i.e.sudo cp -P lib64/libcudnn* /usr/lib/x86_64-linux-gnu/
, and avoids the message:/sbin/ldconfig.real: /usr/lib/x86_64-linux-gnu/libcudnn.so.5 is not a symbolic link
-
mastazi almost 8 yearsPlease note that as of now (July 2016) cuDNN v5.1 won't work with TensorFlow unless you compiled it from source, see tensorflow.org/versions/r0.9/get_started/os_setup.html
-
Brent Bradburn over 7 yearsUpdate from here: "Download cuDNN v4 (v5 is currently a release candidate and is only supported when installing TensorFlow from sources)."
-
David Stutz over 7 yearsFor Tensorflow to find everything, I had to copy
include/cudnn.h
and the libraries inlib64/
to/usr/local/cuda-8.0/include
and/usr/local/cuda-8.0/lib64
(using CUDA 8.0, Ubuntu 14.04, Tensorflow 0.12.0rc0) - maybe this is helpful for somebody. -
sudodus over 7 yearsPlease edit your answer and add the reference, 'the instruction above'.
-
tryingtolearn almost 7 years@MaxGordon Hi, does it matter if I use the runtime library for ubuntu16.04 power8 or the library for linux?
-
Rafael_Espericueta almost 7 yearsThe version listed is incorrect it seems. This one: cuDNN v5.1 Runtime Library for Ubuntu16.04 Power8 (Deb) ..... You may want to try the corresponding version for Ubuntu 14.04. At least that got me to the next step.
-
kangaroo almost 7 yearsJust add comments to @MartinThoma's answer. If you run
sudo chmod a+r /usr/lib/x86_64-linux-gnu/libcudnn*
, it may cause the issue described here. github.com/tensorflow/tensorflow/issues/7522 -
Anuraag Vaidya over 6 yearsThanks. I have fallen into this problem multiple times. Let's just establish a thumb rule. When things don't work, stick to installing using .deb packages.
-
kevins over 6 yearsAnother tip - make sure you install cuda before you install cudnn. Otherwise the cuda installers won't overwrite any /usr/local/cuda directories you may have created.
-
Martin Thoma over 6 years@kevins You cannot install cuDNN without already having cuda
-
Visionscaper over 6 yearsWhen compiling Tensorflow from source it is good to know that the cuDNN library installation path is
/usr/lib/x86_64-linux-gnu/
-
kevins over 6 years@MartinThoma This may be true if installing via the repositories, however, if the user were to install from the tarball he may make the mistake I did and create the missing directories
/usr/local/cuda/lib64/
etc and that will break a subsequent cuda install. -
ComputerScientist about 6 yearsSeems like the library is now about 330 MB!
-
Hossein about 6 yearsThanks @Mike, do you know what the difference is between using the deb files and the ordinary .tar file? which one is recommended and why? (By the way I myself used to install CUDA using the runfile and also use the .tar package for cuDNN in ubuntu)
-
n1k31t4 about 6 yearsAccording to the relevant installation documents from Nvidia, what you say about having to remove the old versions is not correct:
cuDNN v7 can coexist with previous versions of cuDNN, such as v5 or v6.
-
Tinmarino about 5 yearsYou must first install
runtime
decausedev
depends on it