To setup a GPU- Supportfor Nvidia and Tensor flow you need these things
-
You should have nvidia device drivers installed.
-
Check nvidia-smi it should be working.if it is not working dont worry follow the steps
-
You need to downlod CUDA and cuDNN
-
Before downloading CUDA and cuDNN check for the comptability with the tensorflow version
-
Here will be installing tensorflow 2.9.0 so we need to download CUDA 11.2 and cuDNN 8.1
-
Go to https://developer.nvidia.com/cuda-downloads then archive or directly to https://developer.nvidia.com/cuda-toolkit-archive
-
Select the version thatis 11.2 we will click on 11.2.2 which is the ist as in
-
Select Linux then x86 then ubuntu then 20.04 then run file you will get the two steps as below
-
Exectute these two in your ubuntu shell. The first one will download the file and second one for installation.
-
Wait for the menu to pop up and continue the type accept.
-
if your nvidia-smi was not working the check the Driver and CUDA Toolkit11.2. you do not need Samples Demo Suite and Documentation
-
You now have CUDA installed and now you need cuDNN
-
Download cuDNN from this https://developer.nvidia.com/rdp/cudnn-archive
-
Select the compatible version for tensorflow2.9 we need 8.1
-
Click on the link and download the for Linux(x86_64) if you have 64. A tar file will be download
-
Unzip the tar file by thefollowing command
-
tar -xvf file_name
-
You will now have a cuda folder in created in the current directory and the files are extracted there
-
Type these three commands but remeber to check you have cuda folder in you current directory.
-
sudo cp cuda/include/cudnn*.h /usr/local/cuda/include
-
sudo cp -P cuda/lib64/libcudnn* /usr/local/cuda/lib64
-
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
-
open .bashrc file using nano
-
nano ~/.bashrc
-
add these two lines at the end of the file
-
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}$
-
export LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
-
save it and close it.
-
Restart the terminal and check
-
nvidia-smi
-
nvcc -V
-
both shod be working
-
now create an python environment
-
sudo apt-get install -y python3-pip
-
sudo apt-get install -y python3-venv
-
python -m venv environemnt_name
-
activate your environment
-
source environment_name/bin/activate
-
using pip install tensorflow-gpu 2.9.0
-
pip install tensorflow-gpu==2.9.0
-
now you have tensorflow-gpu2.9.0 CUDA 11.2 and cuDNN 8.1 installed
-
wile installing tensorflow-gpu you might get the error of protobuf version comptability issue
-
Solve that using
-
pip install --upgrade protobuf==3.11
-
That is all