12 m_TensorInfo(tensorInfo),
13 m_MemoryManager(memoryManager),
15 m_UnmanagedMemory(nullptr),
16 m_ImportedMemory(nullptr),
22 : m_TensorInfo(tensorInfo),
24 m_UnmanagedMemory(nullptr),
25 m_ImportedMemory(nullptr),
31 : m_TensorInfo(tensorInfo),
32 m_MemoryManager(parent.m_MemoryManager),
33 m_Pool(parent.m_Pool),
34 m_UnmanagedMemory(parent.m_UnmanagedMemory),
35 m_ImportedMemory(parent.m_ImportedMemory),
42 ::operator
delete(m_UnmanagedMemory);
52 m_Pool = m_MemoryManager->Manage(m_TensorInfo.
GetNumBytes());
58 if (!m_UnmanagedMemory)
63 m_UnmanagedMemory = ::operator
new(m_TensorInfo.
GetNumBytes());
67 m_MemoryManager->Allocate(m_Pool);
73 "that already has allocated memory.");
82 void* RefTensorHandle::GetPointer()
const
86 return m_ImportedMemory;
88 else if (m_UnmanagedMemory)
90 return m_UnmanagedMemory;
94 return m_MemoryManager->GetPointer(m_Pool);
98 throw NullPointerException(
"RefTensorHandle::GetPointer called on unmanaged, unallocated tensor handle");
102 void RefTensorHandle::CopyOutTo(
void* dest)
const
104 const void* src = GetPointer();
107 throw NullPointerException(
"TensorHandle::CopyOutTo called with a null src pointer");
111 throw NullPointerException(
"TensorHandle::CopyOutTo called with a null dest pointer");
116 void RefTensorHandle::CopyInFrom(
const void* src)
118 void* dest = GetPointer();
121 throw NullPointerException(
"RefTensorHandle::CopyInFrom called with a null dest pointer");
125 throw NullPointerException(
"RefTensorHandle::CopyInFrom called with a null src pointer");
142 m_ImportedMemory =
nullptr;
146 m_ImportedMemory = memory;
158 if (
reinterpret_cast<uintptr_t
>(memory) % alignment)
169 auto decorated = std::make_shared<RefTensorHandleDecorator>(tensorInfo, *
this);
170 m_Decorated.emplace_back(decorated);
176 , m_TensorInfo(tensorInfo)
191 return m_Parent.
Map(unused);
#define ARMNN_THROW_MSG_IF_FALSE(_cond, _except, _str)
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
virtual std::shared_ptr< ITensorHandle > DecorateTensorHandle(const TensorInfo &tensorInfo) override
Returns a decorated version of this TensorHandle allowing us to override the TensorInfo for it.
virtual MemorySourceFlags GetImportFlags() const override
Get flags describing supported import sources.
RefTensorHandleDecorator(const TensorInfo &tensorInfo, const RefTensorHandle &parent)
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.
virtual const void * Map(bool blocking=true) const=0
Map the tensor data for access.
virtual bool CanBeImported(void *memory, MemorySource source) override
Implementations must determine if this memory block can be imported.
RefTensorHandle(const TensorInfo &tensorInfo, std::shared_ptr< RefMemoryManager > &memoryManager)
const TensorInfo & GetTensorInfo() const
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
virtual std::shared_ptr< ITensorHandle > DecorateTensorHandle(const TensorInfo &tensorInfo) override
Returns a decorated version of this TensorHandle allowing us to override the TensorInfo for it.
virtual MemorySourceFlags GetImportFlags() const override
Get flags describing supported import sources.
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.
virtual const void * Map(bool) const override
Map the tensor data for access.
virtual const void * Map(bool blocking=true) const=0
Map the tensor data for access.
virtual bool CanBeImported(void *memory, MemorySource source) override
Implementations must determine if this memory block can be imported.
unsigned int GetNumBytes() const
DataType GetDataType() const
Copyright (c) 2021 ARM Limited and Contributors.
MemorySource
Define the Memory Source to reduce copies.
unsigned int MemorySourceFlags
constexpr unsigned int GetDataTypeSize(DataType dataType)