Installing TensorRT on Ubuntu20.04
1. Install CUDA, cuDNN
CUDA:
(1) Remove old version
sudo apt-get purge nvidia*sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /usr/local/cuda*
(2) Download and install CUDA toolkit 11.3 [1]
$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
$ sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
$ wget https://developer.download.nvidia.com/compute/cuda/11.3.0/local_installers/cuda-repo-ubuntu2004-11-3-local_11.3.0-465.19.01-1_amd64.deb
$ sudo dpkg -i cuda-repo-ubuntu2004-11-3-local_11.3.0-465.19.01-1_amd64.deb
$ sudo apt-key add /var/cuda-repo-ubuntu2004-11-3-local/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get -y install cuda
(3) Check
$ cd /usr/local/cuda-11.3/samples/1_Utilities/deviceQuery
$ sudo make
$ ./deviceQuery
ex:
cuDNN:
(1) Download cuDNN 8.2.1 [2]
(2) Install
extract cudnn-11.3-linux-x64-v8.2.1.32.tgz$ cd cuda
$ sudo apt-key add /var/nv-tensorrt-repo-ubuntu2004-cuda11.3-trt8.0.1.6-ga-20210626/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get install tensorrt
$ sudo apt-get install python3-libnvinfer-dev
$ sudo cp cuda/include/cudnn.h /usr/local/cuda-11.3/include/
$ sudo cp cuda/include/cudnn_version.h /usr/local/cuda-11.3/include/
$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda-11.3/lib64/
$ sudo chmod a+r /usr/local/cuda-11.3/include/cudnn.h
(3) Check
$ cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
2. Download the corresponding .deb file for installing TensorRT [3]
* EA version stands for early access (It is before actual release). GA stands for general availability. GA is stable version and completely tested.
$ sudo dpkg -i nv-tensorrt-repo-ubuntu2004-cuda11.3-trt8.0.1.6-ga-20210626_1-1_amd64.deb$ sudo apt-key add /var/nv-tensorrt-repo-ubuntu2004-cuda11.3-trt8.0.1.6-ga-20210626/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get install tensorrt
$ sudo apt-get install python3-libnvinfer-dev
Check:
$ dpkg -l | grep TensorRT
* Remember to install pycuda for using tensorrt in Python
$ pip3 install 'pycuda<2021.1'or
Download the source file [4]
$ ./configure.py
$ make
$ sudo make install
* Useful command for checking Ubuntu, CUDA, cuDNN version
Ubuntu:
$ lsb_release -a
CUDA:
$ nvcc -V
or
$ nvidia-smi
or
$ import torch
$ print(torch.version.cuda)
cuDNN:
cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
or
$ import torch
$ print(torch.backends.cudnn.version())
Reference:
[1] CUDA Toolkit 11.3 Downloads
[2] cuDNN Library for Linux (x86_64)
[3] https://developer.nvidia.com/nvidia-tensorrt-8x-download
[4] https://pypi.org/project/pycuda/#modal-close
[5] https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html
留言
張貼留言