Installing Tensorflow in Ubuntu 20.04 LTS with GPU support
- Installing CUDA ToolKit 10.1
- Install the cuDNN version compatible with CUDA ToolKit 10.1
- Source Environment Variables
- Downgrade the Numpy and
- Install TensorFlow with GPU support
In Ubuntu 20.04LTS install a proprietary Nvidia Driver from the Additional Drivers software
Preferred versions are <= 535.x
OR one can use the traditional method of installation
$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt install nvidia-driver-525 or 535
Installing pip
$ sudo apt install python3-pip
Install the CUDA ToolKit by running the following command
$ sudo apt install nvidia-cuda-toolkit
Then run this command to verify the installation
$ nvcc --version
Then follow this link to install the cuDNN compatible with the CUDA ToolKit
Click “Download cuDNN v7.6.5 (November 5th, 2019) for CUDA 10.1”, then choose “cuDNN Library for Linux” to download cuDNN 7.6.5 for CUDA 10.1. Follow this link to install : https://developer.nvidia.com/rdp/cudnn-download
Then run the following commands in the terminal in the folder containing the downloaded file
$ tar -xvzf cudnn-10.1-linux-x64-v7.6.5.32.tgz
$ sudo cp cuda/include/cudnn.h /usr/lib/cuda/include/
$ sudo cp cuda/lib64/libcudnn* /usr/lib/cuda/lib64/
$ sudo chmod a+r /usr/lib/cuda/include/cudnn.h /usr/lib/cuda/lib64/libcudnn*
$ echo 'export LD_LIBRARY_PATH=/usr/lib/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
$ echo 'export LD_LIBRARY_PATH=/usr/lib/cuda/include:$LD_LIBRARY_PATH' >> ~/.bashrc
Now load the variables sourced
$ source ~/.bashrc
these may be in higher versions than the supported ones for tf and CUDA so downgrading them to the last supported version will be better
$ pip install protobuf==3.20.0
$ pip install numpy==1.20.0
$ pip install tensorflow==2.2.0
Then enter python3 in the shell to enter python idle shell. Now we will test our installation
>>> import tensorflow as tf
>>> tf.config.list_physical_devices("GPU")
[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
These steps will ensure the successful installation of tensorflow in Ubuntu 20.04 with GPU support.