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

1 Win7+CUDA9.0+TensorRT安装

1-1 下载对应TensorRT版本

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

这里我们选择 TensorRT 5.0 GA For Windows
在这里插入图片描述

1-2 解压 TensorRT

在这里插入图片描述

1-3 配置环境变量

将TensorRT解压位置\lib 加入系统环境变量
在这里插入图片描述
将TensorRT解压位置\lib下的dll文件复制到C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\bin目录下
在这里插入图片描述

1-4 测试示例代码

用VS2017打开sampleMNIST示例(D:\TensorRT-5.0.4.3\samples\sampleMNIST)
a. 将D:\TensorRT-5.0.4.3\lib加入 VC++目录–>可执行文件目录
在这里插入图片描述
b. 将D:\TensorRT-5.0.4.3\include加入C/C++ --> 常规 --> 附加包含目录
在这里插入图片描述
c.将D:\TensorRT-5.0.4.3\lib加入 VC++目录–>库目录
将nvinfer.lib、nvinfer_plugin.lib、nvonnxparser.lib和nvparsers.lib加入链接器–>输入–>附加依赖项

在这里插入图片描述
编译后运行得到结果
在这里插入图片描述

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/
&&&& FAILED

这是因为在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

<think>嗯,用户想查找TensorRT安装方法或者教程,特别是询问安装指南如何安装。首先,我需要回忆一下之前提供的引用内容。引用[1]提到了Windows10下的安装步骤,包括下载ZIP文件、解压、添加环境变量验证安装。引用[2]则涉及ONNX-TensorRT安装,需要替换路径编译项目。引用[3]是通用的安装配置指南,确认安装成功后的使用。 用户的需求很明确,是要安装TensorRT,可能需要详细的步骤指导。我应该先概述安装前的准备,比如检查CUDA版本下载对应的TensorRT版本。然后分步骤说明WindowsLinux下的安装方法,因为用户可能使用不同的操作系统。Windows部分可以参考引用[1]的内容,详细列出解压、环境变量设置、验证等步骤。Linux部分可能需要使用deb包或者Tar包安装,同样需要环境变量配置,并验证安装是否成功。 另外,用户可能需要知道如何验证安装是否成功,比如运行sample程序或者Python测试。这部分需要确保用户完成安装后能够确认TensorRT正常工作。同时,考虑到用户可能遇到的问题,比如路径替换、环境变量配置错误,或者依赖项缺失,应该在注意事项里提醒他们注意版本匹配路径正确性。 可能还需要补充一些常见问题,比如安装后无法导入TensorRT模块,这时候需要检查PYTHONPATH是否正确,或者是否有缺失的依赖库。此外,引用[2]提到的ONNX-TensorRT编译可能对部分用户有用,但用户主要问题是安装,可能暂时不需要深入,但可以作为后续步骤提及。 最后,生成的相关问题需要覆盖安装验证、不同系统安装、依赖检查以及其他框架的集成,这样用户如果有进一步的问题可以自行参考。需要确保回答结构清晰,分步骤说明,并且引用正确的来源,比如引用[1][3]作为主要安装步骤,引用[2]作为扩展内容。</think>以下是TensorRT安装的详细步骤指南: ### TensorRT安装步骤 1. **安装前准备** - 确认已安装对应版本的CUDAcuDNN(建议使用Nvidia官方推荐的版本组合)[^3] - 下载对应版本的TensorRT压缩包(推荐从[Nvidia开发者网站](https://developer.nvidia.com/tensorrt)获取) 2. **Windows安装** ```markdown 1. 解压下载的TensorRT ZIP文件到指定目录(建议路径不含中文空格)[^1] 2. 添加以下环境变量: - TensorRT安装目录:`<path_to_tensorrt>` - 将TensorRT的lib目录添加到PATH:`<path_to_tensorrt>\lib` 3. 验证安装: ```python import tensorrt print(tensorrt.__version__) ``` ``` 3. **Linux安装(Debian包方式)** ```bash # 安装基础包 sudo dpkg -i nv-tensorrt-local-repo-<distro>_<version>-1_amd64.deb sudo apt-key add /var/nv-tensorrt-local-repo-<version>/7fa2af80.pub sudo apt-get update sudo apt-get install tensorrt ``` 4. **验证安装** ```bash # 检查样本程序 cd <TensorRT安装目录>/samples/sampleMNIST make ./sample_mnist ``` ### 注意事项 - 必须保证CUDA、cuDNN、TensorRT版本严格对应[^3] - Python接口需要额外安装`python3-libnvinfer`包 - 遇到路径问题时,请检查`LD_LIBRARY_PATH`(Linux)或`PATH`(Windows是否包含TensorRT库路径[^2]
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mingo_敏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值