I wrote this post to simplify the installation process of gpu version of TensorFlow on Ubuntu 18.04. I have described installation steps below and hope that it will be helpful.
Check the nvidia driver is installed by running the command ‘nvidia-smi’
Normally, the command will be installed as part of the driver and expected to get the result below.
If you are not able to see the result like above picture, it may be due to either nvidia driver is not installed or nvidia-smi utility is missing. I had to run the below to install the nvidia driver and was successful with installation.
Only follow below steps if you can’t get information like above.
- Run the below code to uninstall the existing nvidia driver and restart.
sudo apt-get purge nvidia*
2. Run the below code to install the nvidia driver 390 at the time of this post writing.
sudo apt-get install nvidia-390
After these steps, you have installed the nvidia driver and ‘nvidia-smi’ commad should give you some information about the GPU.
CUDA 9.0 installation
- Download cuda9.0 installation file from nvidia site.
2. Change the permission of the downloaded file
sudo chmod +xcuda_9.0.176_384.81_linux.run
3. The run the file
Accept the terms and condition and make sure you type ‘no’ to the accelerated graphics driver installation question. Also make sure type ‘yes’ to symoblic link question.
CUDANN 7.2.1 installation
Next, Download the file from nvidia site.
Please make sure you have downloaded the first option cuDNN v7.2.1 Library for Linux.
Once you have downloaded, follow the below steps:
- Extract and copy
sudo tar -xzvf
sudo cp cuda/include/cudnn.h /usr/local/cuda/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
2) Copy below commands to ~/.bashrc
3) Run the below command to source
At this stage we have installed all the required software for tensorflow-gpu version to work. Now, we need to install the miniconda software that will enable us to create python virtual environments.
During the installation, it will be asked to append the path to ~/.bahrc and type yes to append them.
Finally, we are ready to install the gpu version of TensorFlow. We need to run below steps to get there:
- Create virtual environment.
conda create -n tensorflow_gpu
2. Get into the environment
source activate tensorflow_gpu
3. Install tensorflow-gpu
pip install tensorflow-gpu
4. Check the installation by create a file called ‘test.py’ and add below commands to it
import tensorflow as tf
hello = tf.constant('Hello there!')
5. Run ‘python test. py’ and you should be able to get ‘Hello there!’ message that is he indication gpu version TensorFlow has been installed successfully. Otherwise, Installation failed.
You can see similar write up in Github repo.
Source: Deep Learning on Medium