二、TensorRT编程流程
使用TensorRT主要有连个步骤:
构建阶段:构建一个网络定义(network),执行优化,并生产推理引擎(inference engine)
执行阶段:引擎运行推理任务(只需要输入/输出buffers),主要是通过 IExecutionContext::execute和 IExecutionContext::enqueue同步或异步执行推理
目前支持的层(据说更新到TensorRT 2.1将支持自定义层,好消息哦):
Convolution: 2D
Activation: ReLu, tanh and sigmoid
Pooling: max and average
ElementWise: sum, product or max of two tensors
LRN: cross-channel only
Fully-connected: with or without bias
SoftMax: cross-channel only
Deconvolution
1.主要两个头文件、两个库:
头文件目录:/usr/include/x86_64-linux-gnu/
NvCaffeParser.h NvInfer.h
库目录:/usr/lib/x86_64-linux-gnu
libnvcaffe_parser.so libnvinfer.so
demo目录:/usr/src/gie_samples
doc目录:/usr/share/doc/gie
2.软件主要流程(代码只列出主要部分):
由于会用到cuda需要包含cuda_runtime_api.h
以sampleMNIST为例:
首先从main()开始:
caffe model转gie model,创建序列化engine;
读入需要处理的图像;
用caffe parser解析均值文件(.binaryproto),与需要处理图像相减;
反序列化gieModelStream到engine,创建引擎执行的环境(context )
执行推理doInference(*context, data, prob, 1);//参数:环境,输入,输出,batch大小