|
| 1 | +#include "pytorch_npu_helper.hpp" |
| 2 | + |
| 3 | +using namespace NPU_NAME_SPACE; |
| 4 | +using namespace std; |
| 5 | + |
| 6 | +void roi_align_rotated_forward_npu(Tensor input, Tensor rois, Tensor output, |
| 7 | + int aligned_height, int aligned_width, |
| 8 | + float spatial_scale, int sampling_ratio, |
| 9 | + bool aligned, bool clockwise) { |
| 10 | + int64_t aligned_height_64 = aligned_height; |
| 11 | + int64_t aligned_width_64 = aligned_width; |
| 12 | + int64_t sampling_ratio_64 = sampling_ratio; |
| 13 | + OpCommand cmd; |
| 14 | + cmd.Name("RoiAlignRotated") |
| 15 | + .Input(input) |
| 16 | + .Input(rois) |
| 17 | + .Output(output) |
| 18 | + .Attr("pooled_h", aligned_height_64) |
| 19 | + .Attr("pooled_w", aligned_width_64) |
| 20 | + .Attr("spatial_scale", spatial_scale) |
| 21 | + .Attr("sampling_ratio", sampling_ratio_64) |
| 22 | + .Attr("aligned", aligned) |
| 23 | + .Attr("clockwise", clockwise) |
| 24 | + .Run(); |
| 25 | +} |
| 26 | + |
| 27 | +void roi_align_rotated_backward_npu(Tensor top_grad, Tensor rois, |
| 28 | + Tensor bottom_grad, int aligned_height, |
| 29 | + int aligned_width, float spatial_scale, |
| 30 | + int sampling_ratio, bool aligned, |
| 31 | + bool clockwise) { |
| 32 | + int64_t aligned_height_64 = aligned_height; |
| 33 | + int64_t aligned_width_64 = aligned_width; |
| 34 | + int64_t sampling_ratio_64 = sampling_ratio; |
| 35 | + c10::SmallVector<int64_t, SIZE> y_grad_shape = |
| 36 | + array_to_small_vector(bottom_grad.sizes()); |
| 37 | + OpCommand cmd; |
| 38 | + cmd.Name("RoiAlignRotatedGrad") |
| 39 | + .Input(top_grad) |
| 40 | + .Input(rois) |
| 41 | + .Output(bottom_grad) |
| 42 | + .Attr("y_grad_shape", y_grad_shape) |
| 43 | + .Attr("pooled_h", aligned_width_64) |
| 44 | + .Attr("pooled_w", aligned_height_64) |
| 45 | + .Attr("spatial_scale", spatial_scale) |
| 46 | + .Attr("sampling_ratio", sampling_ratio_64) |
| 47 | + .Attr("aligned", aligned) |
| 48 | + .Attr("clockwise", clockwise) |
| 49 | + .Run(); |
| 50 | +} |
| 51 | + |
| 52 | +void roi_align_rotated_forward_impl(Tensor input, Tensor rois, Tensor output, |
| 53 | + int aligned_height, int aligned_width, |
| 54 | + float spatial_scale, int sampling_ratio, |
| 55 | + bool aligned, bool clockwise); |
| 56 | + |
| 57 | +void roi_align_rotated_backward_impl(Tensor top_grad, Tensor rois, |
| 58 | + Tensor bottom_grad, int aligned_height, |
| 59 | + int aligned_width, float spatial_scale, |
| 60 | + int sampling_ratio, bool aligned, |
| 61 | + bool clockwise); |
| 62 | + |
| 63 | +REGISTER_NPU_IMPL(roi_align_rotated_forward_impl, |
| 64 | + roi_align_rotated_forward_npu); |
| 65 | +REGISTER_NPU_IMPL(roi_align_rotated_backward_impl, |
| 66 | + roi_align_rotated_backward_npu); |
0 commit comments