0
点赞
收藏
分享

微信扫一扫

TensorRT之安装与测试(Windows和Linux环境下安装TensorRT)

Separes 2022-08-06 阅读 245


1 Win7+CUDA9.0+TensorRT安装

1-1 下载对应TensorRT版本

​​https://developer.nvidia.com/nvidia-tensorrt-5x-download​​

这里我们选择 TensorRT 5.0 GA For Windows

TensorRT之安装与测试(Windows和Linux环境下安装TensorRT)_python

1-2 解压 TensorRT

TensorRT之安装与测试(Windows和Linux环境下安装TensorRT)_python_02

1-3 配置环境变量

将TensorRT解压位置\lib 加入系统环境变量

TensorRT之安装与测试(Windows和Linux环境下安装TensorRT)_TensorRT_03


将TensorRT解压位置\lib下的dll文件复制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin目录下

TensorRT之安装与测试(Windows和Linux环境下安装TensorRT)_ide_04

1-4 测试示例代码

用VS2017打开sampleMNIST示例(D:\TensorRT-5.0.4.3\samples\sampleMNIST)

a. 将D:\TensorRT-5.0.4.3\lib加入 VC++目录–>可执行文件目录

TensorRT之安装与测试(Windows和Linux环境下安装TensorRT)_TensorRT_05


b. 将D:\TensorRT-5.0.4.3\include加入C/C++ --> 常规 --> 附加包含目录

TensorRT之安装与测试(Windows和Linux环境下安装TensorRT)_python_06


c.将D:\TensorRT-5.0.4.3\lib加入 VC++目录–>库目录
将nvinfer.lib、nvinfer_plugin.lib、nvonnxparser.lib和nvparsers.lib加入链接器–>输入–>附加依赖项

TensorRT之安装与测试(Windows和Linux环境下安装TensorRT)_python_07


编译后运行得到结果

TensorRT之安装与测试(Windows和Linux环境下安装TensorRT)_python_08

2 Ubuntu-16.04+CUDA9.0+TensorRT-5.0安装

2-1下载

​​https://developer.nvidia.com/nvidia-tensorrt-5x-download​​

2-2 解压

tar -zxvf TensorRT-5.0.2.6.Ubuntu-16.04.4.x86_64-gnu.cuda-9.0.cudnn7.3.tar.gz
cd TensorRT-5.0.2.6/

2-3 添加环境变量

vim ~/.bashrc
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/liumin/software/TensorRT-5.0.2.6/lib
source ~/.bashrc

2-4 安装 Python TensorRT wheel 文件

cd python/
pip install tensorrt-5.0.2.6-py2.py3-none-any.whl

2-5 安装 Python UFF wheel 文件

cd ../uff/
pip install uff-0.5.5-py2.py3-none-any.whl

2-6 安装 Python graphsurgeon wheel 文件

cd ../graphsurgeon/
pip install graphsurgeon-0.3.2-py2.py3-none-any.whl

2-7 测试

cd samples/sampleMNIST
make
cd ../../bin
./sample_mnist

输出:

[09/03/2020-09:21:44] [I] Building and running a GPU inference engine for MNIST
[09/03/2020-09:21:48] [I] [TRT] Detected 1 inputs and 1 output network tensors.
[09/03/2020-09:21:48] [W] [TRT] Current optimization profile is: 0. Please ensure there are no enqueued operations pending in this context prior to switching profiles
[09/03/2020-09:21:48] [I] Input:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@+ #@@@@@@
@@@@@@@@@@@@@@@@@* #@@@@@@
@@@@@@@@@@@@@@@@@= #@@@@@@
@@@@@@@@@@@@@@@@# .%@@@@@@@
@@@@@@@@@@@@@@@#. *@@@@@@@@
@@@@@@@@@@@@@@@- :@@@@@@@@@
@@@@@@@@@@@@@@@ #@@@@@@@@@
@@@@@@@@@@@@@%. =@@@@@@@@@@
@@@@@@@@@@@@@+ :@@@@@@@@@@@
@@@@@@@@@@@@* :%@@@@@@@@@@@
@@@@@@@@@@@% -@@@@@@@@@@@@
@@@@@@@@@@@= %@@@@@@@@@@@@
@@@@@@@@@@#. -@@@@@@@@@@@@@
@@@@@@@@@@ :@@@@@@@@@@@@@@
@@@@@@@@@@ *@@@@@@@@@@@@@@
@@@@@@@@@- %@@@@@@@@@@@@@@
@@@@@@@@#. =@@@@@@@@@@@@@@@
@@@@@@@@# .@@@@@@@@@@@@@@@@
@@@@@@@@# .@@@@@@@@@@@@@@@@
@@@@@@@@%: .@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@

[09/03/2020-09:21:48] [I] Output:
0:
1: **********
2:
3:
4:
5:
6:
7:
8:
9:

&&&& PASSED TensorRT.sample_mnist # ./sample_mnist

常见报错:
1 运行示例时,提示找不到 MNIST数据

[xxx@localhost bin]$ ./sample_mnist
&&&& RUNNING TensorRT.sample_mnist # ./sample_mnist
[09/03/2020-09:15:29] [I] Building and running a GPU inference engine for MNIST
[09/03/2020-09:15:34] [I] [TRT] Detected 1 inputs and 1 output network tensors.
[09/03/2020-09:15:34] [W] [TRT] Current optimization profile is: 0. Please ensure there are no enqueued operations pending in this context prior to switching profiles
Could not find 2.pgm in data directories:
data/mnist/
data/samples/mnist/

这是因为在TensorRT 7.x以后需要手动下载MNIST数据
进入data/mnist目录,运行

python download_pgms.py

2 .加载 libnvinfer.so.7报错

[xxx@localhost bin]$ ./sample_mnist
./sample_mnist: error while loading shared libraries: libnvinfer.so.7: cannot open shared object file: No such file or directory

参考资料
1 ​​​TensorRT Installation Guide​​​ https://docs.nvidia.com/deeplearning/sdk/tensorrt-install-guide/index.html
2 ​​​TensorRT Documentation​​​ https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/c_api/index.html
3 ​​​Best Practices For TensorRT Performance​​​ https://docs.nvidia.com/deeplearning/sdk/tensorrt-best-practices/index.html
4 ​​​TensorRT Developer Guide​​​ https://docs.nvidia.com/deeplearning/sdk/tensorrt-developer-guide/index.html
5 ​​​TensorRT API​​​ https://docs.nvidia.com/deeplearning/sdk/tensorrt-api/index.html
6 ​​​Samples Support Guide​​ https://docs.nvidia.com/deeplearning/sdk/tensorrt-sample-support-guide/index.html


举报

相关推荐

0 条评论