11 m_TensorInfo(tensorInfo),
12 m_MemoryManager(memoryManager),
14 m_UnmanagedMemory(nullptr),
23 : m_TensorInfo(tensorInfo),
24 m_MemoryManager(memoryManager),
26 m_UnmanagedMemory(nullptr),
27 m_ImportFlags(importFlags),
40 ::operator
delete(m_UnmanagedMemory);
48 ARMNN_ASSERT_MSG(!m_UnmanagedMemory,
"EthosnRefTensorHandle::Manage() called after Allocate()");
50 m_Pool = m_MemoryManager->Manage(m_TensorInfo.
GetNumBytes());
55 if (!m_UnmanagedMemory)
60 m_UnmanagedMemory = ::operator
new(m_TensorInfo.
GetNumBytes());
64 m_MemoryManager->Allocate(m_Pool);
70 "that already has allocated memory.");
79 void* EthosnRefTensorHandle::GetPointer()
const 81 if (m_UnmanagedMemory)
83 return m_UnmanagedMemory;
87 ARMNN_ASSERT_MSG(m_Pool,
"EthosnRefTensorHandle::GetPointer called on unmanaged, unallocated tensor handle");
88 return m_MemoryManager->GetPointer(m_Pool);
92 void EthosnRefTensorHandle::CopyOutTo(
void* dest)
const 94 const void *src = GetPointer();
99 void EthosnRefTensorHandle::CopyInFrom(
const void* src)
101 void *dest = GetPointer();
109 if (m_ImportFlags & static_cast<MemorySourceFlags>(source))
114 constexpr uintptr_t alignment =
sizeof(size_t);
115 if (reinterpret_cast<uintptr_t>(memory) % alignment)
120 m_UnmanagedMemory =
nullptr;
127 if (!m_Imported && !m_UnmanagedMemory)
129 m_UnmanagedMemory = memory;
135 if (!m_Imported && m_UnmanagedMemory)
143 m_UnmanagedMemory = memory;
virtual void Manage() override
Indicate to the memory manager that this resource is active.
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
unsigned int GetNumBytes() const
unsigned int MemorySourceFlags
Copyright (c) 2021 ARM Limited and Contributors.
virtual bool Import(void *memory, MemorySource source) override
Import externally allocated memory.
#define ARMNN_ASSERT_MSG(COND, MSG)
#define ARMNN_ASSERT(COND)
virtual const void * Map(bool) const override
Map the tensor data for access.
EthosnRefTensorHandle(const TensorInfo &tensorInfo, std::shared_ptr< EthosnRefMemoryManager > &memoryManager)
MemorySource
Define the Memory Source to reduce copies.