fix matmul and convolution delegate

This commit is contained in:
gongdaguo 2021-07-10 15:43:42 +08:00
parent c592b4bcb2
commit eddb27b303
6 changed files with 12 additions and 4 deletions

View File

@ -39,10 +39,12 @@ void ConvolutionDelegateFP16CPUKernel::FreeCopiedData() {
if ((origin_weight_ != nullptr) && (need_free_ & WEIGHT_NEED_FREE)) { if ((origin_weight_ != nullptr) && (need_free_ & WEIGHT_NEED_FREE)) {
free(origin_weight_); free(origin_weight_);
origin_weight_ = nullptr; origin_weight_ = nullptr;
need_free_ = need_free_ & ~WEIGHT_NEED_FREE;
} }
if ((origin_bias_ != nullptr) && (need_free_ & BIAS_NEED_FREE)) { if ((origin_bias_ != nullptr) && (need_free_ & BIAS_NEED_FREE)) {
free(origin_bias_); free(origin_bias_);
origin_bias_ = nullptr; origin_bias_ = nullptr;
need_free_ = need_free_ & ~BIAS_NEED_FREE;
} }
} }

View File

@ -22,8 +22,8 @@
#include "nnacl/conv_parameter.h" #include "nnacl/conv_parameter.h"
#include "nnacl/op_base.h" #include "nnacl/op_base.h"
#define WEIGHT_NEED_FREE 0b01 #define WEIGHT_NEED_FREE 0001
#define BIAS_NEED_FREE 0b10 #define BIAS_NEED_FREE 0010
namespace mindspore::kernel { namespace mindspore::kernel {
class ConvolutionDelegateFP16CPUKernel : public InnerKernel { class ConvolutionDelegateFP16CPUKernel : public InnerKernel {

View File

@ -36,6 +36,10 @@ int MatmulBaseFP16Run(void *cdata, int task_id, float lhs_scale, float rhs_scale
} }
MatmulBaseFP16CPUKernel::~MatmulBaseFP16CPUKernel() { MatmulBaseFP16CPUKernel::~MatmulBaseFP16CPUKernel() {
if (src_b_ != nullptr) {
free(src_b_);
src_b_ = nullptr;
}
if (bias_ptr_ != nullptr) { if (bias_ptr_ != nullptr) {
free(bias_ptr_); free(bias_ptr_);
bias_ptr_ = nullptr; bias_ptr_ = nullptr;

View File

@ -72,13 +72,14 @@ class ConvolutionDelegateCPUKernel : public InnerKernel {
if (origin_weight_ != nullptr && need_free_weight_) { if (origin_weight_ != nullptr && need_free_weight_) {
free(origin_weight_); free(origin_weight_);
origin_weight_ = nullptr; origin_weight_ = nullptr;
need_free_weight_ = false;
} }
if (origin_bias_ != nullptr && need_free_bias_) { if (origin_bias_ != nullptr && need_free_bias_) {
free(origin_bias_); free(origin_bias_);
origin_bias_ = nullptr; origin_bias_ = nullptr;
need_free_bias_ = false;
} }
} }
// Train API // Train API
int Eval() override { int Eval() override {
InnerKernel::Eval(); InnerKernel::Eval();

View File

@ -35,6 +35,7 @@ MatmulFp32BaseCPUKernel::~MatmulFp32BaseCPUKernel() {
FreeResizeBufA(); FreeResizeBufA();
FreeResizeBufB(); FreeResizeBufB();
FreeBiasBuf(); FreeBiasBuf();
FreeBuffSrcB();
} }
void MatmulFp32BaseCPUKernel::InitParameter() { void MatmulFp32BaseCPUKernel::InitParameter() {

View File

@ -203,7 +203,7 @@ size_t Tensor::Size() const {
size_t element_size = DataTypeSize(this->data_type_); size_t element_size = DataTypeSize(this->data_type_);
auto element_num = (format_ == mindspore::NC4HW4 || format_ == mindspore::NHWC4) ? ElementsC4Num() : ElementsNum(); auto element_num = (format_ == mindspore::NC4HW4 || format_ == mindspore::NHWC4) ? ElementsC4Num() : ElementsNum();
if (element_num < 0) { 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 0;
} }
return element_size * element_num; return element_size * element_num;