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);
47 BOOST_ASSERT_MSG(!m_Pool,
"RefTensorHandle::Manage() called twice");
48 BOOST_ASSERT_MSG(!m_UnmanagedMemory,
"RefTensorHandle::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* RefTensorHandle::GetPointer()
const 81 if (m_UnmanagedMemory)
83 return m_UnmanagedMemory;
87 BOOST_ASSERT_MSG(m_Pool,
"RefTensorHandle::GetPointer called on unmanaged, unallocated tensor handle");
88 return m_MemoryManager->GetPointer(m_Pool);
92 void RefTensorHandle::CopyOutTo(
void* dest)
const 94 const void *src = GetPointer();
99 void RefTensorHandle::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;
unsigned int GetNumBytes() const
virtual const void * Map(bool) const override
Map the tensor data for access.
unsigned int MemorySourceFlags
Copyright (c) 2020 ARM Limited.
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
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.