1.下载Tensor RT对应的deb包
先要确保cuda和cudnn安装好,https://blog.csdn.net/qq_41246375/article/details/115597025
下载tensor RT,注意版本对应关系
https://developer.nvidia.com/nvidia-tensorrt-8x-download
2.安装
按照官方步骤
https://docs.nvidia.com/deeplearning/tensorrt/install-guide/index.html#downloading
安装 TensorRT 时可以选择以下安装选项;Debian 或 RPM 软件包、Python Wheel 文件、tar 文件或 zip 文件。
Debian 和 RPM 安装会自动安装任何依赖项,但是:
- 需要sudo或root权限来安装
- 对于 TensorRT 安装到哪个位置不灵活
- 要求还使用 Debian 或 RPM 软件包安装CUDA Toolkit 和 cuDNN
- 不允许同时安装多个 TensorRT 小版本
tar 文件提供了更大的灵活性,例如可以同时安装多个版本的 TensorRT。但是,需要确保已安装必要的依赖项,并且必须管理LD_LIBRARY_PATH 。有关详细信息,请参阅Tar 文件安装。windows仅支持zip安装
以上是官网提示,所以选择tar文件安装最为稳妥,deb安装则需要cuda和cudnn也是deb安装的,但一般cuda都是runfile安装。
Tar安装
- Download the TensorRT tar file that matches the CPU architecture and CUDA version you are using.
- Choose where you want to install TensorRT. This tar file will install everything into a subdirectory called
- TensorRT-8.x.x.x.
version="8.x.x.x"
arch=$(uname -m)
cuda="cuda-x.x"
tar -xzvf TensorRT-${version}.Linux.${arch}-gnu.${cuda}.tar.gz
Where:
- 8.x.x.x is your TensorRT version
- cuda-x.x is CUDA version 11.8 or 12.0
This directory will have sub-directories like lib, include, data, and so on.
ls TensorRT-${version}
bin data doc graphsurgeon include lib onnx_graphsurgeon python samples targets uff
- Add the absolute path to the TensorRT lib directory to the environment variable LD_LIBRARY_PATH:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:<TensorRT-${version}/lib>
- Install the Python TensorRT wheel file (replace cp3x with the desired Python version, for example, cp310 for Python 3.10).
cd TensorRT-${version}/python
python3 -m pip install tensorrt-*-cp3x-none-linux_x86_64.whl
Optionally, install the TensorRT lean and dispatch runtime wheel files:
python3 -m pip install tensorrt_lean-*-cp3x-none-linux_x86_64.whl
python3 -m pip install tensorrt_dispatch-*-cp3x-none-linux_x86_64.whl
- Install the Python UFF wheel file. This is only required if you plan to use TensorRT with TensorFlow in UFF format.
cd TensorRT-${version}/uff
python3 -m pip install uff-0.6.9-py2.py3-none-any.whl
Check the installation with:
which convert-to-uff
- Install the Python graphsurgeon wheel file.
cd TensorRT-${version}/graphsurgeon
python3 -m pip install graphsurgeon-0.4.6-py2.py3-none-any.whl
- Install the Python onnx-graphsurgeon wheel file.
cd TensorRT-${version}/onnx_graphsurgeon
python3 -m pip install onnx_graphsurgeon-0.3.12-py2.py3-none-any.whl
- Verify the installation:
-
Ensure that the installed files are located in the correct
directories. For example, run the tree -d command to check whether
all supported installed files are in place in the lib, include, data,
and so on directories. -
Build and run one of the shipped
samples, for example, sampleMNIST in the installed directory. You
should be able to compile and execute the sample without additional
settings. For more information, refer to sampleMNIST. -
The Python samples are in the samples/python directory.
-
为方便c++使用
sudo cp -r TensorRT-8.x.x.x /usr/local/
deb安装,不推荐
sudo dpkg -i nv-tensorrt-local-repo-ubuntu2004-8.6.1-cuda-11.8_1.0-1_amd64.deb
sudo cp /var/nv-tensorrt-local-repo-ubuntu2004-8.6.1-cuda-11.8/nv-tensorrt-local-D7BB1B18-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get install tensorrt
dpkg-query -W tensorrt #查看安装结果