Browse Source

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

tags/v1.1.0
yangruoqi713 5 years ago
parent
commit
c942c484e9
3 changed files with 37 additions and 32 deletions
  1. +16
    -13
      mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc
  2. +19
    -0
      mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc
  3. +2
    -19
      mindspore/lite/src/runtime/kernel/arm/fp32/lstm.h

+ 16
- 13
mindspore/lite/src/runtime/kernel/arm/fp16/deconvolution_depthwise_fp16.cc View File

@@ -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;
}



+ 19
- 0
mindspore/lite/src/runtime/kernel/arm/fp32/lstm.cc View File

@@ -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);


+ 2
- 19
mindspore/lite/src/runtime/kernel/arm/fp32/lstm.h View File

@@ -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