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

[Feature] Add NPU operator RotatedFeatureAlign #2994

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/en/understand_mmcv/ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ We implement common ops used in detection, segmentation, etc.
| PointsInBoxes | √ | √ | | | |
| PointsInPolygons | | √ | | | √ |
| PSAMask | √ | √ | √ | | √ |
| RotatedFeatureAlign | √ | √ | √ | | |
| RotatedFeatureAlign | √ | √ | √ | | |
| RoIPointPool3d | | √ | √ | | |
| RoIPool | | √ | √ | | √ |
| RoIAlignRotated | √ | √ | √ | | |
Expand Down
2 changes: 1 addition & 1 deletion docs/zh_cn/understand_mmcv/ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ MMCV 提供了检测、分割等任务中常用的算子
| PointsInBoxes | √ | √ | | | |
| PointsInPolygons | | √ | | | |
| PSAMask | √ | √ | √ | | √ |
| RotatedFeatureAlign | √ | √ | √ | | |
| RotatedFeatureAlign | √ | √ | √ | | |
| RoIPointPool3d | | √ | √ | | |
| RoIPool | | √ | √ | | √ |
| RoIAlignRotated | √ | √ | √ | | |
Expand Down
52 changes: 52 additions & 0 deletions mmcv/ops/csrc/pytorch/npu/rotated_feature_align_npu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "pytorch_npu_helper.hpp"

using namespace NPU_NAME_SPACE;
using namespace std;

void rotated_feature_align_forward_impl(const Tensor features,
const Tensor best_bboxes,
const float spatial_scale,
const int points, Tensor output);

void rotated_feature_align_backward_impl(const Tensor top_grad,
const Tensor best_bboxes,
const float spatial_scale,
const int points, Tensor bottom_grad);

void rotated_feature_align_forward_npu(const Tensor features,
const Tensor best_bboxes,
const float spatial_scale,
const int points, Tensor output) {
int64_t points_ = (int64_t)points;
at::Tensor best_bboxes_ = best_bboxes.transpose(2, 3).transpose(1, 2);
OpCommand cmd;
cmd.Name("RotatedFeatureAlign")
.Input(features)
.Input(best_bboxes_)
.Output(output)
.Attr("spatial_scale", spatial_scale)
.Attr("points", points_)
.Run();
}

void rotated_feature_align_backward_npu(const Tensor top_grad,
const Tensor best_bboxes,
const float spatial_scale,
const int points, Tensor bottom_grad) {
int64_t points_ = (int64_t)points;
at::Tensor best_bboxes_ = best_bboxes.transpose(2, 3).transpose(1, 2);
OpCommand cmd;
cmd.Name("RotatedFeatureAlignGrad")
.Input(top_grad)
.Input(best_bboxes_)
.Output(bottom_grad)
.Attr("spatial_scale", spatial_scale)
.Attr("points", points_)
.Run();
}

REGISTER_NPU_IMPL(rotated_feature_align_forward_impl,
rotated_feature_align_forward_npu);

REGISTER_NPU_IMPL(rotated_feature_align_backward_impl,
rotated_feature_align_backward_npu);
6 changes: 5 additions & 1 deletion tests/test_ops/test_rotated_feature_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import torch

from mmcv.ops import rotated_feature_align
from mmcv.utils import IS_CUDA_AVAILABLE, IS_MLU_AVAILABLE
from mmcv.utils import IS_CUDA_AVAILABLE, IS_MLU_AVAILABLE, IS_NPU_AVAILABLE


@pytest.mark.skipif(
Expand All @@ -17,6 +17,10 @@
'mlu',
marks=pytest.mark.skipif(
not IS_MLU_AVAILABLE, reason='requires MLU support')),
pytest.param(
'npu',
marks=pytest.mark.skipif(
not IS_NPU_AVAILABLE, reason='requires NPU support')),
pytest.param(
'cpu',
marks=pytest.mark.skipif(
Expand Down
Loading