diff options
author | Narumol Prangnawarat <narumol.prangnawarat@arm.com> | 2020-02-03 12:29:56 +0000 |
---|---|---|
committer | Jim Flynn <jim.flynn@arm.com> | 2020-02-03 16:36:55 +0000 |
commit | 867eba59ffd2276086a14f7b2632b390c94392d3 (patch) | |
tree | d7626f933f2a72e8c398c0f43c71b4950e980a09 /src/dynamic/sample/SampleMemoryManager.cpp | |
parent | 9d0ff74843b9d36d9f233d208e18a96de1b7d47b (diff) | |
download | armnn-867eba59ffd2276086a14f7b2632b390c94392d3.tar.gz |
IVGCVSW-4399 Create Sample Dynamic backend
* Move IWorkload and WorkloadInfo to include/armnn/backends
* Add simple sample dynamic backend with addition workload
* Add sample example to run dynamic backend
* Unit tests
Signed-off-by: Narumol Prangnawarat <narumol.prangnawarat@arm.com>
Change-Id: I0753ce35b8e8a6223a1471388b49246d82438a44
Diffstat (limited to 'src/dynamic/sample/SampleMemoryManager.cpp')
-rw-r--r-- | src/dynamic/sample/SampleMemoryManager.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/dynamic/sample/SampleMemoryManager.cpp b/src/dynamic/sample/SampleMemoryManager.cpp new file mode 100644 index 0000000000..30a7548b02 --- /dev/null +++ b/src/dynamic/sample/SampleMemoryManager.cpp @@ -0,0 +1,95 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "SampleMemoryManager.hpp" + +#include <algorithm> + +namespace armnn +{ + +SampleMemoryManager::SampleMemoryManager() +{} + +SampleMemoryManager::~SampleMemoryManager() +{} + +SampleMemoryManager::Pool* SampleMemoryManager::Manage(unsigned int numBytes) +{ + if (!m_FreePools.empty()) + { + Pool* res = m_FreePools.back(); + m_FreePools.pop_back(); + res->Reserve(numBytes); + return res; + } + else + { + m_Pools.push_front(Pool(numBytes)); + return &m_Pools.front(); + } +} + +void SampleMemoryManager::Allocate(SampleMemoryManager::Pool* pool) +{ + m_FreePools.push_back(pool); +} + +void* SampleMemoryManager::GetPointer(SampleMemoryManager::Pool* pool) +{ + return pool->GetPointer(); +} + +void SampleMemoryManager::Acquire() +{ + for (Pool &pool: m_Pools) + { + pool.Acquire(); + } +} + +void SampleMemoryManager::Release() +{ + for (Pool &pool: m_Pools) + { + pool.Release(); + } +} + +SampleMemoryManager::Pool::Pool(unsigned int numBytes) + : m_Size(numBytes), + m_Pointer(nullptr) +{} + +SampleMemoryManager::Pool::~Pool() +{ + if (m_Pointer) + { + Release(); + } +} + +void* SampleMemoryManager::Pool::GetPointer() +{ + return m_Pointer; +} + +void SampleMemoryManager::Pool::Reserve(unsigned int numBytes) +{ + m_Size = std::max(m_Size, numBytes); +} + +void SampleMemoryManager::Pool::Acquire() +{ + m_Pointer = ::operator new(size_t(m_Size)); +} + +void SampleMemoryManager::Pool::Release() +{ + ::operator delete(m_Pointer); + m_Pointer = nullptr; +} + +} |