mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 07:13:02 +04:00
Merge pull request #24122 from fengyuentau:remove_tengine
dnn: cleanup of tengine backend #24122 🚀 Cleanup for OpenCV 5.0. Tengine backend is added for convolution layer speedup on ARM CPUs, but it is not maintained and the convolution layer on our default backend has reached similar performance to that of Tengine. Tengine backend related PRs: - https://github.com/opencv/opencv/pull/16724 - https://github.com/opencv/opencv/pull/18323 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
@@ -62,9 +62,6 @@
|
||||
#include "opencl_kernels_dnn.hpp"
|
||||
using namespace cv::dnn::ocl4dnn;
|
||||
#endif
|
||||
#ifdef HAVE_TENGINE
|
||||
#include "../tengine4dnn/include/tengine_graph_convolution.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
#include "../cuda4dnn/primitives/convolution.hpp"
|
||||
@@ -267,10 +264,6 @@ public:
|
||||
float power;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TENGINE
|
||||
teng_graph_t tengine_graph;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
cuda4dnn::ConvolutionConfiguration::FusionMode cudaFusionMode;
|
||||
cuda4dnn::ConvolutionConfiguration::ActivationType cudaActType;
|
||||
@@ -289,20 +282,8 @@ public:
|
||||
#ifdef HAVE_CUDA
|
||||
cudaFusionMode = cuda4dnn::ConvolutionConfiguration::FusionMode::NONE;
|
||||
cudaActType = cuda4dnn::ConvolutionConfiguration::ActivationType::IDENTITY;
|
||||
#endif
|
||||
#ifdef HAVE_TENGINE
|
||||
tengine_graph=NULL;
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_TENGINE
|
||||
~ConvolutionLayerImpl()
|
||||
{
|
||||
if(NULL != tengine_graph )
|
||||
{
|
||||
tengine_release(tengine_graph);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
MatShape computeColRowShape(const MatShape &inpShape, const MatShape &outShape) const CV_OVERRIDE
|
||||
{
|
||||
@@ -466,13 +447,6 @@ public:
|
||||
for(int i = 0; i < numOutput; i++ )
|
||||
biasvec[i] = biasMat.at<float>(i);
|
||||
}
|
||||
#ifdef HAVE_TENGINE
|
||||
if(NULL != tengine_graph )
|
||||
{
|
||||
tengine_release(tengine_graph);
|
||||
tengine_graph = NULL ;
|
||||
}
|
||||
#endif
|
||||
#ifdef HAVE_OPENCL
|
||||
convolutionOp.release();
|
||||
#endif
|
||||
@@ -1305,65 +1279,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_TENGINE
|
||||
bool tengine_ret = false;
|
||||
|
||||
std::vector<Mat> teng_in, teng_out;
|
||||
inputs_arr.getMatVector(teng_in);
|
||||
outputs_arr.getMatVector(teng_out);
|
||||
|
||||
int inch = teng_in[0].size[1]; // inch
|
||||
int in_h = teng_in[0].size[2]; // in_h
|
||||
int in_w = teng_in[0].size[3]; // in_w
|
||||
|
||||
int out_b = teng_out[0].size[0]; // out batch size
|
||||
int outch = teng_out[0].size[1]; // outch
|
||||
int out_h = teng_out[0].size[2]; // out_h
|
||||
int out_w = teng_out[0].size[3]; // out_w
|
||||
|
||||
float *input_ = teng_in[0].ptr<float>();
|
||||
float *output_ = teng_out[0].ptr<float>();
|
||||
float *kernel_ = weightsMat.ptr<float>();
|
||||
float *teg_bias = &biasvec[0];
|
||||
|
||||
int nstripes = std::max(getNumThreads(), 1);
|
||||
|
||||
/* tengine_init will run when first time. */
|
||||
if(NULL == tengine_graph)
|
||||
{
|
||||
// pads_begin: 0 - pad_top, 1 - pad_left
|
||||
// pads_end: 0 - pad_bottom, 1 - pad_right
|
||||
// pad_h0: pad_top, pad_h1: pad_bottom
|
||||
// pad_w0: pad_left, pad_w1: pad_right
|
||||
tengine_graph = tengine_init(name.c_str(), input_, inch, ngroups, in_h, in_w,
|
||||
output_, out_b, outch, out_h, out_w,
|
||||
kernel_, kernel_size.size(), kernel.height, kernel.width,
|
||||
teg_bias, stride.height, stride.width,
|
||||
pads_begin[0], pads_end[0], pads_begin[1], pads_end[1], dilation.height, dilation.width,
|
||||
weightsMat.step1(), padMode, tengine_graph, nstripes);
|
||||
// printf("Init(%s): input=%p(%d %d %d %d ),output=%p(%d %d %d %d ),kernel=%p(%ld %d %d ), bias=%p ,"
|
||||
// "stride(%d %d), pad(%d %d %d %d), dilation(%d %d) ,weightsMat=%ld, padMode=%s ,tengine_graph = %p \n",
|
||||
// name.c_str(),input_, inch, ngroups, in_h, in_w,
|
||||
// output_, out_b, outch, out_h, out_w,
|
||||
// kernel_, kernel_size.size(), kernel.height, kernel.width,
|
||||
// teg_bias, stride.height, stride.width,
|
||||
// pads_begin[0], pads_end[0], pads_begin[1], pads_end[1], dilation.height, dilation.width,
|
||||
// weightsMat.step1(), padMode.c_str() ,tengine_graph);
|
||||
}
|
||||
if(NULL != tengine_graph)
|
||||
{
|
||||
tengine_ret = tengine_forward(tengine_graph);
|
||||
}
|
||||
/* activation */
|
||||
if((true == tengine_ret) && activ )
|
||||
{
|
||||
int out_cstep = out_h * out_w; // out_cstep
|
||||
|
||||
ActivationLayer* activ_ = activ.get();
|
||||
activ_->forwardSlice(output_, output_, out_cstep, out_cstep, 0, outch);
|
||||
}
|
||||
if(false == tengine_ret)
|
||||
#endif
|
||||
{
|
||||
int nstripes = std::max(getNumThreads(), 1);
|
||||
int conv_dim = CONV_2D;
|
||||
|
||||
Reference in New Issue
Block a user