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 <anthony.barbier@arm.com>
Tested-by: bsgcomp <bsgcomp@arm.com>
diff --git a/arm_compute/runtime/IMemoryManager.h b/arm_compute/runtime/IMemoryManager.h
index 00aa566..9280b30 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 @@
      * @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 4cc3c07..6f5af3d 100644
--- a/arm_compute/runtime/IPoolManager.h
+++ b/arm_compute/runtime/IPoolManager.h
@@ -53,6 +53,16 @@
      * @param[in] pool Pool to be managed
      */
     virtual void register_pool(std::unique_ptr<IMemoryPool> 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<IMemoryPool> 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 ad4b831..43f557e 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 <memory>
-#include <set>
 
 namespace arm_compute
 {
-class IAllocator;
-
 /** On-demand memory manager */
 class MemoryManagerOnDemand : public IMemoryManager
 {
@@ -52,33 +48,16 @@
     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<ILifetimeManager> _lifetime_mgr; /**< Lifetime manager */
     std::shared_ptr<IPoolManager>     _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 5090805..4f0f538 100644
--- a/arm_compute/runtime/PoolManager.h
+++ b/arm_compute/runtime/PoolManager.h
@@ -56,7 +56,9 @@
     IMemoryPool *lock_pool() override;
     void unlock_pool(IMemoryPool *pool) override;
     void register_pool(std::unique_ptr<IMemoryPool> pool) override;
-    size_t num_pools() const override;
+    std::unique_ptr<IMemoryPool> release_pool() override;
+    void                         clear_pools() override;
+    size_t                       num_pools() const override;
 
 private:
     std::list<std::unique_ptr<IMemoryPool>> _free_pools;     /**< List of free pools */