diff --git a/onnxruntime/core/providers/common.h b/onnxruntime/core/providers/common.h index 16c8e2045f..564c7690c8 100644 --- a/onnxruntime/core/providers/common.h +++ b/onnxruntime/core/providers/common.h @@ -146,6 +146,25 @@ inline Status ComputePadAndOutputShape(const int64_t in_dim, return Status::OK(); } +constexpr inline int64_t ComputeTotalPad(int64_t in_size, int64_t stride, int64_t adj, + int64_t kernel, int64_t dilation, int64_t out_size) { + return std::max(0, (in_size - 1) * stride + adj + (kernel - 1) * dilation + 1 - out_size); +} + +inline void DistributePadding(AutoPadType pad_type, const int64_t& total_pad, + int64_t& pad_head, int64_t& pad_tail) { + if (pad_type == AutoPadType::SAME_UPPER) { + // pad more on tail when total_pad is odd. + pad_head = total_pad / 2; + pad_tail = total_pad - total_pad / 2; + } else { + // When pad_type is NOTSET, SAME_LOWER or VALID, + // pad more on head when total_pad is odd. + pad_head = total_pad - total_pad / 2; + pad_tail = total_pad / 2; + } +} + // Note: This helper function will not have overflow protection template