mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 09:10:35 -06:00
dnn: add the CANN backend (#22634)
* cann backend impl v1 * cann backend impl v2: use opencv parsers to build models for cann * adjust fc according to the new transA and transB * put cann net in cann backend node and reuse forwardLayer * use fork() to create a child process and compile cann model * remove legacy code * remove debug code * fall bcak to CPU backend if there is one layer not supoorted by CANN backend * fix netInput forward
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
#include "../op_vkcom.hpp"
|
||||
#include "../op_webnn.hpp"
|
||||
#include "../op_timvx.hpp"
|
||||
#include "../op_cann.hpp"
|
||||
|
||||
#include <float.h>
|
||||
#include <algorithm>
|
||||
@@ -143,7 +144,8 @@ public:
|
||||
return backendId == DNN_BACKEND_OPENCV ||
|
||||
backendId == DNN_BACKEND_CUDA ||
|
||||
backendId == DNN_BACKEND_WEBNN ||
|
||||
(backendId == DNN_BACKEND_VKCOM && haveVulkan());
|
||||
(backendId == DNN_BACKEND_VKCOM && haveVulkan()) ||
|
||||
backendId == DNN_BACKEND_CANN;
|
||||
}
|
||||
|
||||
bool getMemoryShapes(const std::vector<MatShape> &inputs,
|
||||
@@ -438,6 +440,34 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_CANN
|
||||
virtual Ptr<BackendNode> initCann(const std::vector<Ptr<BackendWrapper> > &inputsWrapper, const int index, const std::vector<Ptr<BackendNode> >& nodes) CV_OVERRIDE
|
||||
{
|
||||
auto x = inputsWrapper[0].dynamicCast<CannBackendWrapper>();
|
||||
|
||||
// create operator
|
||||
std::string op_name = cv::format("permute_%d", index);
|
||||
auto op = std::make_shared<ge::op::Permute>(op_name);
|
||||
|
||||
// set attributes
|
||||
op->set_attr_order(ge::Operator::OpListInt(
|
||||
_order.begin(), _order.end()
|
||||
));
|
||||
|
||||
// set inputs
|
||||
// set inputs : x
|
||||
auto op_x = nodes[0].dynamicCast<CannBackendNode>()->getOp();
|
||||
op->set_input_x_by_name(*op_x, "y");
|
||||
auto x_desc = x->getTensorDesc();
|
||||
op->update_input_desc_x(*x_desc);
|
||||
|
||||
// set outputs
|
||||
auto output_y_desc = std::make_shared<ge::TensorDesc>(ge::Shape(), ge::FORMAT_NCHW, ge::DT_FLOAT);
|
||||
op->update_output_desc_y(*output_y_desc);
|
||||
|
||||
return Ptr<BackendNode>(new CannBackendNode(op));
|
||||
}
|
||||
#endif // HAVE_CANN
|
||||
|
||||
#ifdef HAVE_DNN_NGRAPH
|
||||
virtual Ptr<BackendNode> initNgraph(const std::vector<Ptr<BackendWrapper> >& inputs,
|
||||
|
||||
Reference in New Issue
Block a user