Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnn: add more CANN operators to support SAM #23550

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
add sqrt
  • Loading branch information
fengyuentau committed Apr 27, 2023
commit 1fddf4a271e03a8105475ac61d2f3898cf78c48b
26 changes: 25 additions & 1 deletion modules/dnn/src/layers/elementwise_layers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,14 +1617,38 @@ struct SqrtFunctor : public BaseDefaultFunctor<SqrtFunctor>

bool supportBackend(int backendId, int)
{
return backendId == DNN_BACKEND_OPENCV || backendId == DNN_BACKEND_CUDA || backendId == DNN_BACKEND_HALIDE;
return backendId == DNN_BACKEND_OPENCV ||
backendId == DNN_BACKEND_CUDA ||
backendId == DNN_BACKEND_HALIDE ||
backendId == DNN_BACKEND_CANN;
}

inline float calculate(float x) const
{
return sqrt(x);
}

#ifdef HAVE_CANN
Ptr<BackendNode> initCannOp(const std::string& name,
const std::vector<Ptr<BackendWrapper> > &inputs,
const std::vector<Ptr<BackendNode> >& nodes)
{
auto x = inputs[0].dynamicCast<CannBackendWrapper>();

auto op = std::make_shared<ge::op::Sqrt>(name);

auto op_x = nodes[0].dynamicCast<CannBackendNode>()->getOp();
op->set_input_x_by_name(*op_x, x->name.c_str());
auto x_desc = x->getTensorDesc();
op->update_input_desc_x(*x_desc);

auto output_desc = std::make_shared<ge::TensorDesc>(ge::Shape(), ge::FORMAT_NCHW, ge::DT_FLOAT);
op->update_output_desc_y(*output_desc);

return Ptr<BackendNode>(new CannBackendNode(op));
}
#endif // HAVE_CANN

#ifdef HAVE_CUDA
Ptr<BackendNode> initCUDA(int target, csl::Stream stream)
{
Expand Down