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

特性

  1. 量化的时候不损失精度, 量化的过程中做精度校正,通过将模型量化到INT8或FP16来最大化吞吐量,同时保持准确性。
  2. Layer以及Tensor之间相互融合,减少inference过程中的计算量。
  3. 根据GPU平台的不同,定制专属的Engine.
  4. 提高内存利用率
  5. 多流并行计算

融合机制

  1. 垂直融合
    1. 将一些Convolution, bia和**等层合在一起计算
  2. 水平融合
    1. 将一些非常相似的操作合在一起同时计算

图示

原始网络:
TensorRT学习笔记1. 垂直层融合
TensorRT学习笔记2. 水平融合
TensorRT学习笔记

操作步骤

// 待完善

  1. 创建builder
    Need have an ICudaEngine for executing inference on a build network(builder).
  2. 通过builder创建一个空的TensorRT网络(Net)
    Create an empty TensorRT Network(network).
  3. 为这个空的Net添加组件
    Add all components to the network.(e.g. input data, convolution, relu and so on.)
  4. 为builder设置参数
    Configure some assign parameters for the builder(e.g. fp16, batch size and so on.)
  5. 通过这个builder将Net打包成一个engine
    Builder build the cuda engine through this network(engine).
  6. 通过ICudaEngine将engine进行包装
    Build a context for executing inference using an ICudaEngine.
  7. 通过这个input data来执行inference
    Executing context by the input data.

结果

yolov3 <> Drive: 418.87 <> Cuda: 10.1 <> Cudnn: 7.6.5
TensorRT学习笔记TensorRT学习笔记
代码