2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // See LICENSE file in the project root for full license information.
5 #include "OffsetMemoryPool.hpp"
7 #include "boost/assert.hpp"
14 OffsetMemoryPool::OffsetMemoryPool(arm_compute::IAllocator* allocator, size_t blobSize)
15 : m_Allocator(allocator)
17 , m_BlobSize(blobSize)
18 , m_MemoryAllocated(false)
23 OffsetMemoryPool::~OffsetMemoryPool()
28 void OffsetMemoryPool::acquire(arm_compute::MemoryMappings& handles)
32 // Set memory to handlers
33 for(auto& handle : handles)
35 BOOST_ASSERT(handle.first);
36 *handle.first = reinterpret_cast<uint8_t*>(m_Blob) + handle.second;
40 void OffsetMemoryPool::release(arm_compute::MemoryMappings &handles)
42 for(auto& handle : handles)
44 BOOST_ASSERT(handle.first);
45 *handle.first = nullptr;
49 arm_compute::MappingType OffsetMemoryPool::mapping_type() const
51 return arm_compute::MappingType::OFFSETS;
54 std::unique_ptr<arm_compute::IMemoryPool> OffsetMemoryPool::duplicate()
56 BOOST_ASSERT(m_Allocator);
57 return std::make_unique<OffsetMemoryPool>(m_Allocator, m_BlobSize);
60 void OffsetMemoryPool::AllocatePool()
62 if (!m_MemoryAllocated)
64 BOOST_ASSERT(m_Allocator);
65 m_Blob = m_Allocator->allocate(m_BlobSize, 0);
67 m_MemoryAllocated = true;
71 void OffsetMemoryPool::ReleasePool()
73 if (m_MemoryAllocated)
75 BOOST_ASSERT(m_Allocator);
77 m_Allocator->free(m_Blob);
80 m_MemoryAllocated = false;