From 1ea51762d34fb568fe77ebd59d12685957b393ba Mon Sep 17 00:00:00 2001 From: juncaipeng <52520497+juncaipeng@users.noreply.github.com> Date: Wed, 25 Dec 2019 20:15:19 +0800 Subject: [PATCH] fix mask rcnn error when run twice, test=develop (#2675) add clear for tensor --- lite/core/memory.h | 1 + lite/core/tensor.h | 4 ++++ lite/kernels/arm/conditional_block_compute.cc | 3 +++ lite/kernels/arm/split_lod_tensor_compute.cc | 4 ++++ 4 files changed, 12 insertions(+) diff --git a/lite/core/memory.h b/lite/core/memory.h index 18b9958911..001db760a0 100644 --- a/lite/core/memory.h +++ b/lite/core/memory.h @@ -120,6 +120,7 @@ class Buffer { if (space_ > 0) { TargetFree(target_, data_); } + data_ = nullptr; target_ = TargetType::kHost; space_ = 0; } diff --git a/lite/core/tensor.h b/lite/core/tensor.h index a1141c613e..de08aa82f3 100644 --- a/lite/core/tensor.h +++ b/lite/core/tensor.h @@ -176,6 +176,10 @@ class TensorLite { (static_cast(buffer_->data()) + offset_)); } + void clear() { + buffer_->Free(); + offset_ = 0; + } size_t data_size() const { return this->dims().production(); } size_t memory_size() const { return memory_size_; } diff --git a/lite/kernels/arm/conditional_block_compute.cc b/lite/kernels/arm/conditional_block_compute.cc index 225709b793..f0bd43e130 100644 --- a/lite/kernels/arm/conditional_block_compute.cc +++ b/lite/kernels/arm/conditional_block_compute.cc @@ -34,6 +34,9 @@ void ConditionalBlockCompute::PrepareForRun() { } void ConditionalBlockCompute::Run() { auto& param = Param(); + for (auto& out : param.outs) { + out->clear(); + } bool need_run = true; if (param.is_scalar_condition) { auto* cond = param.cond; diff --git a/lite/kernels/arm/split_lod_tensor_compute.cc b/lite/kernels/arm/split_lod_tensor_compute.cc index 16603bc5fd..8bb5e4ae6b 100644 --- a/lite/kernels/arm/split_lod_tensor_compute.cc +++ b/lite/kernels/arm/split_lod_tensor_compute.cc @@ -82,6 +82,10 @@ void SplitLodTensorCompute::Run() { ranges.begin(), ranges.end(), 0UL, [](size_t a, const CopyRange &b) { return a + b.end - b.begin; }); + if (height == 0) { + out->clear(); + continue; + } auto x_dim = x->dims(); x_dim[0] = static_cast(height); out->Resize(x_dim); -- GitLab