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

add FusedBiasLeakyRelu npu adapter #2474

Merged
merged 83 commits into from
Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
093f462
init npu
wangjiangben-hw Sep 14, 2022
ba9c36b
Merge pull request #2261 from wangjiangben-hw/npu-dev
ckirchhoff2021 Sep 15, 2022
716b3b3
add npu extension and focal loss adapter
ckirchhoff2021 Sep 19, 2022
6e53b3f
clean code
ckirchhoff2021 Sep 20, 2022
08f0a16
clean code
ckirchhoff2021 Sep 20, 2022
da659cb
clean code
ckirchhoff2021 Sep 20, 2022
448476e
clean code
ckirchhoff2021 Sep 20, 2022
afbd351
fix autocast bugs on npu (#2273)
wangjiangben-hw Sep 20, 2022
26f35e0
code format
ckirchhoff2021 Sep 20, 2022
58618ac
code format
ckirchhoff2021 Sep 20, 2022
d75dcb1
code format
ckirchhoff2021 Sep 21, 2022
7af2a6f
bug fix
ckirchhoff2021 Sep 21, 2022
268ff0e
pytorch_npu_helper.hpp clean code
ckirchhoff2021 Sep 21, 2022
9b0133c
Merge pull request #2269 from ckirchhoff2021/npu-dev
ckirchhoff2021 Sep 28, 2022
a043541
Npu dev (#2306)
wangjiangben-hw Sep 29, 2022
90fc3dc
raise ImportError when compile with npu
wangjiangben-hw Sep 29, 2022
6ffdb57
add npu test case (#2307)
wangjiangben-hw Sep 29, 2022
3f11861
Update focal_loss.py
wangjiangben-hw Sep 29, 2022
c81daa3
add comment
wangjiangben-hw Sep 30, 2022
1cee865
clean lint
wangjiangben-hw Sep 30, 2022
5841f92
update dtype assert
wangjiangben-hw Sep 30, 2022
4ce938c
update DDP forward and comment
wangjiangben-hw Sep 30, 2022
ea1d8f8
fix bug
wangjiangben-hw Sep 30, 2022
8c0945c
sigmoidfocalloss npu adapter bug fix
ckirchhoff2021 Oct 8, 2022
183e4af
BugFix: modify softmaxFocalLoss adapter
ckirchhoff2021 Oct 9, 2022
9d1376e
BugFix: remove equal sign in the code
ckirchhoff2021 Oct 9, 2022
33dbcde
add npu install information in README
ckirchhoff2021 Oct 12, 2022
cf49223
Merge branch 'npu-dev' of https://github.com/ckirchhoff2021/mmcv into…
ckirchhoff2021 Oct 12, 2022
21b94c1
Merge pull request #2323 from ckirchhoff2021/npu-dev
ckirchhoff2021 Oct 12, 2022
09dd081
add modulatedDeformConv npu adapter
ckirchhoff2021 Nov 3, 2022
ff3ffbb
init npu
wangjiangben-hw Sep 14, 2022
57e4171
add npu extension and focal loss adapter
ckirchhoff2021 Sep 19, 2022
65b5fe1
clean code
ckirchhoff2021 Sep 20, 2022
f38b1b2
clean code
ckirchhoff2021 Sep 20, 2022
f5c156f
clean code
ckirchhoff2021 Sep 20, 2022
c5ffc60
add modulatedDeformConv npu adapter
ckirchhoff2021 Nov 3, 2022
bd3ec11
merge master branch 20221103
ckirchhoff2021 Nov 3, 2022
421cca0
Merge pull request #2381 from ckirchhoff2021/npu-dev
ckirchhoff2021 Nov 3, 2022
74d3181
remove conflicts
ckirchhoff2021 Nov 3, 2022
632e853
Merge pull request #2385 from ckirchhoff2021/npu-dev
ckirchhoff2021 Nov 3, 2022
4b9af63
Add masked_ Conv2d operator in NPU
zcc-zjut Nov 4, 2022
fee53c4
add nms_npu
Nov 2, 2022
3a970b9
fix bug
momo609 Nov 5, 2022
4647429
fix code check
momo609 Nov 5, 2022
05d57a4
fix code check
momo609 Nov 5, 2022
d0702b6
fix code check
momo609 Nov 5, 2022
57a2734
Merge pull request #2378 from momo609/npu
ckirchhoff2021 Nov 5, 2022
aa90e8e
Masked_conv2d NPU
zcc-zjut Nov 7, 2022
e3d78a8
Merge pull request #2390 from zcc-zjut/mask
ckirchhoff2021 Nov 7, 2022
8dab3a3
Masked_conv2d NPU
zcc-zjut Nov 7, 2022
97e35bc
Masked_conv2d NPU
zcc-zjut Nov 7, 2022
ab36885
Merge pull request #2394 from zcc-zjut/mask
ckirchhoff2021 Nov 7, 2022
2fb3bba
remove npu-install-info in README.md
ckirchhoff2021 Nov 8, 2022
5a9842e
Merge pull request #2398 from ckirchhoff2021/npu-dev
ckirchhoff2021 Nov 8, 2022
f1e825d
annotate the clang-format in pre-commit-config-zh-ch.yaml
ckirchhoff2021 Nov 8, 2022
2e51383
Merge pull request #2399 from ckirchhoff2021/npu-dev
ckirchhoff2021 Nov 8, 2022
b73d8cb
Clean code: fix the clean code problem in masked_conv2d and modulated…
ckirchhoff2021 Nov 14, 2022
15f1776
Merge pull request #2413 from ckirchhoff2021/npu-dev
ckirchhoff2021 Nov 14, 2022
fad6d96
Create fused_bias_leakyrelu_npu.cpp
jayggh Nov 18, 2022
5c59540
Update fused_bias_leakyrelu_npu.cpp
jayggh Dec 7, 2022
9c2c2d8
Update fused_bias_leakyrelu_npu.cpp
jayggh Dec 7, 2022
0e41281
Merge branch 'master' into npu-dev
jayggh Dec 7, 2022
4755f97
Update ops.md
jayggh Dec 7, 2022
2176a30
Update ops.md
jayggh Dec 7, 2022
e1e1f08
Update fused_bias_leakyrelu_npu.cpp
jayggh Dec 7, 2022
051f007
Merge branch 'master' into npu-dev
jayggh Dec 7, 2022
0a0f089
Update fused_bias_leakyrelu_npu.cpp
jayggh Dec 7, 2022
0f382c2
Update test_fused_bias_leakyrelu.py
jayggh Dec 8, 2022
5ea830d
Update fused_bias_leakyrelu.py
jayggh Dec 8, 2022
faf4f0c
Update test_fused_bias_leakyrelu.py
jayggh Dec 8, 2022
27a3060
Update fused_bias_leakyrelu.py
jayggh Dec 8, 2022
0ec0363
Update test_fused_bias_leakyrelu.py
jayggh Dec 8, 2022
0869a60
Update ops.md
jayggh Dec 8, 2022
5477510
amend for CI
jayggh Dec 8, 2022
15ac0eb
bugfix
jayggh Dec 8, 2022
780e3a1
amend ops.md
jayggh Dec 9, 2022
7bb7049
Update test_fused_bias_leakyrelu.py
jayggh Dec 12, 2022
f60c916
clean code
jayggh Dec 12, 2022
5b645dd
Merge branch 'master' of https://github.com/open-mmlab/mmcv into npu-dev
jayggh Dec 12, 2022
37b0d85
bugfix
jayggh Dec 12, 2022
5775477
clean code
jayggh Dec 12, 2022
2b33fa1
Update fused_bias_leakyrelu_npu.cpp
jayggh Dec 12, 2022
15a3c76
Update fused_bias_leakyrelu_npu.cpp
jayggh Dec 12, 2022
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
116 changes: 58 additions & 58 deletions docs/en/understand_mmcv/ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,61 @@

We implement common ops used in detection, segmentation, etc.

| Device | CPU | CUDA | MLU | MPS | Ascend |
| ---------------------------- | --- | ---- | --- | --- | ------ |
| ActiveRotatedFilter | √ | √ | | | |
| AssignScoreWithK | | √ | | | |
| BallQuery | | √ | | | |
| BBoxOverlaps | | √ | √ | √ | |
| BorderAlign | | √ | | | |
| BoxIouRotated | √ | √ | | | |
| BoxIouQuadri | √ | √ | | | |
| CARAFE | | √ | √ | | |
| ChamferDistance | | √ | | | |
| CrissCrossAttention | | √ | | | |
| ContourExpand | √ | | | | |
| ConvexIoU | | √ | | | |
| CornerPool | | √ | | | |
| Correlation | | √ | | | |
| Deformable Convolution v1/v2 | √ | √ | | | |
| Deformable RoIPool | | √ | √ | | |
| DiffIoURotated | | √ | | | |
| DynamicScatter | | √ | | | |
| FurthestPointSample | | √ | | | |
| FurthestPointSampleWithDist | | √ | | | |
| FusedBiasLeakyrelu | | √ | | | |
| GatherPoints | | √ | | | |
| GroupPoints | | √ | | | |
| Iou3d | | √ | √ | | |
| KNN | | √ | | | |
| MaskedConv | | √ | √ | | √ |
| MergeCells | | √ | | | |
| MinAreaPolygon | | √ | | | |
| ModulatedDeformConv2d | √ | √ | √ | | √ |
| MultiScaleDeformableAttn | | √ | √ | | |
| NMS | √ | √ | √ | | √ |
| NMSRotated | √ | √ | | | |
| NMSQuadri | √ | √ | | | |
| PixelGroup | √ | | | | |
| PointsInBoxes | √ | √ | | | |
| PointsInPolygons | | √ | | | |
| PSAMask | √ | √ | √ | | |
| RotatedFeatureAlign | √ | √ | | | |
| RoIPointPool3d | | √ | √ | | |
| RoIPool | | √ | √ | | |
| RoIAlignRotated | √ | √ | √ | | |
| RiRoIAlignRotated | | √ | | | |
| RoIAlign | √ | √ | √ | | |
| RoIAwarePool3d | | √ | √ | | |
| SAConv2d | | √ | | | |
| SigmoidFocalLoss | | √ | √ | | √ |
| SoftmaxFocalLoss | | √ | | | √ |
| SoftNMS | | √ | | | |
| Sparse Convolution | | √ | | | |
| Synchronized BatchNorm | | √ | | | |
| ThreeInterpolate | | √ | | | |
| ThreeNN | | √ | √ | | |
| TINShift | | √ | √ | | |
| UpFirDn2d | | √ | | | |
| Voxelization | √ | √ | | | |
| PrRoIPool | | √ | | | |
| Device | CPU | CUDA | MLU | MPS | NPU |
| ---------------------------- | --- | ---- | --- | --- | --- |
| ActiveRotatedFilter | √ | √ | | | |
| AssignScoreWithK | | √ | | | |
| BallQuery | | √ | | | |
| BBoxOverlaps | | √ | √ | √ | |
| BorderAlign | | √ | | | |
| BoxIouRotated | √ | √ | | | |
| BoxIouQuadri | √ | √ | | | |
| CARAFE | | √ | √ | | |
| ChamferDistance | | √ | | | |
| CrissCrossAttention | | √ | | | |
| ContourExpand | √ | | | | |
| ConvexIoU | | √ | | | |
| CornerPool | | √ | | | |
| Correlation | | √ | | | |
| Deformable Convolution v1/v2 | √ | √ | | | |
| Deformable RoIPool | | √ | √ | | |
| DiffIoURotated | | √ | | | |
| DynamicScatter | | √ | | | |
| FurthestPointSample | | √ | | | |
| FurthestPointSampleWithDist | | √ | | | |
| FusedBiasLeakyrelu | | √ | | | |
| GatherPoints | | √ | | | |
| GroupPoints | | √ | | | |
| Iou3d | | √ | √ | | |
| KNN | | √ | | | |
| MaskedConv | | √ | √ | | √ |
| MergeCells | | √ | | | |
| MinAreaPolygon | | √ | | | |
| ModulatedDeformConv2d | √ | √ | √ | | √ |
| MultiScaleDeformableAttn | | √ | √ | | |
| NMS | √ | √ | √ | | √ |
| NMSRotated | √ | √ | | | |
| NMSQuadri | √ | √ | | | |
| PixelGroup | √ | | | | |
| PointsInBoxes | √ | √ | | | |
| PointsInPolygons | | √ | | | |
| PSAMask | √ | √ | √ | | |
| RotatedFeatureAlign | √ | √ | | | |
| RoIPointPool3d | | √ | √ | | |
| RoIPool | | √ | √ | | |
| RoIAlignRotated | √ | √ | √ | | |
| RiRoIAlignRotated | | √ | | | |
| RoIAlign | √ | √ | √ | | |
| RoIAwarePool3d | | √ | √ | | |
| SAConv2d | | √ | | | |
| SigmoidFocalLoss | | √ | √ | | √ |
| SoftmaxFocalLoss | | √ | | | √ |
| SoftNMS | | √ | | | |
| Sparse Convolution | | √ | | | |
| Synchronized BatchNorm | | √ | | | |
| ThreeInterpolate | | √ | | | |
| ThreeNN | | √ | √ | | |
| TINShift | | √ | √ | | |
| UpFirDn2d | | √ | | | |
| Voxelization | √ | √ | | | |
| PrRoIPool | | √ | | | |
116 changes: 58 additions & 58 deletions docs/zh_cn/understand_mmcv/ops.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,61 @@

MMCV 提供了检测、分割等任务中常用的算子

| Device | CPU | CUDA | MLU | MPS | Ascend |
| ---------------------------- | --- | ---- | --- | --- | ------ |
| ActiveRotatedFilter | √ | √ | | | |
| AssignScoreWithK | | √ | | | |
| BallQuery | | √ | | | |
| BBoxOverlaps | | √ | √ | √ | |
| BorderAlign | | √ | | | |
| BoxIouRotated | √ | √ | | | |
| BoxIouQuadri | √ | √ | | | |
| CARAFE | | √ | √ | | |
| ChamferDistance | | √ | | | |
| CrissCrossAttention | | √ | | | |
| ContourExpand | √ | | | | |
| ConvexIoU | | √ | | | |
| CornerPool | | √ | | | |
| Correlation | | √ | | | |
| Deformable Convolution v1/v2 | √ | √ | | | |
| Deformable RoIPool | | √ | √ | | |
| DiffIoURotated | | √ | | | |
| DynamicScatter | | √ | | | |
| FurthestPointSample | | √ | | | |
| FurthestPointSampleWithDist | | √ | | | |
| FusedBiasLeakyrelu | | √ | | | |
| GatherPoints | | √ | | | |
| GroupPoints | | √ | | | |
| Iou3d | | √ | √ | | |
| KNN | | √ | | | |
| MaskedConv | | √ | √ | | √ |
| MergeCells | | √ | | | |
| MinAreaPolygon | | √ | | | |
| ModulatedDeformConv2d | √ | √ | √ | | √ |
| MultiScaleDeformableAttn | | √ | √ | | |
| NMS | √ | √ | √ | | √ |
| NMSRotated | √ | √ | | | |
| NMSQuadri | √ | √ | | | |
| PixelGroup | √ | | | | |
| PointsInBoxes | √ | √ | | | |
| PointsInPolygons | | √ | | | |
| PSAMask | √ | √ | √ | | |
| RotatedFeatureAlign | √ | √ | | | |
| RoIPointPool3d | | √ | √ | | |
| RoIPool | | √ | √ | | |
| RoIAlignRotated | √ | √ | √ | | |
| RiRoIAlignRotated | | √ | | | |
| RoIAlign | √ | √ | √ | | |
| RoIAwarePool3d | | √ | √ | | |
| SAConv2d | | √ | | | |
| SigmoidFocalLoss | | √ | √ | | √ |
| SoftmaxFocalLoss | | √ | | | √ |
| SoftNMS | | √ | | | |
| Sparse Convolution | | √ | | | |
| Synchronized BatchNorm | | √ | | | |
| ThreeInterpolate | | √ | | | |
| ThreeNN | | √ | √ | | |
| TINShift | | √ | √ | | |
| UpFirDn2d | | √ | | | |
| Voxelization | √ | √ | | | |
| PrRoIPool | | √ | | | |
| Device | CPU | CUDA | MLU | MPS | NPU |
| ---------------------------- | --- | ---- | --- | --- | --- |
| ActiveRotatedFilter | √ | √ | | | |
| AssignScoreWithK | | √ | | | |
| BallQuery | | √ | | | |
| BBoxOverlaps | | √ | √ | √ | |
| BorderAlign | | √ | | | |
| BoxIouRotated | √ | √ | | | |
| BoxIouQuadri | √ | √ | | | |
| CARAFE | | √ | √ | | |
| ChamferDistance | | √ | | | |
| CrissCrossAttention | | √ | | | |
| ContourExpand | √ | | | | |
| ConvexIoU | | √ | | | |
| CornerPool | | √ | | | |
| Correlation | | √ | | | |
| Deformable Convolution v1/v2 | √ | √ | | | |
| Deformable RoIPool | | √ | √ | | |
| DiffIoURotated | | √ | | | |
| DynamicScatter | | √ | | | |
| FurthestPointSample | | √ | | | |
| FurthestPointSampleWithDist | | √ | | | |
| FusedBiasLeakyrelu | | √ | | | |
| GatherPoints | | √ | | | |
| GroupPoints | | √ | | | |
| Iou3d | | √ | √ | | |
| KNN | | √ | | | |
| MaskedConv | | √ | √ | | √ |
| MergeCells | | √ | | | |
| MinAreaPolygon | | √ | | | |
| ModulatedDeformConv2d | √ | √ | √ | | √ |
| MultiScaleDeformableAttn | | √ | √ | | |
| NMS | √ | √ | √ | | √ |
| NMSRotated | √ | √ | | | |
| NMSQuadri | √ | √ | | | |
| PixelGroup | √ | | | | |
| PointsInBoxes | √ | √ | | | |
| PointsInPolygons | | √ | | | |
| PSAMask | √ | √ | √ | | |
| RotatedFeatureAlign | √ | √ | | | |
| RoIPointPool3d | | √ | √ | | |
| RoIPool | | √ | √ | | |
| RoIAlignRotated | √ | √ | √ | | |
| RiRoIAlignRotated | | √ | | | |
| RoIAlign | √ | √ | √ | | |
| RoIAwarePool3d | | √ | √ | | |
| SAConv2d | | √ | | | |
| SigmoidFocalLoss | | √ | √ | | √ |
| SoftmaxFocalLoss | | √ | | | √ |
| SoftNMS | | √ | | | |
| Sparse Convolution | | √ | | | |
| Synchronized BatchNorm | | √ | | | |
| ThreeInterpolate | | √ | | | |
| ThreeNN | | √ | √ | | |
| TINShift | | √ | √ | | |
| UpFirDn2d | | √ | | | |
| Voxelization | √ | √ | | | |
| PrRoIPool | | √ | | | |
60 changes: 60 additions & 0 deletions mmcv/ops/csrc/pytorch/npu/fused_bias_leakyrelu_npu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "pytorch_npu_helper.hpp"

using namespace NPU_NAME_SPACE;
using namespace std;

Tensor fused_bias_leakyrelu_op_impl(const Tensor &input, const Tensor &bias,
const Tensor &refer, int act, int grad,
float alpha, float scale);

Tensor fused_bias_leakyrelu_npu(const Tensor &input, const Tensor &bias,
const Tensor &refer, int act, int grad,
float alpha, float scale)
{
at::Tensor py = at::empty_like(input);
// forward
if (grad == 0)
{
auto input_size = input.sizes();
int input_length = input_size.size();
c10::SmallVector<int64_t, SIZE> input_size_tmp;
input_size_tmp = array_to_small_vector(input_size);
if (input_length > 1)
{
for (int i = 0; i < input_length; i++)
{
if (i != 1)
{
input_size_tmp[i] = 1;
}
}
}
at::Tensor bias_tmp = at::reshape(bias, input_size_tmp);
at::Tensor bias_ = at_npu::native::NPUNativeFunctions::npu_broadcast(
bias_tmp, input.sizes());
OpCommand cmd;
cmd.Name("FusedBiasLeakyRelu")
.Input(input)
.Input(bias_)
.Output(py)
.Attr("scale", scale)
.Attr("negative_slope", alpha)
.Run();
}

// backward
if (grad == 1)
{
OpCommand cmd;
cmd.Name("FusedBiasLeakyReluGrad")
.Input(input)
.Input(refer)
.Output(py)
.Attr("scale", scale)
.Attr("negative_slope", alpha)
.Run();
}
return py;
}

REGISTER_NPU_IMPL(fused_bias_leakyrelu_op_impl, fused_bias_leakyrelu_npu);
2 changes: 1 addition & 1 deletion mmcv/ops/fused_bias_leakyrelu.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def fused_bias_leakyrelu(input: torch.Tensor,
torch.Tensor: Feature map after non-linear activation.
"""

if not input.is_cuda:
if not input.is_cuda and input.device.type != 'npu':
return bias_leakyrelu_ref(input, bias, negative_slope, scale)

return FusedBiasLeakyReLUFunction.apply(input, bias.to(input.dtype),
Expand Down
Loading