From 9a5685a9958f9e3b85b24b3621be3e339febd494 Mon Sep 17 00:00:00 2001 From: liuhw <71241939+dflhw@users.noreply.github.com> Date: Wed, 10 May 2023 17:07:17 +0800 Subject: [PATCH] [Feature] Add the support of arf op for ascend device (#2792) --- docs/en/compatibility.md | 9 +++-- docs/en/understand_mmcv/ops.md | 2 +- docs/zh_cn/compatibility.md | 11 +++--- docs/zh_cn/understand_mmcv/ops.md | 2 +- .../pytorch/npu/active_rotated_filter_npu.cpp | 36 +++++++++++++++++++ tests/test_ops/test_active_rotated_filter.py | 7 +++- 6 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 mmcv/ops/csrc/pytorch/npu/active_rotated_filter_npu.cpp diff --git a/docs/en/compatibility.md b/docs/en/compatibility.md index cd2e1a10ea..09d25e1629 100644 --- a/docs/en/compatibility.md +++ b/docs/en/compatibility.md @@ -9,7 +9,7 @@ The OpenMMLab team released MMCV v2.0.0 on April 6, 2023. In the 2.x version, it - `mmcv.fileio` module, removed in PR [#2179](https://github.com/open-mmlab/mmcv/pull/2179). FileIO module from mmengine will be used wherever required. - `mmcv.runner`, `mmcv.parallel`, `mmcv. engine` and `mmcv.device`, removed in PR [#2216](https://github.com/open-mmlab/mmcv/pull/2216). - All classes in `mmcv.utils` (eg `Config` and `Registry`) and many functions, removed in PR [#2217](https://github.com/open-mmlab/mmcv/pull/2217). Only a few functions related to mmcv are reserved. -- `mmcv.onnex`, `mmcv.tensorrt` modules and related functions, removed in PR [#2225](https://github.com/open-mmlab/mmcv/pull/2225). +- `mmcv.onnx`, `mmcv.tensorrt` modules and related functions, removed in PR [#2225](https://github.com/open-mmlab/mmcv/pull/2225). - Removed all root registrars in MMCV and registered classes or functions to the [root registrar](https://github.com/open-mmlab/mmengine/blob/main/mmengine/registry/root.py) in MMEngine. (2) It added the [`mmcv.transforms`](https://github.com/open-mmlab/mmcv/tree/main/mmcv/transforms) data transformation module. @@ -27,10 +27,12 @@ The OpenMMLab team released MMCV v2.0.0 on April 6, 2023. In the 2.x version, it ```bash # Contains ops, because the highest version of mmcv-full is less than 2.0.0, so there is no need to add version restrictions +pip install openmim mim install mmcv-full # do not contain ops -mmcv install "mmcv < 2.0.0" +pip install openmim +mim install "mmcv < 2.0.0" ``` @@ -38,10 +40,11 @@ mmcv install "mmcv < 2.0.0" ```bash # Contains ops -mim install openmim +pip install openmim mim install mmcv # Ops are not included, because the starting version of mmcv-lite is 2.0.0rc1, so there is no need to add version restrictions +pip install openmim mim install mmcv-lite ``` diff --git a/docs/en/understand_mmcv/ops.md b/docs/en/understand_mmcv/ops.md index dc21f4f070..0874bc11c6 100644 --- a/docs/en/understand_mmcv/ops.md +++ b/docs/en/understand_mmcv/ops.md @@ -4,7 +4,7 @@ We implement common ops used in detection, segmentation, etc. | Device | CPU | CUDA | MLU | MPS | Ascend | | ---------------------------- | --- | ---- | --- | --- | ------ | -| ActiveRotatedFilter | √ | √ | | | | +| ActiveRotatedFilter | √ | √ | | | √ | | AssignScoreWithK | | √ | | | | | BallQuery | | √ | √ | | | | BBoxOverlaps | | √ | √ | √ | √ | diff --git a/docs/zh_cn/compatibility.md b/docs/zh_cn/compatibility.md index f9c80e74ce..2729243f9f 100644 --- a/docs/zh_cn/compatibility.md +++ b/docs/zh_cn/compatibility.md @@ -9,7 +9,7 @@ OpenMMLab 团队于 2023 年 4 月 6 日发布 MMCV [v2.0.0](https://github.com/ - `mmcv.fileio` 模块,删除于 PR [#2179](https://github.com/open-mmlab/mmcv/pull/2179)。在需要使用 FileIO 的地方使用 mmengine 中的 FileIO 模块 - `mmcv.runner`、`mmcv.parallel`、`mmcv.engine` 和 `mmcv.device`,删除于 PR [#2216](https://github.com/open-mmlab/mmcv/pull/2216) - `mmcv.utils` 的所有类(例如 `Config` 和 `Registry`)和大部分函数,删除于 PR [#2217](https://github.com/open-mmlab/mmcv/pull/2217),只保留少数和 mmcv 相关的函数 -- `mmcv.onnex`、`mmcv.tensorrt` 模块以及相关的函数,删除于 PR [#2225](https://github.com/open-mmlab/mmcv/pull/2225) +- `mmcv.onnx`、`mmcv.tensorrt` 模块以及相关的函数,删除于 PR [#2225](https://github.com/open-mmlab/mmcv/pull/2225) - 删除 MMCV 所有的根注册器并将类或者函数注册到 MMEngine 的[根注册器](https://github.com/open-mmlab/mmengine/blob/main/mmengine/registry/root.py) (2)新增了 [`mmcv.transforms`](https://github.com/open-mmlab/mmcv/tree/main/mmcv/transforms) 数据变换模块 @@ -27,10 +27,12 @@ OpenMMLab 团队于 2023 年 4 月 6 日发布 MMCV [v2.0.0](https://github.com/ ```bash # 包含算子,因为 mmcv-full 的最高版本小于 2.0.0,所以无需加版本限制 +pip install openmim mim install mmcv-full # 不包含算子 -mmcv install "mmcv < 2.0.0" +pip install openmim +mim install "mmcv < 2.0.0" ``` @@ -38,11 +40,12 @@ mmcv install "mmcv < 2.0.0" ```bash # 包含算子 -mim install openmim +pip install openmim mim install mmcv # 不包含算子,因为 mmcv-lite 的起始版本为 2.0.0,所以无需加版本限制 -pip install mmcv-lite +pip install openmim +mim install mmcv-lite ``` diff --git a/docs/zh_cn/understand_mmcv/ops.md b/docs/zh_cn/understand_mmcv/ops.md index 067e8f2199..3bffca5071 100644 --- a/docs/zh_cn/understand_mmcv/ops.md +++ b/docs/zh_cn/understand_mmcv/ops.md @@ -4,7 +4,7 @@ MMCV 提供了检测、分割等任务中常用的算子 | Device | CPU | CUDA | MLU | MPS | Ascend | | ---------------------------- | --- | ---- | --- | --- | ------ | -| ActiveRotatedFilter | √ | √ | | | | +| ActiveRotatedFilter | √ | √ | | | √ | | AssignScoreWithK | | √ | | | | | BallQuery | | √ | √ | | | | BBoxOverlaps | | √ | √ | √ | √ | diff --git a/mmcv/ops/csrc/pytorch/npu/active_rotated_filter_npu.cpp b/mmcv/ops/csrc/pytorch/npu/active_rotated_filter_npu.cpp new file mode 100644 index 0000000000..b6363fefbf --- /dev/null +++ b/mmcv/ops/csrc/pytorch/npu/active_rotated_filter_npu.cpp @@ -0,0 +1,36 @@ +#include "pytorch_npu_helper.hpp" + +using namespace NPU_NAME_SPACE; +using namespace std; + +void active_rotated_filter_forward_impl(const Tensor input, + const Tensor indices, Tensor output); + +void active_rotated_filter_backward_impl(const Tensor grad_out, + const Tensor indices, Tensor grad_in); + +void active_rotated_filter_forward_npu(const Tensor input, const Tensor indices, + Tensor output) { + OpCommand cmd; + cmd.Name("ActiveRotatedFilter") + .Input(input) + .Input(indices) + .Output(output) + .Run(); +} + +void active_rotated_filter_backward_npu(const Tensor grad_out, + const Tensor indices, Tensor grad_in) { + OpCommand cmd; + cmd.Name("ActiveRotatedFilterGrad") + .Input(grad_out) + .Input(indices) + .Output(grad_in) + .Run(); +} + +REGISTER_NPU_IMPL(active_rotated_filter_forward_impl, + active_rotated_filter_forward_npu); + +REGISTER_NPU_IMPL(active_rotated_filter_backward_impl, + active_rotated_filter_backward_npu); diff --git a/tests/test_ops/test_active_rotated_filter.py b/tests/test_ops/test_active_rotated_filter.py index 30ea59c5c6..c2f7295abd 100644 --- a/tests/test_ops/test_active_rotated_filter.py +++ b/tests/test_ops/test_active_rotated_filter.py @@ -4,6 +4,7 @@ import torch from mmcv.ops import active_rotated_filter +from mmcv.utils import IS_CUDA_AVAILABLE, IS_NPU_AVAILABLE np_feature = np.array([[[[[-1.4934e-01, 1.1341e+00, -1.6241e-01], [-1.0986e+00, -1.1463e+00, -1.3176e+00], @@ -245,7 +246,11 @@ pytest.param( 'cuda', marks=pytest.mark.skipif( - not torch.cuda.is_available(), reason='requires CUDA support')), + not IS_CUDA_AVAILABLE, reason='requires CUDA support')), + pytest.param( + 'npu', + marks=pytest.mark.skipif( + not IS_NPU_AVAILABLE, reason='requires NPU support')) ]) def test_active_rotated_filter(device): feature = torch.tensor(