in , , ,

How To Install Python TensorFlow 2.8.0 GPU On Ubuntu 20.04 LTS

Install TensorFlow 2.8.0 on ubuntu 20.04 LTS

In this lab, we will make our Ubuntu 20.04 LTS ready to run The Python machine learning and deep learning library TensorFlow 2.8.0 GPU with other ML libraries and dependencies.

Step1: Update Ubuntu Linux

# apt update
# apt upgrade

Step2: Install Python And PIP

# apt install python3 python-is-python3 python3-dev pip virtualenv

Step3: Install And Check Prerequests

Pre-Requests Packages

Now we need to make sure that all Linux required headers are installed.

# apt install linux-headers-$(uname -r) -y

Check If Build-Essential development libraries and tools are installed

# apt install build-essential

Detect GPU CUDA Support

Check your GPU Graphic Card for the CUDA Enabled feature, the compute capability listed here for Nvidia CUDA GPUs Graphic Cards.

# lspci | grep -i nvidia

If (you found your GPU Card is CUDA Supported) { continue applying the following steps } else { Skip CUDA and cuDNN Installation Step }.

Check TensorFlow Requirements

TensorFlow-2.8.0 Requirements

As listed for Tensorflow-2.8.0 version environment requirements we need to install cuDNN 8.1 and CUDA 11.2

Install Nvidia CUDA Driver Official Repository

According to the requirements version we will use the Nvidia CUDA Driver repository for Ubuntu 18.04 LTS, It’s OK and compatible with Ubuntu 20.04 LTS

# wget -O /etc/apt/preferences.d/cuda-repository-pin-600 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
# apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
# add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
# apt-get update

Install Nvidia Machine Learning Repository

We will install the TensorRT the machine learning framework, so we have to install the Nvidia Machine Learning repository as the following.

Note that TensorRT requires cuDNN libcudnn8 to be installed, anyway, it’s optionally for TensorFlow. to improve performance and latency in some models.

# wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
# apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
# apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
# apt update

Step3: Install CUDA 11.2 And cuDNN 8.1

You can detect and select the correct version from the repository URL of the packages list.

# apt install --no-install-recommends cuda=11.2.0-1
# apt install --no-install-recommends libcudnn8=8.1.0.77-1+cuda11.2 libcudnn8-dev=8.1.0.77-1+cuda11.2
# echo 'export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}' >> ~/.bashrc

Step4: Install TensorRT

# apt install --no-install-recommends libnvinfer7=7.2.2-1+cuda11.0 libnvinfer-dev=7.2.2-1+cuda11.0 libnvinfer-plugin-dev=7.2.2-1+cuda11.0 libnvinfer-plugin7=7.2.2-1+cuda11.0

Step5: Install TensorFlow 2.8.0

Install extra packages

# apt install libfreetype6-dev libhdf5-serial-dev libzmq3-dev unzip zip zlib1g-dev libcurl3-dev curl clang-format gcc-7 g++-7 openjdk-8-jdk

We can create a symbolic link for the libcuda stub to the location where TensorFlow is searching for it, then ldconfig

# ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/stubs/libcuda.so.1
# echo "/usr/local/cuda/lib64/stubs" > /etc/ld.so.conf.d/z-cuda-stubs.conf 
# ldconfig

Install TensorFlow 2.8.0

# python3 -m pip install --no-cache-dir tensorflow

Test Your Installation

You can test your installation by running the script

import tensorflow as tf
tf.test.gpu_device_name()

Extend Your libraries

# python -m pip --no-cache-dir install Pillow h5py keras_preprocessing tb-nightly matplotlib mock numpy scipy sklearn pandas future portpicker enum34

Note That: If you are not the root user while using nvcc or CUDA tools, you will need to sudo commands to be run as the superuser, and we need to append the CUDA tools bin directory /usr/local/cuda/bin to the secure_path value at the /etc/sudoers file.

# visudo /etc/sudoers
~~~~
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/local/cuda/bin"

# Host alias specification
~~~~

What do you think?

18 Points
Upvote Downvote

Leave a Reply

Your email address will not be published. Required fields are marked *

Install Odoo 15 On Ubuntu 20.04LTS

Install Odoo 15 The OpenERP On Ubuntu 20.04LTS… Quick Start Guide

ubuntu nvidia driver with cuda and cudnn

How To Install Ubuntu Nvidia Driver With CUDA And cuDNN