MCPcopy Create free account
hub / github.com/alibaba/MNN / onEncode

Method onEncode

source/backend/tensorrt/execution/TRTConvolution.cpp:22–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22std::vector<ITensor *> TRTConvolution::onEncode(const std::vector<ITensor *> &xOp) {
23#ifdef TRT_LOG
24 printf("TRTConvolution in\n");
25#endif
26 auto conv2D = mOp->main_as_Convolution2D();
27 auto conv2DCommon = conv2D->common();
28
29 auto kernelX = conv2DCommon->kernelX();
30 auto kernelY = conv2DCommon->kernelY();
31 auto outputCount = conv2DCommon->outputCount();
32 int srcCount = 0;
33 const float *source = nullptr;
34 int weightSize = 0;
35 std::shared_ptr<ConvolutionCommon::Int8Common> quanWeight;
36 if (nullptr != mOp->main_as_Convolution2D()->quanParameter()) {
37 quanWeight = ConvolutionCommon::load(mOp, backend(), true);
38 srcCount = quanWeight->weightFloat.size() / (outputCount * kernelX * kernelY);
39 source = quanWeight->weightFloat.get();
40 weightSize = quanWeight->weightFloat.size();
41 } else {
42 if (nullptr != conv2D->weight()) {
43 srcCount = conv2D->weight()->size() / (outputCount * kernelX * kernelY);
44 source = conv2D->weight()->data();
45 weightSize = conv2D->weight()->size();
46 } else {
47 srcCount = conv2D->common()->inputCount();
48 }
49 }
50 int inputCount = srcCount;
51 mTrtBackend->pushCache(quanWeight);
52
53 nvinfer1::DimsHW NVKSize(kernelY, kernelX);
54 nvinfer1::DimsHW NVKDSize(conv2DCommon->dilateY(), conv2DCommon->dilateX());
55 nvinfer1::DimsHW NVKSSize(conv2DCommon->strideY(), conv2DCommon->strideX());
56
57 TRTWeight weight{nvinfer1::DataType::kFLOAT, static_cast<void *>(const_cast<float *>(source)),
58 static_cast<size_t>(weightSize)};
59
60 TRTWeight bias{nvinfer1::DataType::kFLOAT, static_cast<void *>(const_cast<float *>(conv2D->bias()->data())),
61 static_cast<size_t>(conv2D->bias()->size())};
62 ITensor* input = xOp[0];
63 auto originDim = xOp[0]->getDimensions();
64 auto dims = originDim.nbDims;
65 if (dims < 4) {
66 auto shuffle = mTrtBackend->getNetwork()->addShuffle(*(xOp[0]));
67 auto dimReshape = originDim;
68 dimReshape.nbDims = 4;
69 for (int v=dims; v<4; ++v) {
70 dimReshape.d[v] = 1;
71 }
72 shuffle->setReshapeDimensions(dimReshape);
73 input = shuffle->getOutput(0);
74 }
75 auto conv_layer =
76 mTrtBackend->getNetwork()->addConvolution(*input, outputCount, NVKSize, weight.get(), bias.get());
77
78 MNN_ASSERT(conv_layer != nullptr);
79 conv_layer->setStride(NVKSSize);

Callers

nothing calls this directly

Calls 15

backendFunction · 0.85
weightMethod · 0.80
pushCacheMethod · 0.80
biasMethod · 0.80
getDimensionsMethod · 0.80
getNetworkMethod · 0.80
setPaddingMethod · 0.80
loadFunction · 0.50
sizeMethod · 0.45
getMethod · 0.45
dataMethod · 0.45
getOutputMethod · 0.45

Tested by

no test coverage detected