From 45fbf9fd00cc8fa564229bd6e2c20f84bc7cafd1 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Fri, 13 Aug 2021 12:07:59 +0100 Subject: Avoid releasing weights if they are used by multiple functions Resolves: COMPMID-4769 Signed-off-by: Georgios Pinitas Change-Id: Iccadcbd68b0fd84ed3bf212e358a4ea944084a40 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/c/VisualCompute/ComputeLibrary/+/349845 Tested-by: bsgcomp Reviewed-by: Giorgio Arena Comments-Addressed: bsgcomp Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/6107 Reviewed-by: Gian Marco Iodice Reviewed-by: SiCong Li Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- src/runtime/CL/functions/CLFullyConnectedLayer.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/runtime/CL/functions/CLFullyConnectedLayer.cpp') diff --git a/src/runtime/CL/functions/CLFullyConnectedLayer.cpp b/src/runtime/CL/functions/CLFullyConnectedLayer.cpp index ae10cd23b1..c719a667a7 100644 --- a/src/runtime/CL/functions/CLFullyConnectedLayer.cpp +++ b/src/runtime/CL/functions/CLFullyConnectedLayer.cpp @@ -80,6 +80,11 @@ void CLFullyConnectedLayer::configure(const CLCompileContext &compile_context, c _impl->op->configure(compile_context, input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(), fc_info); + if(_impl->weights_manager != nullptr) + { + _impl->weights_manager->manage(weights); + } + _impl->aux_mem_req = _impl->op->workspace(); _impl->run_pack = { { ACL_SRC_0, input }, { ACL_SRC_1, weights }, { ACL_SRC_2, biases }, { ACL_DST, output } }; _impl->workspace = manage_workspace(_impl->aux_mem_req, _impl->memory_group, _impl->run_pack, _impl->run_pack); @@ -108,6 +113,19 @@ void CLFullyConnectedLayer::prepare() // Release temporary tensors that are only used in prepare stage release_temporaries(_impl->aux_mem_req, _impl->workspace); _impl->is_prepared = true; + + // Handle weights managed infrastructure + if(_impl->weights_manager != nullptr && _impl->weights_manager->are_weights_managed(_impl->original_weights)) + { + // If function marks b as unused ensure that all prepare stages are done before releasing + const ITensor *original_b = _impl->original_weights; + if(!original_b->is_used()) + { + _impl->weights_manager->mark_as_unused(original_b); + } + _impl->original_weights->mark_as_used(); + _impl->weights_manager->release(_impl->original_weights); + } } } } // namespace arm_compute -- cgit v1.2.1