Tensorflow GPU Installation on Ubuntu 18.04
This article is about complete installation step for Tensorflow-GPU on Ubuntu 18.04 .As we can check that NVIDIA have supported driver and CUDA version for respective NVIDIA product.
Step1: NVIDIA driver version
First check what is the version of NVIDIA driver on your GPU system.You can check it with below command.
nvidia-smi
As like same you have to cross check driver version and if it is not there ,you have to install first.
Steps for installation of NVIDIA driver:
Click here to select your NVIDIA product information to select graphics driver and follow the instructions.
Step2: Install CUDA toolkit
First check here recommended version for tensorflow, cuDNN and CUDA .
For example if you are using Tensorflow version 1.12.0 then CUDA version 9.0 and cuDNN 7.0 is recommended.
Once you downloaded the file, you have to run below command.
sudo dpkg -i cuda-repo-ubuntu1804–10–0-local-10.0.130–410.48_1.0–1_amd64.deb
sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
sudo apt-get update
sudo apt-get install cuda
In the installation step , make sure that again you do not agree to install new driver.
Step3 : Install CUDNN
Click here and select the option ‘Download cuDNN’ then join or login with your membership details and find the recommended version of cuDNN as given above.
Once you get download your CUDA version archive , run below command.
# Unpack the archive
tar -zxvf cudnn-9.0-linux-x64-v7.tgz# Move the unpacked files 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/# Change file access to all users
sudo chmod a+r /usr/local/cuda-9.0/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
Step 4: Install libcupti
Run below command for this.
sudo apt-get install libcupti-dev
Step 5: Set the Environment Variable
On command prompt tensorflow will find the CUDA installation to use for GPU enabling. You have to set your environment variable for this.
Open .bashrc file and append below lines and source to the file.
export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
After source , restart your terminal.
Step 6: Install your Tensorflow-GPU
For Python3 version:
pip3 install –upgrade tensorflow-gpu
For Python 2 version :
pip install –upgrade tensorflow-gpu
Step7: Verify your installation
With the installed version of your python , run below command on ternimal and verify that your Tensorflow is running on the GPU.
Python3
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
Note: We should check the compatibility of Tensorflow ,CUDA and cuDNN in case of any particular application.
Happy learning…