12 std::shared_ptr<SampleMemoryManager> &memoryManager)
13 : m_TensorInfo(tensorInfo),
14 m_MemoryManager(memoryManager),
16 m_UnmanagedMemory(nullptr),
25 : m_TensorInfo(tensorInfo),
26 m_MemoryManager(nullptr),
28 m_UnmanagedMemory(nullptr),
29 m_ImportFlags(importFlags),
42 ::operator
delete(m_UnmanagedMemory);
49 m_Pool = m_MemoryManager->Manage(m_TensorInfo.
GetNumBytes());
54 if (!m_UnmanagedMemory)
59 m_UnmanagedMemory = ::operator
new(m_TensorInfo.
GetNumBytes());
63 m_MemoryManager->Allocate(m_Pool);
69 "SampleTensorHandle that already has allocated " 79 void* SampleTensorHandle::GetPointer()
const 81 if (m_UnmanagedMemory)
83 return m_UnmanagedMemory;
87 return m_MemoryManager->GetPointer(m_Pool);
94 if (m_ImportFlags & static_cast<armnn::MemorySourceFlags>(source))
99 constexpr uintptr_t alignment =
sizeof(size_t);
100 if (reinterpret_cast<uintptr_t>(memory) % alignment)
105 m_UnmanagedMemory =
nullptr;
112 if (!m_Imported && !m_UnmanagedMemory)
114 m_UnmanagedMemory = memory;
120 if (!m_Imported && m_UnmanagedMemory)
128 m_UnmanagedMemory = memory;
137 void SampleTensorHandle::CopyOutTo(
void* dest)
const 139 const void *src = GetPointer();
144 void SampleTensorHandle::CopyInFrom(
const void* src)
146 void *dest = GetPointer();
unsigned int GetNumBytes() const
unsigned int MemorySourceFlags
Copyright (c) 2021 ARM Limited and Contributors.
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
SampleTensorHandle(const armnn::TensorInfo &tensorInfo, std::shared_ptr< SampleMemoryManager > &memoryManager)
#define ARMNN_ASSERT(COND)
MemorySource
Define the Memory Source to reduce copies.
virtual void Manage() override
Indicate to the memory manager that this resource is active.
virtual const void * Map(bool) const override
Map the tensor data for access.
virtual bool Import(void *memory, armnn::MemorySource source) override
Import externally allocated memory.