| 57 | |
| 58 | private: |
| 59 | void Compute(user_op::KernelComputeContext* ctx) const override { |
| 60 | const user_op::Tensor* x = ctx->Tensor4ArgNameAndIndex("x", 0); |
| 61 | user_op::Tensor* y = ctx->Tensor4ArgNameAndIndex("y", 0); |
| 62 | const int64_t num_axes = x->shape_view().NumAxes(); |
| 63 | const std::string& padding = ctx->Attr<std::string>("padding"); |
| 64 | const std::string& data_format = ctx->Attr<std::string>("data_format"); |
| 65 | const std::vector<int32_t> kernel_size = ctx->Attr<std::vector<int32_t>>("kernel_size"); |
| 66 | const std::vector<int32_t> strides = ctx->Attr<std::vector<int32_t>>("strides"); |
| 67 | const std::vector<int32_t> dilation_rate = ctx->Attr<std::vector<int32_t>>("dilation_rate"); |
| 68 | std::vector<int64_t> padding_before(num_axes, 0); |
| 69 | const size_t idx_offset = IdxOffset(data_format); |
| 70 | const int32_t num_spatial_dims = x->shape_view().NumAxes() - 2; |
| 71 | for (int32_t i = 0; i < num_spatial_dims; ++i) { |
| 72 | int32_t padding_small = 0; |
| 73 | int32_t padding_large = 0; |
| 74 | CHECK_JUST(CalcSamePadding(x->shape_view().At(idx_offset + i), kernel_size.at(i), // NOLINT |
| 75 | dilation_rate.at(i), strides.at(i), &padding_small, // NOLINT |
| 76 | &padding_large)); // NOLINT |
| 77 | if (padding == "same_lower") { |
| 78 | padding_before[idx_offset + i] = padding_large; |
| 79 | } else if (padding == "same_upper") { |
| 80 | padding_before[idx_offset + i] = padding_small; |
| 81 | } else { |
| 82 | UNIMPLEMENTED(); |
| 83 | } |
| 84 | CHECK_EQ(y->shape_view().At(idx_offset + i), |
| 85 | x->shape_view().At(idx_offset + i) + padding_small + padding_large); |
| 86 | } |
| 87 | CHECK_EQ(padding_before.size(), num_axes); |
| 88 | std::unique_ptr<ep::primitive::Fill> fill_primitive = NewFillPrimitive(ctx); |
| 89 | CHECK(fill_primitive); |
| 90 | fill_primitive->Launch(ctx->stream(), y->mut_dptr(), Scalar(0), y->shape_view().elem_cnt()); |
| 91 | DimVector src_pos_vec(num_axes, 0); |
| 92 | DimVector dst_pos_vec(padding_before.cbegin(), padding_before.cend()); |
| 93 | std::unique_ptr<ep::primitive::CopyNd> copy_nd_primitive = NewCopyNdPrimitive(ctx); |
| 94 | CHECK(copy_nd_primitive); |
| 95 | copy_nd_primitive->Launch(ctx->stream(), x->data_type(), num_axes, y->mut_dptr(), |
| 96 | y->shape_view().ptr(), dst_pos_vec.data(), x->dptr(), |
| 97 | x->shape_view().ptr(), src_pos_vec.data(), x->shape_view().ptr()); |
| 98 | } |
| 99 | bool AlwaysComputeWhenAllOutputsEmpty() const override { return false; } |
| 100 | }; |
| 101 |
nothing calls this directly
no test coverage detected