This guide attempts to highlight a process of installing CUDA 11 on UBUNTU 18.04 LTS.
This post is inspired by the following blog post on pyimagesearch on installing Tensorflow 2.0.
Its not by any means a comprehensive guide as hardware differs but it aims to hopefully get you up and running asap.
The steps documented below applies for both new installs or to update an existing CUDA install.
Hardware and operating system tested
Ubuntu 18.04 LTS with GeForce GTX 1060
Pre-install step
Update and install system dependencies:
Update / Install nvidia device driver
Add PPA for nvidia device drivers and install nvidia-driver-470
CUDA 11.3 only works for versions of device drivers >= 465.
Note: for Ubuntu, the 465 driver is linked to the 470 driver so there is no dedicated 465 version
Install device driver:
After install/update, reboot the system.
Check that the device driver is working by running nvidia-smi
If it works, you should see the device driver version and the GPU hardware in the display.
As an additional sanity check, you can also bring up NVIDIA Xserver settings and check that it has picked up the right device driver version and GPU.
Note that the nvidia-smi utility is installed through the drivers and is independent of CUDA.
Installing CUDA
For the purposes of this guide we are installing CUDA 11.3 in order to install and run tensorflow 2.6.0. This is to overcome the issue of the missing libcudart.11.0 library.
For CUDA 11.3, you need the device driver to be at least >= 465, hence we installed 470 of the driver above.
Easiest way to install CUDA is to download and run the installer.
This will bring up an install screen. Uncheck the 465 driver option. This is IMPORTANT else it will corrupt the device driver since we have already installed it in step 1.
Keep the remaining options as it is.
After installation, it will copy the cuda libs to /usr/local/cuda-11.3
and makes a symlink to /usr/local/cuda
To check that cuda is installed, run nvcc compiler:
Note that the CUDA version reported in nvidia-smi will not match the current installed version.
Update ~/.bashrc by setting the LD_PATH and PATH variables for cuda:
Install CUDNN
The CUDNN library is required by tensorflow.
The approach I took was to install using the deb file from the nvidia cuda repo. The version of libcudnn after the + symbol has to match with the installed cuda version.
For example, if we have cuda 11.3 then we need to install the deb files with ..+cuda11.3.. in the suffix.
NOTE: You need to ensure that you don’t have existing versions of CUDNN before installing a newer version. TF will pick up the older version and will throw a mismatch CUDNN version
error during invocation.
Install TensorRT libs
To run TensorRT, we need to install the libnvinfer libraries. These would require cuda-nvrtc libraries as dependencies else the install would fail.
Again, ensure that the cuda versions in the filenames match the actual installed cuda version.
Install Tensorflow
I tend to create a venv to test any new install of tensorflow as it has multiple dependencies which may or may not conflict with existing packages.
Firstly, we need to export the LD_PATH to include CUPTI from CUDA. Then we create a venv and install tensorflow:
Test tensorflow install
While still in activated venv, run following test script:
If all goes well, should see output similar to this:
Important lines are device /job:localhost/replica:0/task:0/device:GPU:0 which indicates that TF is able to locate and access the GPU device.
Pre-built docker images
An alternative is to run tensorflow locally using one of the prebuilt Tensorflow docker image and bind-mount a local directory into the running container: