Linux (Ubuntu) and NVIDIA GPU support
If you want to use tensorflow-gpu
, Flux.jl
or any other library that benefits from GPU parallelisation, then you need to setup:
- Appropriate NVIDIA drivers
- CUDA
- cuDNN
Step 1: Installing appropriate drivers
In Linux Mint the appropriate NVIDIA drivers can be hard to determine, as the latest drivers on the NVIDIA website may not necessarily be the most ideal ones, a fact accepted by NVIDIA themselves in the Additional Information section when trying to download drivers here.
A foolproof method is as follows:
- Fire up the terminal and run
sudo add-apt-repository ppa:graphics-drivers/ppa
followed bysudo apt-get update
. This allows the system to search for the latest drivers. - Then run
ubuntu-drivers devices
. The output should mention your graphic card and the recommended driver. - Install the driver by running
sudo apt-get install nvidia-driver-xxx nvidia-settings nvidia-prime
wherexxx
is the driver number recommended in the previous step. In my case this wasnvidia-driver-430
(ASUS GX531 running RTX 2070, as of September 24, 2019). - Reboot, if you’re able to log in, run
nvidia-smi
in the terminal. If the output mentions the GPU ands the driver you installed, you are done!- If you enter a black screen on reboot, press
Ctrl+Shift+F2
to fire uptty
. Use your login credentials and typesudo apt-get remove --purge nvidia*
followed bysudo apt-get install --reinstall xorg xserver-xorg
. - Running
reboot
restarts the computer and you should be back to the integrated drivers. Repeat driver installation steps, but this time with different (lower) driver numbers. For example, the recommended driver for RTX 2070 is 418, but I could only get 410 to work, which is still compatible with CUDA 10.
- If you enter a black screen on reboot, press
ISSUES: Although this method always works, it has multiple disadvantages. Firstly, the CUDA installation in the next step can mess up the drivers again. Secondly, the drivers that do work are always outdated. Updating them as you update CUDA and cuDNN can lead to clashes as well.
Step 2: Install CUDA
Check the appropriate CUDA version for the driver installed in Step 1
here. Follow the instructions to install from the CUDA website. If using Debian based distros, make sure to use the appropriate .deb
files for installation. After installing CUDA with apt-get
, also install nvidia-cuda-toolkit
in the same way
Step 3: Install cuDNN
Get cuDNN from here and follow the installation instructions. The copy-paste technique works best!
Final step: Get GPU dependent packages working!
I use Flux.jl
(julia) and tensorflow
(python) for GPU-related tasks. Both these packages rely on a proper CUDA installation. In my experience, installing tensorflow
from conda ensures proper CUDA installation for python.
You can now check if CUDA works on these two packages.
1. Tensorflow
Check using the following code
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
2. Julia
Check with CUDAnative
and CuArrays
by first installing with
import Pkg
Pkg.Add("CUDAnative")
Pkg.Add("CuArrays")
and then running
] test CuArrays
Bypass all above methods using Docker
I haven’t tried this but it is recommended by folks at TensorFlow: https://www.tensorflow.org/install/docker