From aec0d8c92e7422e711b3848951be3c683c1f59fb Mon Sep 17 00:00:00 2001 From: wuchenghui Date: Fri, 18 May 2018 14:44:35 +0800 Subject: [PATCH] fix memory reuse --- mace/core/BUILD | 7 ++++++- mace/core/tensor.h | 2 ++ mace/core/workspace.cc | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mace/core/BUILD b/mace/core/BUILD index 417c1374..d1fdd7ac 100644 --- a/mace/core/BUILD +++ b/mace/core/BUILD @@ -15,6 +15,7 @@ load( "if_production_mode", "if_not_production_mode", "if_openmp_enabled", + "if_neon_enabled", ) cc_library( @@ -47,7 +48,11 @@ cc_library( "-DMACE_ENABLE_OPENMP", ]) + if_android([ "-DMACE_ENABLE_OPENCL", - ]) + if_hexagon_enabled(["-DMACE_ENABLE_HEXAGON"]), + ]) + if_hexagon_enabled([ + "-DMACE_ENABLE_HEXAGON", + ]) + if_neon_enabled([ + "-DMACE_ENABLE_NEON", + ]), linkopts = ["-ldl"] + if_android([ "-pie", "-lm", diff --git a/mace/core/tensor.h b/mace/core/tensor.h index 8c9f3e3b..ac321f2e 100644 --- a/mace/core/tensor.h +++ b/mace/core/tensor.h @@ -222,6 +222,8 @@ class Tensor { if (buffer_ != nullptr) { MACE_CHECK(!has_opencl_image(), "Cannot resize image, use ResizeImage."); if (raw_size() + EXTRA_BUFFER_PAD_SIZE > buffer_->size()) { + LOG(WARNING) << "Resize buffer from size " << buffer_->size() << " to " + << raw_size() + EXTRA_BUFFER_PAD_SIZE; return buffer_->Resize(raw_size() + EXTRA_BUFFER_PAD_SIZE); } return MaceStatus::MACE_SUCCESS; diff --git a/mace/core/workspace.cc b/mace/core/workspace.cc index 1f653a45..73c2f8ea 100644 --- a/mace/core/workspace.cc +++ b/mace/core/workspace.cc @@ -177,7 +177,7 @@ MaceStatus Workspace::CreateOutputTensorBuffer(const NetDef &net_def, std::unique_ptr tensor_buf( new Buffer(GetDeviceAllocator(device_type))); MaceStatus status = tensor_buf->Allocate( - mem_block.x() * GetEnumTypeSize(dtype)); + mem_block.x() * GetEnumTypeSize(dtype) + EXTRA_BUFFER_PAD_SIZE); if (status != MaceStatus::MACE_SUCCESS) { return status; } -- GitLab