11 m_TensorInfo(tensorInfo),
12 m_MemoryManager(memoryManager),
14 m_UnmanagedMemory(nullptr),
17 m_IsImportEnabled(
false)
24 : m_TensorInfo(tensorInfo),
26 m_UnmanagedMemory(nullptr),
27 m_ImportFlags(importFlags),
29 m_IsImportEnabled(
true)
41 ::operator
delete(m_UnmanagedMemory);
48 if (!m_IsImportEnabled)
51 ARMNN_ASSERT_MSG(!m_UnmanagedMemory,
"RefTensorHandle::Manage() called after Allocate()");
53 m_Pool = m_MemoryManager->Manage(m_TensorInfo.
GetNumBytes());
60 if (!m_IsImportEnabled)
63 if (!m_UnmanagedMemory)
68 m_UnmanagedMemory = ::operator
new(m_TensorInfo.
GetNumBytes());
72 m_MemoryManager->Allocate(m_Pool);
78 "that already has allocated memory.");
88 void* RefTensorHandle::GetPointer()
const 90 if (m_UnmanagedMemory)
92 return m_UnmanagedMemory;
96 return m_MemoryManager->GetPointer(m_Pool);
100 throw NullPointerException(
"RefTensorHandle::GetPointer called on unmanaged, unallocated tensor handle");
104 void RefTensorHandle::CopyOutTo(
void* dest)
const 106 const void *src = GetPointer();
111 void RefTensorHandle::CopyInFrom(
const void* src)
113 void *dest = GetPointer();
120 if (m_ImportFlags & static_cast<MemorySourceFlags>(source))
125 constexpr uintptr_t alignment =
sizeof(size_t);
126 if (reinterpret_cast<uintptr_t>(memory) % alignment)
131 m_UnmanagedMemory =
nullptr;
138 if (!m_Imported && !m_UnmanagedMemory)
140 m_UnmanagedMemory = memory;
146 if (!m_Imported && m_UnmanagedMemory)
154 m_UnmanagedMemory = memory;
unsigned int GetNumBytes() const
virtual const void * Map(bool) const override
Map the tensor data for access.
unsigned int MemorySourceFlags
Copyright (c) 2021 ARM Limited and Contributors.
#define ARMNN_ASSERT_MSG(COND, MSG)
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
#define ARMNN_ASSERT(COND)
RefTensorHandle(const TensorInfo &tensorInfo, std::shared_ptr< RefMemoryManager > &memoryManager)
virtual bool Import(void *memory, MemorySource source) override
Import externally allocated memory.
virtual void Manage() override
Indicate to the memory manager that this resource is active.
DataLayout::NCHW DataLayout::NCHW DataLayout::NHWC DataLayout::NHWC true