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 the CANN backend #22634

Merged
merged 9 commits into from
Dec 21, 2022
Merged

Conversation

fengyuentau
Copy link
Member

@fengyuentau fengyuentau commented Oct 13, 2022

merge with adding a wiki page: https://gist.github.com/fengyuentau/083f7f339592545c1f1d2c1fde6a53dc

Benchmark

Environment (provided by Ascend):

  1. CPU: 20-core aarch64, freq unknown
  2. NPU: Ascend 310

Time is in millisecond. The time of first run is excluded.

Model CPU backend CANN backend (this PR) Native CANN
PP-ResNet50 69.74 3.29 2.51
MobileNetV1 6.60 1.21 0.85
YOLOX 265.90 12.80 9.11
AlexNet 13.19 3.82 3.36

Notes:

  1. PP-ResNet50, MobileNetV1 and YOLOX are from https://github.com/opencv/opencv_zoo.
  2. Native CANN stands for loading and inferring a ATC-converted OM model with CANN interfaces. ATC is the model conversion from ONNX/TF/CAFFE to OM tool provided by CANN. Native CANN only measures the time of aclmdlExecute.
  3. CANN backend (this PR) stands for loading ONNX/TF/CAFFE models with opencv parsers and inferring the OM model built by CANN backend. CANN backend (this PR) measures the time of net.forward(), including aclmdlExecute and some other overheads. Models built by CANN backend and converted by ATC have the same time of aclmdlExecute.
  4. Differences between the implementations of this PR and the previous one:
    • This PR: use aclgrphBuildModel to fully optimize the graph and use aclmdlExecute to forward the graph directly.
    • Previous: use aclopCompileAndExecute to call and run operator on the fly.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Comment on lines +170 to +172
if(HAVE_CANN)
list(APPEND include_dirs ${CANN_INCLUDE_DIRS})
list(APPEND libs -Wl,--whole-archive ${CANN_LIBRARIES} -Wl,--no-whole-archive)
endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to reuse ocv_add_external_target() approach for 3rdparty libraries.

Copy link
Member Author

@fengyuentau fengyuentau Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about keep it as-is since other 3rdparty libraries are still using the old approach? We can do this kind of change for all other 3rdparty libraries in a separate pr.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this? (as there is ocv.3rdparty.cann usage below)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do. ocv.3rdparty.cann is used to link for opencv_test_dnn only for now.

modules/dnn/src/op_cann.cpp Outdated Show resolved Hide resolved
modules/dnn/test/test_onnx_importer.cpp Outdated Show resolved Hide resolved
modules/dnn/test/test_onnx_importer.cpp Outdated Show resolved Hide resolved
Comment on lines +170 to +172
if(HAVE_CANN)
list(APPEND include_dirs ${CANN_INCLUDE_DIRS})
list(APPEND libs -Wl,--whole-archive ${CANN_LIBRARIES} -Wl,--no-whole-archive)
endif()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this? (as there is ocv.3rdparty.cann usage below)

modules/dnn/src/layer.cpp Show resolved Hide resolved
@vpisarev vpisarev merged commit a2b3acf into opencv:4.x Dec 21, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
@HaoWangDL
Copy link

can support siamrpn use cann backend?
thank you

@fengyuentau
Copy link
Member Author

can support siamrpn use cann backend?

Working on the support of DaSiamRPN with CANN backend.

@HaoWangDL
Copy link

thank u. I will have a try.

@HaoWangDL
Copy link

can support siamrpn use cann backend?

Working on the support of DaSiamRPN with CANN backend.

I try yolox and classify in model zoo with cann backend, it works.
But i try dasiamrpn(model zoo) with cann backend, encounterd some errors.

[ERROR:0@6.253] global net_cann.cpp:286 compileCannGraph CANN graph check failed, ret = 4294967295 [ERROR:0@8.231] global net_cann.cpp:286 compileCannGraph CANN graph check failed, ret = 4294967295 [ERROR:0@9.299] global op_cann.cpp:258 loadToDevice CANN check failed, ret = 100000 FATAL: C++ exception: OpenCV(4.7.0) /home/ubuntu/Desktop/opencv_git/opencv/modules/dnn/src/op_cann.cpp:258: error: (-2:Unspecified error) CANN check failed in function 'loadToDevice'

can help me? thank u.

@fengyuentau
Copy link
Member Author

I am afraid that DaSiamRPN on CANN backend will not be fixed in recent future due to some complicated issues. Actually we are planning to add some other better object tracking models into the zoo to replace DaSiamRPN. They are much faster and more lightweight without sacrificing too much accuracy. I will try to make those new models working on CANN backend instead.

Stay tune for updates!

@HaoWangDL
Copy link

HaoWangDL commented Mar 8, 2023 via email

a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
* 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
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Aug 30, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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.
Note that these operators only support Ascend 310 now, other NPUs are
theoretically supported, but not tested.

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    | AclMat    | GpuMat   |
| Stream    | AclStream | Stream   |
| Event     | AclEvent  | Event    |

The current commit provides CANN backend operator support framework, In
order to make code viewing easy, only 7 basic interfaces are
implemented, all of the following operators are tested and compared
result with CPU backend:
- [x] Add
- [x] subtract
- [x] multiply
- [x] divide
- [x] bitwise_and
- [x] bitwise_or
- [x] bitwise_xor

More operators will continue implement in new independent commits.
Performance test shows these operators efficiency improved by 2 times.

Co-authored-by: CaoMengqing <cmq0113@163.com>
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Aug 30, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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.
Note that these operators only support Ascend 310 now, other NPUs are
theoretically supported, but not tested.

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    | AclMat    | GpuMat   |
| Stream    | AclStream | Stream   |
| Event     | AclEvent  | Event    |

The current commit provides CANN backend operator support framework, In
order to make code viewing easy, only 7 basic interfaces are
implemented, all of the following operators are tested and compared
result with CPU backend:
- [x] Add
- [x] subtract
- [x] multiply
- [x] divide
- [x] bitwise_and
- [x] bitwise_or
- [x] bitwise_xor

More operators will continue implement in new independent commits.

Co-authored-by: CaoMengqing <cmq0113@163.com>
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Aug 31, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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    | AclMat    | GpuMat   |
| Stream    | AclStream | Stream   |
| Event     | AclEvent  | Event    |

The current commit provides CANN backend operator support framework, In
order to make code viewing easy, only 7 basic interfaces are
implemented, all of the following operators are tested and compared
result with CPU backend:
- [x] Add
- [x] subtract
- [x] multiply
- [x] divide
- [x] bitwise_and
- [x] bitwise_or
- [x] bitwise_xor

More operators will continue implement in new independent commits.

Co-authored-by: CaoMengqing <cmq0113@163.com>
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Aug 31, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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    | AclMat    | GpuMat   |
| Stream    | AclStream | Stream   |
| Event     | AclEvent  | Event    |

The current commit provides CANN backend operator support framework, In
order to make code viewing easy, only 7 basic interfaces are
implemented, all of the following operators are tested and compared
result with CPU backend:
- [x] Add
- [x] subtract
- [x] multiply
- [x] divide
- [x] bitwise_and
- [x] bitwise_or
- [x] bitwise_xor

More operators will continue implement in new independent commits.

Co-authored-by: CaoMengqing <cmq0113@163.com>
@fengyuentau fengyuentau added the category:dnn_cann CANN backend related issues in DNN module label Sep 13, 2023
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Nov 6, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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    | AclMat    | GpuMat   |
| Stream    | AclStream | Stream   |
| Event     | AclEvent  | 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>
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Nov 6, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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    | AclMat    | GpuMat   |
| Stream    | AclStream | Stream   |
| Event     | AclEvent  | 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>
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Nov 6, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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    | AclMat    | GpuMat   |
| Stream    | AclStream | Stream   |
| Event     | AclEvent  | 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>
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Nov 16, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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>
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Nov 16, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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>
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Nov 16, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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>
hipudding added a commit to hipudding/opencv_contrib that referenced this pull request Nov 16, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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>
vpisarev pushed a commit to opencv/opencv_contrib that referenced this pull request Nov 21, 2023
CANN (Compute Architecture of Neural Networks), developped by Huawei, is
a heterogeneous computing architecture for AI. Opencv DNN has already
suppoted CANN backend [#22634](opencv/opencv#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>
@fengyuentau fengyuentau deleted the cann_backend_221010 branch June 28, 2024 09:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:dnn_cann CANN backend related issues in DNN module category: dnn feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants