Skip to content

Commit 9f43b8c

Browse files
authored
add npu roipoint_pool3d_forward (#3147)
* add npu roipoint_pool3d_forward * nms_rotated npu add new attr is_angle
1 parent 44eab26 commit 9f43b8c

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

mmcv/ops/csrc/pytorch/npu/nms_rotated_npu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Tensor nms_rotated_npu(const Tensor dets, const Tensor scores,
2727
.Output(selectedBox)
2828
.Output(selectedIndex)
2929
.Attr("iou_threshold", (float)iou_threshold)
30+
.Attr("is_angle", false)
3031
.Run();
3132
selectedIndex = selectedIndex.to(at::kLong);
3233
return selectedIndex;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "pytorch_npu_helper.hpp"
2+
3+
using namespace NPU_NAME_SPACE;
4+
using namespace std;
5+
6+
void roipoint_pool3d_forward_impl_npu(int batch_size, int pts_num,
7+
int boxes_num, int feature_in_len,
8+
int sampled_pts_num, const Tensor xyz,
9+
const Tensor boxes3d,
10+
const Tensor pts_feature,
11+
Tensor pooled_features,
12+
Tensor pooled_empty_flag) {
13+
auto points_trans = xyz.transpose(1, 2).contiguous();
14+
auto point_features_trans = pts_feature.transpose(1, 2).contiguous();
15+
c10::SmallVector<int64_t, SIZE> features_trans_size = {
16+
xyz.size(0), boxes3d.size(1), xyz.size(2) + pts_feature.size(2),
17+
sampled_pts_num};
18+
at::Tensor pooled_features_trans =
19+
at::empty(features_trans_size, xyz.options());
20+
c10::SmallVector<int64_t, SIZE> empty_flag_size = {boxes3d.size(0),
21+
boxes3d.size(1)};
22+
EXEC_NPU_CMD(aclnnRoipointPool3dForward, points_trans, point_features_trans,
23+
boxes3d, sampled_pts_num, pooled_features_trans,
24+
pooled_empty_flag);
25+
auto pooled_features_cache =
26+
pooled_features_trans.transpose(2, 3).contiguous();
27+
pooled_features.copy_(pooled_features_cache);
28+
}
29+
30+
void roipoint_pool3d_forward_impl(int batch_size, int pts_num, int boxes_num,
31+
int feature_in_len, int sampled_pts_num,
32+
const Tensor xyz, const Tensor boxes3d,
33+
const Tensor pts_feature,
34+
Tensor pooled_features,
35+
Tensor pooled_empty_flag);
36+
37+
REGISTER_NPU_IMPL(roipoint_pool3d_forward_impl,
38+
roipoint_pool3d_forward_impl_npu);

mmcv/ops/nms.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,6 @@ def nms_rotated(dets: Tensor,
413413
input_labels = labels
414414
if dets.device.type in ('npu', 'mlu'):
415415
order = scores.new_empty(0, dtype=torch.long)
416-
if dets.device.type == 'npu':
417-
coefficient = 57.29578 # 180 / PI
418-
for i in range(dets.size()[0]):
419-
dets_cw[i][4] *= coefficient # radians to angle
420416
keep_inds = ext_module.nms_rotated(dets_cw, scores, order, dets_cw,
421417
input_labels, iou_threshold,
422418
multi_label)

tests/test_ops/test_roipoint_pool3d.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import torch
44

55
from mmcv.ops import RoIPointPool3d
6-
from mmcv.utils import IS_CUDA_AVAILABLE, IS_MLU_AVAILABLE
6+
from mmcv.utils import IS_CUDA_AVAILABLE, IS_MLU_AVAILABLE, IS_NPU_AVAILABLE
77

88

99
@pytest.mark.parametrize('device', [
@@ -14,14 +14,19 @@
1414
pytest.param(
1515
'mlu',
1616
marks=pytest.mark.skipif(
17-
not IS_MLU_AVAILABLE, reason='requires MLU support'))
17+
not IS_MLU_AVAILABLE, reason='requires MLU support')),
18+
pytest.param(
19+
'npu',
20+
marks=pytest.mark.skipif(
21+
not IS_NPU_AVAILABLE, reason='requires NPU support'))
1822
])
1923
@pytest.mark.parametrize('dtype', [
2024
torch.float, torch.half,
2125
pytest.param(
2226
torch.double,
2327
marks=pytest.mark.skipif(
24-
IS_MLU_AVAILABLE, reason='MLU does not support for double'))
28+
IS_MLU_AVAILABLE or IS_NPU_AVAILABLE,
29+
reason='MLU and NPU does not support for double'))
2530
])
2631
def test_roipoint(device, dtype):
2732
points = torch.tensor(

0 commit comments

Comments
 (0)