TensorRT学习笔记
参考文献
https://github.com/NVIDIA/TensorRT
https://docs.nvidia.com/deeplearning/sdk/tensorrt-archived/
https://docs.nvidia.com/deeplearning/sdk/tensorrt-developer-guide/index.html
https://developer.nvidia.com/tensorrt
特性
- 量化的时候不损失精度, 量化的过程中做精度校正,通过将模型量化到INT8或FP16来最大化吞吐量,同时保持准确性。
- Layer以及Tensor之间相互融合,减少inference过程中的计算量。
- 根据GPU平台的不同,定制专属的Engine.
- 提高内存利用率
- 多流并行计算
融合机制
- 垂直融合
- 将一些Convolution, bia和**等层合在一起计算
- 水平融合
- 将一些非常相似的操作合在一起同时计算
图示
原始网络:1. 垂直层融合
2. 水平融合
操作步骤
// 待完善
- 创建builder
Need have an ICudaEngine for executing inference on a build network(builder). - 通过builder创建一个空的TensorRT网络(Net)
Create an empty TensorRT Network(network). - 为这个空的Net添加组件
Add all components to the network.(e.g. input data, convolution, relu and so on.) - 为builder设置参数
Configure some assign parameters for the builder(e.g. fp16, batch size and so on.) - 通过这个builder将Net打包成一个engine
Builder build the cuda engine through this network(engine). - 通过ICudaEngine将engine进行包装
Build a context for executing inference using an ICudaEngine. - 通过这个input data来执行inference
Executing context by the input data.
结果
yolov3 <> Drive: 418.87 <> Cuda: 10.1 <> Cudnn: 7.6.5
代码