1
0
mirror of https://github.com/opencv/opencv_contrib.git synced 2025-10-21 23:01:45 +08:00
Files
opencv_contrib/modules/cannops/misc/python/pyopencv_cann.hpp
hipudding 3c5635eacf Add operators support for Ascend NPU (CANN backend) (#3552)
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](https://github.com/opencv/opencv/pull/22634).

There are more and more users using [Ascend NPU](https://www.hiascend.com/)
and programming with CANN, and the number is still growing rapidly.
AI training and inference are inseparable from data preprocessing.
When users use OpenCV to work with CANN backend, data preprocessing can
only run on CPUs, resulting in inefficiency.

The purpose of this commit is to enable OpenCV operators on CANN backend.

The usage of CANN backend is consistent, Please refer to OpenCV DNN: [CANN backend manual]
(https://gist.github.com/fengyuentau/083f7f339592545c1f1d2c1fde6a53dc#file-a_ocv_cann-md):
1. [Install dependencies]
   (https://gist.github.com/fengyuentau/083f7f339592545c1f1d2c1fde6a53dc#install-dependencies)
2. [Install CANN]
   (https://gist.github.com/fengyuentau/083f7f339592545c1f1d2c1fde6a53dc#install-cann)
3. [Compile OpenCV with CANN]
   (https://gist.github.com/fengyuentau/083f7f339592545c1f1d2c1fde6a53dc#build-opencv-with-cann)

The CANN backend is used in a similar way to CUDA:
| Object    | CANN         | CUDA     |
| --------- | ------------ | -------- |
| Namespace | cv::cann     | cv::cuda |
| Matrix    | AscendMat    | GpuMat   |
| Stream    | AscendStream | Stream   |
| Event     | AscendEvent  | Event    |

The current commit provides CANN backend operator support framework, In
order to make code viewing easy, only a few basic interfaces are
implemented, all of the following operators are tested and compared
result with CPU backend.

More operators will continue implement in new independent commits.

Co-authored-by: CaoMengqing <cmq0113@163.com>
2023-11-21 09:44:57 +03:00

29 lines
796 B
C++

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#ifndef OPENCV_CANNOPS_PYOPENCV_CANN_HPP
#define OPENCV_CANNOPS_PYOPENCV_CANN_HPP
#ifdef HAVE_OPENCV_CORE
#include "opencv2/cann.hpp"
typedef std::vector<cann::AscendMat> vector_AscendMat;
typedef cann::AscendMat::Allocator AscendMat_Allocator;
CV_PY_TO_CLASS(cann::AscendMat);
CV_PY_TO_CLASS(cann::AscendStream);
CV_PY_TO_CLASS_PTR(cann::AscendMat);
CV_PY_TO_CLASS_PTR(cann::AscendMat::Allocator);
CV_PY_FROM_CLASS(cann::AscendMat);
CV_PY_FROM_CLASS(cann::AscendStream);
CV_PY_FROM_CLASS_PTR(cann::AscendMat::Allocator);
#endif // HAVE_OPENCV_CORE
#endif // OPENCV_CANNOPS_PYOPENCV_CANN_HPP