Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
d2aecbe4
Unverified
Commit
d2aecbe4
authored
Jun 01, 2023
by
tudejiang79
Committed by
GitHub
Jun 01, 2023
Browse files
[Feature] Add the support for rotated_feature_align with MLU (#2809)
parent
92b3e861
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
3 deletions
+122
-3
docs/en/understand_mmcv/ops.md
docs/en/understand_mmcv/ops.md
+1
-1
docs/zh_cn/understand_mmcv/ops.md
docs/zh_cn/understand_mmcv/ops.md
+1
-1
mmcv/ops/csrc/pytorch/mlu/rotated_feature_align_mlu.cpp
mmcv/ops/csrc/pytorch/mlu/rotated_feature_align_mlu.cpp
+115
-0
tests/test_ops/test_rotated_feature_align.py
tests/test_ops/test_rotated_feature_align.py
+5
-1
No files found.
docs/en/understand_mmcv/ops.md
View file @
d2aecbe4
...
@@ -41,7 +41,7 @@ We implement common ops used in detection, segmentation, etc.
...
@@ -41,7 +41,7 @@ We implement common ops used in detection, segmentation, etc.
| PointsInBoxes | √ | √ | | | |
| PointsInBoxes | √ | √ | | | |
| PointsInPolygons | | √ | | | |
| PointsInPolygons | | √ | | | |
| PSAMask | √ | √ | √ | | √ |
| PSAMask | √ | √ | √ | | √ |
| RotatedFeatureAlign | √ | √ |
| | |
| RotatedFeatureAlign | √ | √ |
√
| | |
| RoIPointPool3d | | √ | √ | | |
| RoIPointPool3d | | √ | √ | | |
| RoIPool | | √ | √ | | √ |
| RoIPool | | √ | √ | | √ |
| RoIAlignRotated | √ | √ | √ | | |
| RoIAlignRotated | √ | √ | √ | | |
...
...
docs/zh_cn/understand_mmcv/ops.md
View file @
d2aecbe4
...
@@ -41,7 +41,7 @@ MMCV 提供了检测、分割等任务中常用的算子
...
@@ -41,7 +41,7 @@ MMCV 提供了检测、分割等任务中常用的算子
| PointsInBoxes | √ | √ | | | |
| PointsInBoxes | √ | √ | | | |
| PointsInPolygons | | √ | | | |
| PointsInPolygons | | √ | | | |
| PSAMask | √ | √ | √ | | √ |
| PSAMask | √ | √ | √ | | √ |
| RotatedFeatureAlign | √ | √ |
| | |
| RotatedFeatureAlign | √ | √ |
√
| | |
| RoIPointPool3d | | √ | √ | | |
| RoIPointPool3d | | √ | √ | | |
| RoIPool | | √ | √ | | √ |
| RoIPool | | √ | √ | | √ |
| RoIAlignRotated | √ | √ | √ | | |
| RoIAlignRotated | √ | √ | √ | | |
...
...
mmcv/ops/csrc/pytorch/mlu/rotated_feature_align_mlu.cpp
0 → 100644
View file @
d2aecbe4
/*************************************************************************
* Copyright (C) 2022 by Cambricon.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*************************************************************************/
#include "mlu_common_helper.h"
void
RotatedFeatureAlignForwardMLUKernelLauncher
(
const
Tensor
features
,
const
Tensor
best_bboxes
,
const
float
spatial_scale
,
const
int
points
,
Tensor
output
)
{
auto
memory_format
=
torch_mlu
::
cnnl
::
ops
::
get_channels_last_memory_format
(
features
.
dim
());
auto
features_
=
torch_mlu
::
cnnl
::
ops
::
cnnl_contiguous
(
features
,
memory_format
);
auto
best_bboxes_contiguous
=
torch_mlu
::
cnnl
::
ops
::
cnnl_contiguous
(
best_bboxes
,
best_bboxes
.
suggest_memory_format
());
auto
output_contiguous
=
torch_mlu
::
cnnl
::
ops
::
cnnl_contiguous
(
output
,
memory_format
);
MluOpTensorDescriptor
features_desc
,
best_bboxes_desc
,
output_desc
;
features_desc
.
set_with_layout
(
features_
,
MLUOP_LAYOUT_NHWC
);
best_bboxes_desc
.
set
(
best_bboxes_contiguous
);
output_desc
.
set_with_layout
(
output_contiguous
,
MLUOP_LAYOUT_NHWC
);
// get ptr of tensors
auto
features_impl
=
torch_mlu
::
getMluTensorImpl
(
features_
);
auto
features_ptr
=
features_impl
->
cnnlMalloc
();
auto
best_bboxes_impl
=
torch_mlu
::
getMluTensorImpl
(
best_bboxes_contiguous
);
auto
best_bboxes_ptr
=
best_bboxes_impl
->
cnnlMalloc
();
auto
output_impl
=
torch_mlu
::
getMluTensorImpl
(
output_contiguous
);
auto
output_ptr
=
output_impl
->
cnnlMalloc
();
// get compute handle
auto
handle
=
mluOpGetCurrentHandle
();
mluOpRotatedFeatureAlignForward
(
handle
,
features_desc
.
desc
(),
features_ptr
,
best_bboxes_desc
.
desc
(),
best_bboxes_ptr
,
spatial_scale
,
points
,
output_desc
.
desc
(),
output_ptr
);
output
.
copy_
(
output_contiguous
);
}
void
RotatedFeatureAlignBackwardMLUKernelLauncher
(
const
Tensor
top_grad
,
const
Tensor
best_bboxes
,
const
float
spatial_scale
,
const
int
points
,
Tensor
bottom_grad
)
{
auto
memory_format
=
torch_mlu
::
cnnl
::
ops
::
get_channels_last_memory_format
(
top_grad
.
dim
());
auto
top_grad_
=
torch_mlu
::
cnnl
::
ops
::
cnnl_contiguous
(
top_grad
,
memory_format
);
auto
best_bboxes_contiguous
=
torch_mlu
::
cnnl
::
ops
::
cnnl_contiguous
(
best_bboxes
,
best_bboxes
.
suggest_memory_format
());
auto
bottom_grad_
=
torch_mlu
::
cnnl
::
ops
::
cnnl_contiguous
(
bottom_grad
,
memory_format
);
// get ptr of tensors
auto
top_grad_impl
=
torch_mlu
::
getMluTensorImpl
(
top_grad_
);
auto
top_grad_ptr
=
top_grad_impl
->
cnnlMalloc
();
auto
best_bboxes_impl
=
torch_mlu
::
getMluTensorImpl
(
best_bboxes_contiguous
);
auto
best_bboxes_ptr
=
best_bboxes_impl
->
cnnlMalloc
();
auto
bottom_grad_impl
=
torch_mlu
::
getMluTensorImpl
(
bottom_grad_
);
auto
bottom_grad_ptr
=
bottom_grad_impl
->
cnnlMalloc
();
MluOpTensorDescriptor
top_grad_desc
,
best_bboxes_desc
,
bottom_grad_desc
;
top_grad_desc
.
set_with_layout
(
top_grad_
,
MLUOP_LAYOUT_NHWC
);
best_bboxes_desc
.
set
(
best_bboxes_contiguous
);
bottom_grad_desc
.
set_with_layout
(
bottom_grad_
,
MLUOP_LAYOUT_NHWC
);
// get compute handle
auto
handle
=
mluOpGetCurrentHandle
();
mluOpRotatedFeatureAlignBackward
(
handle
,
top_grad_desc
.
desc
(),
top_grad_ptr
,
best_bboxes_desc
.
desc
(),
best_bboxes_ptr
,
spatial_scale
,
points
,
bottom_grad_desc
.
desc
(),
bottom_grad_ptr
);
bottom_grad
.
copy_
(
bottom_grad_
);
}
void
rotated_feature_align_forward_mlu
(
const
Tensor
features
,
const
Tensor
best_bboxes
,
const
float
spatial_scale
,
const
int
points
,
Tensor
output
)
{
RotatedFeatureAlignForwardMLUKernelLauncher
(
features
,
best_bboxes
,
spatial_scale
,
points
,
output
);
}
void
rotated_feature_align_backward_mlu
(
const
Tensor
top_grad
,
const
Tensor
best_bboxes
,
const
float
spatial_scale
,
const
int
points
,
Tensor
bottom_grad
)
{
RotatedFeatureAlignBackwardMLUKernelLauncher
(
top_grad
,
best_bboxes
,
spatial_scale
,
points
,
bottom_grad
);
}
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
);
REGISTER_DEVICE_IMPL
(
rotated_feature_align_forward_impl
,
MLU
,
rotated_feature_align_forward_mlu
);
REGISTER_DEVICE_IMPL
(
rotated_feature_align_backward_impl
,
MLU
,
rotated_feature_align_backward_mlu
);
tests/test_ops/test_rotated_feature_align.py
View file @
d2aecbe4
...
@@ -3,7 +3,7 @@ import pytest
...
@@ -3,7 +3,7 @@ import pytest
import
torch
import
torch
from
mmcv.ops
import
rotated_feature_align
from
mmcv.ops
import
rotated_feature_align
from
mmcv.utils
import
IS_CUDA_AVAILABLE
from
mmcv.utils
import
IS_CUDA_AVAILABLE
,
IS_MLU_AVAILABLE
@
pytest
.
mark
.
skipif
(
@
pytest
.
mark
.
skipif
(
...
@@ -13,6 +13,10 @@ from mmcv.utils import IS_CUDA_AVAILABLE
...
@@ -13,6 +13,10 @@ from mmcv.utils import IS_CUDA_AVAILABLE
'cuda'
,
'cuda'
,
marks
=
pytest
.
mark
.
skipif
(
marks
=
pytest
.
mark
.
skipif
(
not
IS_CUDA_AVAILABLE
,
reason
=
'requires CUDA support'
)),
not
IS_CUDA_AVAILABLE
,
reason
=
'requires CUDA support'
)),
pytest
.
param
(
'mlu'
,
marks
=
pytest
.
mark
.
skipif
(
not
IS_MLU_AVAILABLE
,
reason
=
'requires MLU support'
)),
pytest
.
param
(
pytest
.
param
(
'cpu'
,
'cpu'
,
marks
=
pytest
.
mark
.
skipif
(
marks
=
pytest
.
mark
.
skipif
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment