From eddb27b303feb5818caff836e72fafcb987c9cb6 Mon Sep 17 00:00:00 2001 From: gongdaguo Date: Sat, 10 Jul 2021 15:43:42 +0800 Subject: [PATCH] fix matmul and convolution delegate --- .../src/runtime/kernel/arm/fp16/convolution_delegate_fp16.cc | 2 ++ .../src/runtime/kernel/arm/fp16/convolution_delegate_fp16.h | 4 ++-- .../lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc | 4 ++++ .../src/runtime/kernel/arm/fp32/convolution_delegate_fp32.h | 3 ++- .../lite/src/runtime/kernel/arm/fp32/matmul_fp32_base.cc | 1 + mindspore/lite/src/tensor.cc | 2 +- 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.cc index 89aaee606e..9b987c44c5 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.cc @@ -39,10 +39,12 @@ void ConvolutionDelegateFP16CPUKernel::FreeCopiedData() { if ((origin_weight_ != nullptr) && (need_free_ & WEIGHT_NEED_FREE)) { free(origin_weight_); origin_weight_ = nullptr; + need_free_ = need_free_ & ~WEIGHT_NEED_FREE; } if ((origin_bias_ != nullptr) && (need_free_ & BIAS_NEED_FREE)) { free(origin_bias_); origin_bias_ = nullptr; + need_free_ = need_free_ & ~BIAS_NEED_FREE; } } diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.h b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.h index 503b76288c..12018df715 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/convolution_delegate_fp16.h @@ -22,8 +22,8 @@ #include "nnacl/conv_parameter.h" #include "nnacl/op_base.h" -#define WEIGHT_NEED_FREE 0b01 -#define BIAS_NEED_FREE 0b10 +#define WEIGHT_NEED_FREE 0001 +#define BIAS_NEED_FREE 0010 namespace mindspore::kernel { class ConvolutionDelegateFP16CPUKernel : public InnerKernel { diff --git a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc index 6cb9f0ab27..0e19800de1 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp16/matmul_base_fp16.cc @@ -36,6 +36,10 @@ int MatmulBaseFP16Run(void *cdata, int task_id, float lhs_scale, float rhs_scale } MatmulBaseFP16CPUKernel::~MatmulBaseFP16CPUKernel() { + if (src_b_ != nullptr) { + free(src_b_); + src_b_ = nullptr; + } if (bias_ptr_ != nullptr) { free(bias_ptr_); bias_ptr_ = nullptr; diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_delegate_fp32.h b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_delegate_fp32.h index 9a3e4cc90c..66bda6832e 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_delegate_fp32.h +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/convolution_delegate_fp32.h @@ -72,13 +72,14 @@ class ConvolutionDelegateCPUKernel : public InnerKernel { if (origin_weight_ != nullptr && need_free_weight_) { free(origin_weight_); origin_weight_ = nullptr; + need_free_weight_ = false; } if (origin_bias_ != nullptr && need_free_bias_) { free(origin_bias_); origin_bias_ = nullptr; + need_free_bias_ = false; } } - // Train API int Eval() override { InnerKernel::Eval(); diff --git a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32_base.cc b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32_base.cc index a2164b19dc..af6e787f19 100644 --- a/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32_base.cc +++ b/mindspore/lite/src/runtime/kernel/arm/fp32/matmul_fp32_base.cc @@ -35,6 +35,7 @@ MatmulFp32BaseCPUKernel::~MatmulFp32BaseCPUKernel() { FreeResizeBufA(); FreeResizeBufB(); FreeBiasBuf(); + FreeBuffSrcB(); } void MatmulFp32BaseCPUKernel::InitParameter() { diff --git a/mindspore/lite/src/tensor.cc b/mindspore/lite/src/tensor.cc index 25a69e8ad1..70f14ff1f0 100644 --- a/mindspore/lite/src/tensor.cc +++ b/mindspore/lite/src/tensor.cc @@ -203,7 +203,7 @@ size_t Tensor::Size() const { size_t element_size = DataTypeSize(this->data_type_); auto element_num = (format_ == mindspore::NC4HW4 || format_ == mindspore::NHWC4) ? ElementsC4Num() : ElementsNum(); if (element_num < 0) { - MS_LOG(ERROR) << "Element number of tensor should large than 0 : " << element_num; + MS_LOG(INFO) << "Element number of tensor should large than 0 : " << element_num; return 0; } return element_size * element_num;