Content Writing

Configuring GPU Tensorflow on Ubuntu-18.04

Ubuntu comes with opensource ubuntu NVIDIA driver called nouveau. So first step would be disabling it. This tutorial is divided into following parts

  1. Disabling nouveau
  2. Install cuda 9.0 Toolkit for ubuntu 18.04 LTS
  3. Install Cudnn 7.0
  4. Install libcupti
  5. Adding path of cuda toolkit
  6. Installing Tensorflow-GPU on virtual environment

Please see the below image to get with the title of the repository


1. Disabling nouveau

Nouveau is the community/organization that makes the open source drivers for nvidia graphic card. It provides open source drivers. Developers performs reverse enginerring of nvidia proprietary drivers. As we need to build the proprietary drivers for the nvidia, open source ubuntu drivers needs to be disabled. So please type the below code to disable it.

#Create below file
nano /etc/modprobe.d/blacklist-nouveau.conf
#Please update the below content in this file
blacklist nouveau
options nouveau modeset=0
sudo update-initramfs -u
lsmod | grep nouveau

After this step,it is important to download the version of the nvidia drivers which is recommended for the ubuntu system. Please type the below command in the terminal

ubuntu-drivers devices | grep "nvidia-driver"

Please see the output for my system. My configuration is GPU [RTX 2080 Ti] on Ubuntu 18.04 LTS.

driver   : nvidia-driver-410 – third-party free
driver   : nvidia-driver-415 – third-party free recommended

2. Install cuda 9.0 Toolkit for Ubuntu 18.04 LTS


cuda is the programming language develped by Nvidia and is only meant for nvidia.GPU processes the tensors or arrays using the GPU cores (cuda cores), where CPU are having only limited cores whereas GPU has a lot of cores and hence the processing capability of GPU is far far better than CPU. It is pci-e which connects CPU with GPU. When task come to the CPU, it transfers it to GPU memory. GPU again transfer it to the CUDA Cores. Result is transfered back to the CPU memory which we see it. To install cuda toolkit for ubuntu 18.04, please remember that official toolkit has come for ubuntu 17.04. But it will also support ubuntu 18.04. Please follow the below link.

  • Before this step, please install Nvidia Drivers (proprietary)
  • Please visit the link and download cuda 9.0 from archives
  • During the above step, you have to login details so make the account on nvidia and download drivers
  • Once the drivers are downloaded, please follow the below instructions
    sudo chmod +x
    ./ --override
  • Please accept the terms and conditions. Say yes to installing with an unsupported configuration, and no to Install NVIDIA Accelerated Graphics Driver for Linux-x86_64_xx

3.Install Cudnn 7.0

This is the next step. Once the cuda drivers are installed , it is important to install Cudnn 7.0.Please follow the below instruction to complete this step.

  • Please click on link and install Cudnn 7.0 for cuda 9.0
  • Now we need to copy the files to the cuda drivers in the ubuntu machine. Please follow the below steps
tar -zxvf cudnn-9.0-linux-x64-v7.tgz
# Move the unpacked contents to your CUDA directory
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda-9.0/lib64/
sudo cp  cuda/include/cudnn.h /usr/local/cuda-9.0/include/
# Give read access to all users
sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h /usr/local/cuda/lib64/libcudnn*

4.Install libcupti

  • Please follow the below instruction to install libcupti
sudo apt-get install libcupti-dev

5.Exporting the path

Please open the file ~./bashrc with your favourite editor such as vim or nano and paste the below code there.

export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} 

6. Installing Tensorflow-GPU on virtual environment

So please install,create and activate the virtual environment using the below steps.

sudo apt install -y python3-venv
python3 -m venv environment_name
source sample_environment/bin/activate

Now, please run the below code to install tensorflow-gpu.

pip3 install --upgrade tensorflow-gpu

Thanks for reading this.