Tensorflow-gpu installation
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.
sudo apt-get purge nvidia*
sudo reboot
After these steps, you have installed the nvidia driver and ‘nvidia-smi’ commad should give you some information about the GPU.
sudo apt-get install nvidia-390
Download cuda9.0 installation file from nvidia site.
Change the permission of the downloaded file
sudo chmod +x cuda_9.0.176_384.81_linux.run
./cuda_9.0.176_384.81_linux.run
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.
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:
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*
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/cuda/extras/CUPTI/lib64"
export CUDA_HOME=/usr/local/cuda
export PATH="$PATH:/usr/local/cuda/bin"
source ~/.bashrc
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.
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
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:
conda create -n tensorflow_gpu
source activate tensorflow_gpu
pip install tensorflow-gpu
hello = tf.constant(‘Hello there!’)
print(sess.run(hello))
```