For TensorFlow I would like to install cuda and CuDNN. How do I do that on Ubuntu 16.04?
Ubuntu 16.04 – How to Install CuDNN
16.04cudagpunvidia
Related Solutions
Install CUDA for Ubuntu
There is an Linux installation guide. However, it is basically only these steps:
- Download CUDA: I used the 15.04 version and "runfile (local)". That is 1.1 GB.
- Check the md5 sum:
md5sum cuda_7.5.18_linux.run
. Only continue if it is correct. - Remove any other installation (
sudo apt-get purge nvidia-cuda*
- if you want to install the drivers too, thensudo apt-get purge nvidia-*
.)- If you want to install the display drivers(*), logout from your GUI. Go to a terminal session (ctrl+alt+F2)
- Stop lightdm:
sudo service lightdm stop
- Create a file at
/etc/modprobe.d/blacklist-nouveau.conf
with the following contents:blacklist nouveau options nouveau modeset=0
- Then do:
sudo update-initramfs -u
sudo sh cuda_7.5.18_linux.run --override
. Make sure that you sayy
for the symbolic link.- Start lightdm again:
sudo service lightdm start
- Follow the command-line prompts
See also: NVIDIA CUDA with Ubuntu 16.04 beta on a laptop (if you just cannot wait)
Notes: Yes, there is the possibility to install it via apt-get install cuda
. I strongly suggest not to use it, as it changes the paths and makes the installation of other tools more difficult.
You might also be interested in How can I install CuDNN on Ubuntu 16.04?.
*: Don't install the display drivers with this script. They are old. Download the latest ones from http://www.nvidia.com/Download/index.aspx
Verify CUDA installation
The following command shows the current CUDA version (last line):
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44
The following command shows your driver version and how much GPU memory you have:
$ nvidia-smi
Fri Jan 20 12:19:04 2017
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 367.57 Driver Version: 367.57 |
|-------------------------------+----------------------+----------------------+
| 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 940MX Off | 0000:02:00.0 Off | N/A |
| N/A 75C P0 N/A / N/A | 1981MiB / 2002MiB | 98% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1156 G /usr/lib/xorg/Xorg 246MiB |
| 0 3198 G ...m,SecurityWarningIconUpdate<SecurityWarni 222MiB |
| 0 6645 C python 1510MiB |
+-----------------------------------------------------------------------------+
See also: Verify CuDNN installation
Help! The new driver does not work!
Don't panic. Even if you can't see anything on your computer, the following steps should get you back to the state before:
- Press shift during startup
- Go into a root shell
- Make it writable by running
mount -o remount,rw /
(-
is?
and/
is-
in the american layout) sh cuda_7.5.18_linux.run --uninstall
sudo apt-get install nvidia-361 nvidia-common nvidia-prime nvidia-settings
Graphics drivers
Installing the graphics drivers is a bit tricky. This has to be done without graphics support.
- Log out from your current X session.
- Ctrl+Alt+F4 (you can switch back with Ctrl+Alt+F7)
- You should remove all other drivers before.
- Search for them via
dpkg -l | grep -i nvidia
- Remove them via
sudo apt-get remove --purge nvidia-WHATEVER
- Stop lightdm via
sudo service lightdm stop
- You might need to
reboot
your pc / blacklist the nouveau driver (German tutorial)
I found the answer!
I need to create soft link:
sudo ln -s /usr/local/cuda-9.0/lib64/libcufft.so /usr/lib/libcufft.so.9.0
Then I re-configure with MPI support to false.
After that this command is success!
At global scope:
cc1plus: warning: unrecognized command line option '-Wno-self-assign'
Target //tensorflow/tools/pip_package:build_pip_package up-to-date:
bazel-bin/tensorflow/tools/pip_package/build_pip_package
INFO: Elapsed time: 275.306s, Critical Path: 36.05s
INFO: Build completed successfully, 602 total actions
sam@sam:~/code/download/CNN/tensorflow_1.4/tensorflow$
Then I run:
bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
sam@sam:~/code/download/CNN/tensorflow_1.4/tensorflow$ bazel-bin/tensorflow/tools/pip_package/build_pip_package /tmp/tensorflow_pkg
一 11月 20 09:53:08 CST 2017 : === Using tmpdir: /tmp/tmp.xpC8nRamZR
~/code/download/CNN/tensorflow_1.4/tensorflow/bazel-bin/tensorflow/tools/pip_package/build_pip_package.runfiles ~/code/download/CNN/tensorflow_1.4/tensorflow
~/code/download/CNN/tensorflow_1.4/tensorflow
/tmp/tmp.xpC8nRamZR ~/code/download/CNN/tensorflow_1.4/tensorflow
一 11月 20 09:53:10 CST 2017 : === Building wheel
warning: no files found matching '*.dll' under directory '*'
warning: no files found matching '*.lib' under directory '*'
warning: no files found matching '*.h' under directory 'tensorflow/include/tensorflow'
warning: no files found matching '*' under directory 'tensorflow/include/Eigen'
warning: no files found matching '*' under directory 'tensorflow/include/external'
warning: no files found matching '*.h' under directory 'tensorflow/include/google'
warning: no files found matching '*' under directory 'tensorflow/include/third_party'
warning: no files found matching '*' under directory 'tensorflow/include/unsupported'
~/code/download/CNN/tensorflow_1.4/tensorflow
一 11月 20 09:53:35 CST 2017 : === Output wheel file is in: /tmp/tensorflow_pkg
sam@sam:~/code/download/CNN/tensorflow_1.4/tensorflow$
Then I found that it create tensorflow whl file:
sam@sam:~/code/download/CNN/tensorflow_1.4/tensorflow$ ls /tmp/tensorflow_pkg
tensorflow-1.4.1-cp27-cp27mu-linux_x86_64.whl
sam@sam:~/code/download/CNN/tensorflow_1.4/tensorflow$
Then I remove old tensorflow:
sudo pip uninstall tensorflow-gpu
sudo pip uninstall tensorflow-tensorboard
I install new one that I compiled success!
sudo pip install --upgrade /tmp/tensorflow_pkg/tensorflow-1.4.1-cp27-cp27mu-linux_x86_64.whl
Then I create soft link of CUDA:
sudo ln -s /usr/local/cuda-9.0/lib64/libcusolver.so /usr/lib/libcusolver.so.9.0
Then I test tensorflow success!
sam@sam:~/code/download/lib/cudnn7$ python -c 'import os; import inspect; import tensorflow; print(os.path.dirname(inspect.getfile(tensorflow)))'
/usr/local/lib/python2.7/dist-packages/tensorflow
sam@sam:~/code/download/lib/cudnn7$
Thanks~
Best Answer
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 withwhich nvcc
orldconfig -p | grep cuda
Step 3: Copy the files:
Repository installation:
Runfile installation: