From 475b2c9cd79dc4121dea162a713d496434e63785 Mon Sep 17 00:00:00 2001 From: fuzhiye Date: Mon, 22 Feb 2021 16:35:44 +0800 Subject: [PATCH] fix bug of pad_fp16 op, didn't get correct paddings array --- mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc | 6 ++++++ mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.h | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc index 8fb4c8d5e5a..76e6ee8686a 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/pad_fp16.cc @@ -26,6 +26,9 @@ using mindspore::lite::RET_OK; using mindspore::schema::PrimitiveType_Pad; namespace mindspore::kernel { +namespace { +constexpr size_t kPadMaxInputSize = 2; +} // namespace int PadFp16CPUKernel::RunImpl(int task_id) { PadFp16(input_, output_, in_, out_, pad_param_->paddings_, task_id, context_->thread_num_); return RET_OK; @@ -48,6 +51,9 @@ int PadFp16CPUKernel::Run() { int ret = 0; if (pad_param_->pad_mode_ == static_cast(schema::PaddingMode_CONSTANT)) { + if (in_tensors_.size() == kPadMaxInputSize) { + CopyPaddingFromInput(); + } if (pad_param_->constant_value_ - 0.0f < 1e-5) { memset(output_, 0, output_tensor->ElementsNum() * sizeof(float16_t)); } else { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.h index 0ab8131bcb4..92d15be16d9 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/pad_fp32.h @@ -47,7 +47,6 @@ class PadCPUKernel : public LiteKernel { private: int CheckPaddings(int *paddings, int length, int *input_shape, int mode); - int CopyPaddingFromInput(); void CalculateStrides(); int ExtendShape(int *shape, int length, const int *ori_shape, int rank); int ExtendPaddings(int *paddings, int length, const int *ori_paddings, int ori_length); @@ -55,6 +54,7 @@ class PadCPUKernel : public LiteKernel { protected: int HandleMirrorPad(); + int CopyPaddingFromInput(); PadParameter *pad_param_ = nullptr; int in_[4] = {0}; int out_[4] = {0};