From e5404231799a07e731ed0e4d8f0825e8ccc2a069 Mon Sep 17 00:00:00 2001 From: Hector Li Date: Fri, 3 May 2024 08:55:31 -0700 Subject: [PATCH] [QNN EP] Conv ConvTranspose 3D support (#20507) ### Description Support Conv ConvTranspose 3D for QNN EP --- onnxruntime/core/providers/common.h | 19 + .../cpu/nn/conv_transpose_attributes.h | 19 - .../qnn/builder/opbuilder/base_op_builder.h | 56 +- .../qnn/builder/opbuilder/conv_op_builder.cc | 245 ++++----- .../builder/opbuilder/simple_op_builder.cc | 11 - .../core/providers/qnn/builder/qnn_def.h | 5 + .../providers/qnn/builder/qnn_model_wrapper.h | 26 +- .../core/providers/qnn/builder/qnn_utils.cc | 6 + onnxruntime/test/onnx/main.cc | 3 +- onnxruntime/test/providers/qnn/conv_test.cc | 510 ++++++++++++++++-- 10 files changed, 684 insertions(+), 216 deletions(-) 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