!7336 [MSLITE][Develop] fix memory leak bug of arm cpu fp16 op deconv_depthwise

Merge pull request !7336 from yangruoqi713/bugfix
pull/7336/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit 1e678a84dc

@ -53,21 +53,24 @@ int DeconvolutionDepthwiseFp16CPUKernel::InitSlideParam() {
}
int DeconvolutionDepthwiseFp16CPUKernel::InitBuffer() {
int C8 = UP_DIV(conv_param_->input_channel_, C8NUM);
int pack_input_size = conv_param_->input_batch_ * conv_param_->input_h_ * conv_param_->input_w_ * C8NUM * C8;
packed_input_ = reinterpret_cast<float16_t *>(context_->allocator->Malloc(pack_input_size * sizeof(float16_t)));
if (packed_input_ == nullptr) {
MS_LOG(ERROR) << "Malloc buffer failed.";
return RET_ERROR;
}
if (conv_param_->input_channel_ % C8NUM != 0) {
need_align_ = true;
int C8 = UP_DIV(conv_param_->input_channel_, C8NUM);
int pack_input_size = conv_param_->input_batch_ * conv_param_->input_h_ * conv_param_->input_w_ * C8NUM * C8;
packed_input_ = reinterpret_cast<float16_t *>(context_->allocator->Malloc(pack_input_size * sizeof(float16_t)));
if (packed_input_ == nullptr) {
MS_LOG(ERROR) << "Malloc buffer failed.";
return RET_ERROR;
}
int pack_output_size = conv_param_->output_batch_ * conv_param_->output_h_ * conv_param_->output_w_ * C8NUM * C8;
packed_output_ = reinterpret_cast<float16_t *>(context_->allocator->Malloc(pack_output_size * sizeof(float16_t)));
if (packed_output_ == nullptr) {
MS_LOG(ERROR) << "Malloc buffer failed.";
return RET_ERROR;
int pack_output_size = conv_param_->output_batch_ * conv_param_->output_h_ * conv_param_->output_w_ * C8NUM * C8;
packed_output_ = reinterpret_cast<float16_t *>(context_->allocator->Malloc(pack_output_size * sizeof(float16_t)));
if (packed_output_ == nullptr) {
MS_LOG(ERROR) << "Malloc buffer failed.";
return RET_ERROR;
}
memset(packed_output_, 0, pack_output_size * sizeof(float16_t));
}
memset(packed_output_, 0, pack_output_size * sizeof(float16_t));
return RET_OK;
}

@ -27,6 +27,25 @@ using mindspore::lite::RET_OK;
using mindspore::schema::PrimitiveType_Lstm;
namespace mindspore::kernel {
void LstmCPUKernel::FreeTmpBuffer() {
if (gate_buffer_ != nullptr) {
free(gate_buffer_);
gate_buffer_ = nullptr;
}
if (weight_i_ptr_ != nullptr) {
free(weight_i_ptr_);
weight_i_ptr_ = nullptr;
}
if (weight_h_ptr_ != nullptr) {
free(weight_h_ptr_);
weight_h_ptr_ = nullptr;
}
if (bias_ptr_ != nullptr) {
free(bias_ptr_);
bias_ptr_ = nullptr;
}
}
int LstmCPUKernel::InitParam() {
auto input = in_tensors_.front();
MS_ASSERT(input != nullptr);

@ -37,29 +37,12 @@ class LstmCPUKernel : public LiteKernel {
int ReSize() override;
int Run() override;
private:
void FreeTmpBuffer();
int InitParam();
int InitBuffer();
int InitWeightBias();
private:
void FreeTmpBuffer() {
if (gate_buffer_ != nullptr) {
free(gate_buffer_);
gate_buffer_ = nullptr;
}
if (weight_i_ptr_ != nullptr) {
free(weight_i_ptr_);
weight_i_ptr_ = nullptr;
}
if (weight_h_ptr_ != nullptr) {
free(weight_h_ptr_);
weight_h_ptr_ = nullptr;
}
if (bias_ptr_ != nullptr) {
free(bias_ptr_);
bias_ptr_ = nullptr;
}
}
float *gate_buffer_ = nullptr;
float *weight_i_ptr_ = nullptr;
float *weight_h_ptr_ = nullptr;

Loading…
Cancel
Save