-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support fps and points_in_box ops for Ascend device (#3085)
- Loading branch information
Showing
11 changed files
with
188 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "pytorch_npu_helper.hpp" | ||
|
||
using namespace NPU_NAME_SPACE; | ||
using namespace std; | ||
|
||
void furthest_point_sampling_forward_npu(Tensor points_tensor, | ||
Tensor temp_tensor, Tensor idx_tensor, | ||
int b, int n, int m) { | ||
TORCH_CHECK( | ||
(points_tensor.sizes()[1] >= m), | ||
"the num of sampled points should smaller than total num of points."); | ||
at::Tensor points_xyz = points_tensor.transpose(1, 2).contiguous(); | ||
at::Tensor nearest_dist = temp_tensor.contiguous(); | ||
EXEC_NPU_CMD(aclnnFurthestPointSampling, points_xyz, nearest_dist, m, | ||
idx_tensor); | ||
} | ||
|
||
void furthest_point_sampling_forward_impl(Tensor points_tensor, | ||
Tensor temp_tensor, Tensor idx_tensor, | ||
int b, int n, int m); | ||
|
||
REGISTER_NPU_IMPL(furthest_point_sampling_forward_impl, | ||
furthest_point_sampling_forward_npu); |
22 changes: 22 additions & 0 deletions
22
mmcv/ops/csrc/pytorch/npu/furthest_point_sampling_with_dist_npu.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "pytorch_npu_helper.hpp" | ||
using namespace NPU_NAME_SPACE; | ||
using namespace std; | ||
|
||
void furthest_point_sampling_with_dist_npu(Tensor points_tensor, | ||
Tensor temp_tensor, | ||
Tensor idx_tensor, int b, int n, | ||
int m) { | ||
auto output_size = {b, m}; | ||
at::Tensor result = | ||
at::empty(output_size, points_tensor.options().dtype(at::kInt)); | ||
EXEC_NPU_CMD(aclnnFurthestPointSamplingWithDist, points_tensor, temp_tensor, | ||
m, result); | ||
} | ||
|
||
void furthest_point_sampling_with_dist_forward_impl(Tensor points_tensor, | ||
Tensor temp_tensor, | ||
Tensor idx_tensor, int b, | ||
int n, int m); | ||
|
||
REGISTER_NPU_IMPL(furthest_point_sampling_with_dist_forward_impl, | ||
furthest_point_sampling_with_dist_npu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "pytorch_npu_helper.hpp" | ||
|
||
using namespace NPU_NAME_SPACE; | ||
|
||
void iou3d_nms3d_normal_forward_npu(const Tensor boxes, Tensor &keep, | ||
Tensor &keep_num, | ||
float nms_overlap_thresh) { | ||
int32_t box_num = boxes.size(0); | ||
int32_t data_align = 16; | ||
int32_t mask_num = ((box_num - 1) / data_align + 1) * data_align; | ||
at::Tensor mask = | ||
at::empty({box_num, mask_num}, boxes.options().dtype(at::kShort)); | ||
EXEC_NPU_CMD(aclnnNms3dNormal, boxes, nms_overlap_thresh, mask); | ||
|
||
keep = at::zeros({box_num}, mask.options()); | ||
keep_num = at::zeros(1, mask.options()); | ||
EXEC_NPU_CMD(aclnnGatherNms3dMask, mask, keep, keep_num); | ||
} | ||
|
||
void iou3d_nms3d_normal_forward_impl(const Tensor boxes, Tensor &keep, | ||
Tensor &keep_num, | ||
float nms_overlap_thresh); | ||
|
||
REGISTER_NPU_IMPL(iou3d_nms3d_normal_forward_impl, | ||
iou3d_nms3d_normal_forward_npu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "pytorch_npu_helper.hpp" | ||
|
||
using namespace NPU_NAME_SPACE; | ||
using namespace std; | ||
|
||
constexpr int32_t BOX_DIM = 7; | ||
|
||
void iou3d_nms3d_forward_npu(const Tensor boxes, Tensor &keep, Tensor &keep_num, | ||
float nms_overlap_thresh) { | ||
TORCH_CHECK((boxes.sizes()[1] == BOX_DIM), | ||
"Input boxes shape should be (N, 7)"); | ||
int32_t box_num = boxes.size(0); | ||
int32_t data_align = 16; | ||
int32_t mask_num = ((box_num - 1) / data_align + 1) * data_align; | ||
at::Tensor mask = | ||
at::empty({box_num, mask_num}, boxes.options().dtype(at::kShort)); | ||
EXEC_NPU_CMD(aclnnNms3d, boxes, nms_overlap_thresh, mask); | ||
keep = at::zeros({box_num}, mask.options()); | ||
keep_num = at::zeros(1, mask.options()); | ||
EXEC_NPU_CMD(aclnnGatherNms3dMask, mask, keep, keep_num); | ||
} | ||
|
||
void iou3d_nms3d_forward_impl(const Tensor boxes, Tensor &keep, | ||
Tensor &keep_num, float nms_overlap_thresh); | ||
|
||
REGISTER_NPU_IMPL(iou3d_nms3d_forward_impl, iou3d_nms3d_forward_npu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "pytorch_npu_helper.hpp" | ||
|
||
using namespace NPU_NAME_SPACE; | ||
using namespace std; | ||
|
||
void points_in_boxes_part_forward_impl_npu(int batch_size, int boxes_num, | ||
int pts_num, const Tensor boxes, | ||
const Tensor pts, | ||
Tensor box_idx_of_points) { | ||
c10::SmallVector<int64_t, 8> output_size = {pts.size(0), pts.size(1)}; | ||
auto boxes_trans = boxes.transpose(1, 2).contiguous(); | ||
EXEC_NPU_CMD(aclnnPointsInBox, boxes_trans, pts, box_idx_of_points); | ||
} | ||
void points_in_boxes_part_forward_impl(int batch_size, int boxes_num, | ||
int pts_num, const Tensor boxes, | ||
const Tensor pts, | ||
Tensor box_idx_of_points); | ||
REGISTER_NPU_IMPL(points_in_boxes_part_forward_impl, | ||
points_in_boxes_part_forward_impl_npu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters