Setting up TensorRT Environment on Ubuntu 22.04 / 20.04

Summary

Ubuntu 22.04 or Ubuntu 20.04

NVIDIA driver version: 535 (535.129.03)

CUDA version: 12.1.1

cuDNN version: 8.9.7 for CUDA 12.X

TensorRT version: 8.6 GA

Installing CUDA

Follow the official instructionarrow-up-right, download CUDA from herearrow-up-right.

Select CUDA 12.4.0 (March 2024), and then execute the commands prompted by the instruction on the website.

Here's an example set of commands to run:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-ubuntu2204.pin
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb
sudo dpkg -i cuda-repo-ubuntu2204-12-4-local_12.4.0-550.54.14-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-12-4-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-4

After installation, add CUDA to ~/.bashrc:

To test cuda installation, run the following command. The system should be able to find nvcc.

circle-info

Note:

nvidia-smi might fail to run with the following error:

This happens when the CUDA we installed is a different version than the one comes with the driver. If this happens, reboot the system to let nvidia-smi reload the correct CUDA.

After reboot:

Installing cuDNN

Follow the official instructionarrow-up-right, download cuDNN herearrow-up-right.

Select "cuDNN v9.3.0, for CUDA 12.x" with the .deb file option, and then execute the commands prompted by the instruction on the website.

Here's an example set of command to run:

(might not need do the following)

Install the runtime library.

Install the developer library.

Install the code samples.

run the test program to see if success

https://forums.developer.nvidia.com/t/verify-cudnn-install-failed/167220/4arrow-up-right

Installing TensorRT

There are two parts of TensorRT installation

TensorRT GA

Goto https://developer.nvidia.com/tensorrtarrow-up-right

Download both the "TensorRT 10.3 GA for Linux x86_64 and CUDA 12.0 to 12.5 TAR Package" and the DEB package

circle-exclamation

Install the DEB package with Software Install.

Alternatively, do the following commands

We also need to link the libraries. Unpack the tar package:

Then. move the unpacked directory to the installation path (~/Documents/), and add to bashrc

Install to Python using the following command

For TensorRT < 10.3, it might also need this dependency

TensorRT OSS

Seems that normally we don't need this thing.

For python:

Other Dependencies

Final Step

Follow this repo to use TRT

FAQ

solution:

the key is not installed. run the command in "Installing TensorRT" again

Last updated