From 9da19e9da660057785fb736aba5c61b1ae773f2f Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Thu, 11 Oct 2018 15:33:11 +0100 Subject: COMPMID-1605: API alignment for the MemoryManager with ARMNN Change-Id: Iac6a95ba7f388e65b7f1c8865c3e9bf289b233ea Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/155490 Reviewed-by: Anthony Barbier Tested-by: bsgcomp --- arm_compute/graph/GraphContext.h | 1 + arm_compute/runtime/IMemoryManager.h | 19 ++++++++++++++--- arm_compute/runtime/IPoolManager.h | 10 +++++++++ arm_compute/runtime/MemoryManagerOnDemand.h | 33 ++++++----------------------- arm_compute/runtime/PoolManager.h | 4 +++- 5 files changed, 36 insertions(+), 31 deletions(-) (limited to 'arm_compute') diff --git a/arm_compute/graph/GraphContext.h b/arm_compute/graph/GraphContext.h index b77eb1404d..21ba6df785 100644 --- a/arm_compute/graph/GraphContext.h +++ b/arm_compute/graph/GraphContext.h @@ -42,6 +42,7 @@ struct MemoryManagerContext std::shared_ptr intra_mm = { nullptr }; /**< Intra-function memory manager */ std::shared_ptr cross_mm = { nullptr }; /**< Cross-function memory manager */ std::shared_ptr cross_group = { nullptr }; /**< Cross-function memory group */ + IAllocator *allocator = { nullptr }; /**< Backend allocator to use */ }; /** Graph context **/ diff --git a/arm_compute/runtime/IMemoryManager.h b/arm_compute/runtime/IMemoryManager.h index 00aa566a50..9280b309e0 100644 --- a/arm_compute/runtime/IMemoryManager.h +++ b/arm_compute/runtime/IMemoryManager.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -31,6 +31,8 @@ namespace arm_compute { +// Forward declarations +class IAllocator; class IMemoryGroup; /** Memory manager interface to handle allocations of backing memory */ @@ -49,8 +51,19 @@ public: * @return The pool manager */ virtual IPoolManager *pool_manager() = 0; - /** Finalize memory manager */ - virtual void finalize() = 0; + /** Populates the pool manager with the given number of pools + * + * @pre Pool manager must be empty + * + * @param[in] allocator Allocator to use for the backing allocations + * @param[in] num_pools Number of pools to create + */ + virtual void populate(IAllocator &allocator, size_t num_pools) = 0; + /** Clears the pool manager + * + * @pre All pools must be unoccupied + */ + virtual void clear() = 0; }; } // arm_compute #endif /*__ARM_COMPUTE_IMEMORYMANAGER_H__ */ diff --git a/arm_compute/runtime/IPoolManager.h b/arm_compute/runtime/IPoolManager.h index 4cc3c07b5f..6f5af3d499 100644 --- a/arm_compute/runtime/IPoolManager.h +++ b/arm_compute/runtime/IPoolManager.h @@ -53,6 +53,16 @@ public: * @param[in] pool Pool to be managed */ virtual void register_pool(std::unique_ptr pool) = 0; + /** Releases a free pool from the managed pools + * + * @return The released pool in case a free pool existed else nullptr + */ + virtual std::unique_ptr release_pool() = 0; + /** Clears all pools managed by the pool manager + * + * @pre All pools must be unoccupied + */ + virtual void clear_pools() = 0; /** Returns the total number of pools managed by the pool manager * * @return Number of managed pools diff --git a/arm_compute/runtime/MemoryManagerOnDemand.h b/arm_compute/runtime/MemoryManagerOnDemand.h index ad4b831e1f..43f557effc 100644 --- a/arm_compute/runtime/MemoryManagerOnDemand.h +++ b/arm_compute/runtime/MemoryManagerOnDemand.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -21,23 +21,19 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#ifndef __ARM_COMPUTE_MEMORYMANAGERONDEMAND_H__ -#define __ARM_COMPUTE_MEMORYMANAGERONDEMAND_H__ +#ifndef __ARM_COMPUTE_MEMORY_MANAGER_ON_DEMAND_H__ +#define __ARM_COMPUTE_MEMORY_MANAGER_ON_DEMAND_H__ #include "arm_compute/runtime/IMemoryManager.h" -#include "IAllocator.h" #include "arm_compute/runtime/ILifetimeManager.h" #include "arm_compute/runtime/IMemoryGroup.h" #include "arm_compute/runtime/IPoolManager.h" #include -#include namespace arm_compute { -class IAllocator; - /** On-demand memory manager */ class MemoryManagerOnDemand : public IMemoryManager { @@ -52,33 +48,16 @@ public: MemoryManagerOnDemand(MemoryManagerOnDemand &&) = default; /** Allow instances of this class to be moved */ MemoryManagerOnDemand &operator=(MemoryManagerOnDemand &&) = default; - /** Sets the number of pools to create - * - * @param[in] num_pools Number of pools - */ - void set_num_pools(unsigned int num_pools); - /** Sets the allocator to be used for configuring the pools - * - * @param[in] allocator Allocator to use - */ - void set_allocator(IAllocator *allocator); - /** Checks if the memory manager has been finalized - * - * @return True if the memory manager has been finalized else false - */ - bool is_finalized() const; // Inherited methods overridden: ILifetimeManager *lifetime_manager() override; IPoolManager *pool_manager() override; - void finalize() override; + void populate(IAllocator &allocator, size_t num_pools) override; + void clear() override; private: std::shared_ptr _lifetime_mgr; /**< Lifetime manager */ std::shared_ptr _pool_mgr; /**< Memory pool manager */ - IAllocator *_allocator; /**< Allocator used for backend allocations */ - bool _is_finalized; /**< Flag that notes if the memory manager has been finalized */ - unsigned int _num_pools; /**< Number of pools to create */ }; } // arm_compute -#endif /*__ARM_COMPUTE_MEMORYMANAGERONDEMAND_H__ */ +#endif /*__ARM_COMPUTE_MEMORY_MANAGER_ON_DEMAND_H__ */ diff --git a/arm_compute/runtime/PoolManager.h b/arm_compute/runtime/PoolManager.h index 509080532a..4f0f5384e0 100644 --- a/arm_compute/runtime/PoolManager.h +++ b/arm_compute/runtime/PoolManager.h @@ -56,7 +56,9 @@ public: IMemoryPool *lock_pool() override; void unlock_pool(IMemoryPool *pool) override; void register_pool(std::unique_ptr pool) override; - size_t num_pools() const override; + std::unique_ptr release_pool() override; + void clear_pools() override; + size_t num_pools() const override; private: std::list> _free_pools; /**< List of free pools */ -- cgit v1.2.1