diff options
author | Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> | 2018-10-31 11:04:01 +0000 |
---|---|---|
committer | David Beck <david.beck@arm.com> | 2018-11-08 11:34:44 +0000 |
commit | 60578950322491e44b4203fe085c3230ead19c7a (patch) | |
tree | e68bd71cb7b90d66d69a3de25561e32a13dd4e17 /src/backends/aclCommon/BaseMemoryManager.cpp | |
parent | db49a8880ba869627e884b5ba5245a3932de218d (diff) | |
download | armnn-60578950322491e44b4203fe085c3230ead19c7a.tar.gz |
IVGCVSW-1709: Clean up memory manager bodge
* Added quick workaround for the memory management errors in the
CL/Neon unit tests
Change-Id: I56250db462cdbdc1acc0a5824807d288fb0c1d11
Diffstat (limited to 'src/backends/aclCommon/BaseMemoryManager.cpp')
-rw-r--r-- | src/backends/aclCommon/BaseMemoryManager.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/backends/aclCommon/BaseMemoryManager.cpp b/src/backends/aclCommon/BaseMemoryManager.cpp new file mode 100644 index 0000000000..4e0d14c5e4 --- /dev/null +++ b/src/backends/aclCommon/BaseMemoryManager.cpp @@ -0,0 +1,98 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// +#include "BaseMemoryManager.hpp" + +#if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED) +#include "arm_compute/runtime/BlobLifetimeManager.h" +#include "arm_compute/runtime/PoolManager.h" +#include "arm_compute/runtime/OffsetLifetimeManager.h" +#endif + +#include <boost/polymorphic_cast.hpp> + +namespace armnn +{ + +#if defined(ARMCOMPUTENEON_ENABLED) || defined(ARMCOMPUTECL_ENABLED) +BaseMemoryManager::BaseMemoryManager(std::unique_ptr<arm_compute::IAllocator> alloc, + MemoryAffinity memoryAffinity) +{ + BOOST_ASSERT(alloc); + m_Allocator = std::move(alloc); + + m_IntraLayerMemoryMgr = CreateArmComputeMemoryManager(memoryAffinity); + m_InterLayerMemoryMgr = CreateArmComputeMemoryManager(memoryAffinity); +} + +std::shared_ptr<arm_compute::MemoryManagerOnDemand> +BaseMemoryManager::CreateArmComputeMemoryManager(MemoryAffinity memoryAffinity) +{ + std::shared_ptr<arm_compute::ILifetimeManager> lifetimeManager = nullptr; + + if (memoryAffinity == MemoryAffinity::Buffer) + { + lifetimeManager = std::make_shared<arm_compute::BlobLifetimeManager>(); + } + else + { + lifetimeManager = std::make_shared<arm_compute::OffsetLifetimeManager>(); + } + + auto poolManager = std::make_shared<arm_compute::PoolManager>(); + auto memoryManager = std::make_shared<arm_compute::MemoryManagerOnDemand>(lifetimeManager, poolManager); + + return memoryManager; +} + +void BaseMemoryManager::Acquire() +{ + static const size_t s_NumPools = 1; + + // Allocate memory pools for intra-layer memory manager + BOOST_ASSERT(m_IntraLayerMemoryMgr); + m_IntraLayerMemoryMgr->populate(*m_Allocator, s_NumPools); + + // Allocate memory pools for inter-layer memory manager + BOOST_ASSERT(m_InterLayerMemoryMgr); + m_InterLayerMemoryMgr->populate(*m_Allocator, s_NumPools); + + // Acquire inter-layer memory group. NOTE: This has to come after allocating the pools + BOOST_ASSERT(m_InterLayerMemoryGroup); + m_InterLayerMemoryGroup->acquire(); +} + +void BaseMemoryManager::Release() +{ + // Release inter-layer memory group. NOTE: This has to come before releasing the pools + BOOST_ASSERT(m_InterLayerMemoryGroup); + m_InterLayerMemoryGroup->release(); + + // Release memory pools managed by intra-layer memory manager + BOOST_ASSERT(m_IntraLayerMemoryMgr); + m_IntraLayerMemoryMgr->clear(); + + // Release memory pools managed by inter-layer memory manager + BOOST_ASSERT(m_InterLayerMemoryMgr); + m_InterLayerMemoryMgr->clear(); +} +#endif + +#ifdef ARMCOMPUTENEON_ENABLED +std::shared_ptr<arm_compute::IMemoryGroup> +NeonMemoryManager::CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) +{ + return std::make_shared<arm_compute::MemoryGroup>(memoryManager); +} +#endif + +#ifdef ARMCOMPUTECL_ENABLED +std::shared_ptr<arm_compute::IMemoryGroup> +ClMemoryManager::CreateMemoryGroup(const std::shared_ptr<arm_compute::MemoryManagerOnDemand>& memoryManager) +{ + return std::make_shared<arm_compute::CLMemoryGroup>(memoryManager); +} +#endif + +} |