diff --git a/lite/core/memory.h b/lite/core/memory.h index 18b9958911a6173c088b415369555235d63d184d..001db760a00596306e1004fbe062f497181b1a85 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 a1141c613e29326a5f9ffb2fdc1427e3fbe84481..de08aa82f327ebfb9c84b121f6d411dbbab24ff6 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 225709b793d4718545a4077ba469c484fc8b36a3..f0bd43e1300d4034241c03d3e4ce27dcaa59c1e5 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 16603bc5fd5965e525122b76801281b0f48ccae7..8bb5e4ae6b182a8f02e5d72ca763ca0fb0d4122f 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);