From 7000d679b5e5ea1df64a25fbe8e97ec23b95aff6 Mon Sep 17 00:00:00 2001 From: Colm Donelan Date: Wed, 21 Dec 2022 15:33:39 +0000 Subject: Deregistering custom allocators in RuntimeImpl destructor. Signed-off-by: Colm Donelan Change-Id: Ib148daf81700d9038d6e91a35c9c17e770c26e84 --- src/armnn/Runtime.cpp | 10 +++++++++- src/armnn/Runtime.hpp | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp index 75b1ee8179..cec54f4ec8 100644 --- a/src/armnn/Runtime.cpp +++ b/src/armnn/Runtime.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017, 2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -393,6 +393,7 @@ RuntimeImpl::RuntimeImpl(const IRuntime::CreationOptions& options) } // No errors so register the Custom Allocator with the BackendRegistry BackendRegistryInstance().RegisterAllocator(id, customAllocatorMapIterator->second); + m_AllocatorsAddedByThisRuntime.emplace(id); } else { @@ -428,6 +429,7 @@ RuntimeImpl::RuntimeImpl(const IRuntime::CreationOptions& options) } // No errors so register the Custom Allocator with the BackendRegistry BackendRegistryInstance().RegisterAllocator(id, customAllocatorMapIterator->second); + m_AllocatorsAddedByThisRuntime.emplace(id); } } @@ -584,6 +586,12 @@ RuntimeImpl::~RuntimeImpl() m_BackendContexts.clear(); BackendRegistryInstance().SetProfilingService(armnn::EmptyOptional()); + // Remove custom allocators that this runtime has added. + // Note: that as backends can be per process and there can be many instances of a runtime in a process an allocator + // may have been overwritten by another runtime. + for_each(m_AllocatorsAddedByThisRuntime.begin(), m_AllocatorsAddedByThisRuntime.end(), + [](BackendId id) {BackendRegistryInstance().DeregisterAllocator(id);}); + ARMNN_LOG(info) << "Shutdown time: " << std::setprecision(2) << std::fixed << armnn::GetTimeDuration(startTime).count() << " ms."; } diff --git a/src/armnn/Runtime.hpp b/src/armnn/Runtime.hpp index f5dfadf948..9d47b7898d 100644 --- a/src/armnn/Runtime.hpp +++ b/src/armnn/Runtime.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2017, 2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once @@ -157,6 +157,10 @@ private: /// Profiling Service Instance std::unique_ptr m_ProfilingService; + + /// Keep track of backend ids of the custom allocators that this instance of the runtime added. The + /// destructor can then clean up for this runtime. + std::set m_AllocatorsAddedByThisRuntime; }; } // namespace armnn -- cgit v1.2.1