11 std::shared_ptr<TosaRefMemoryManager>& memoryManager)
12 : m_TensorInfo(tensorInfo)
13 , m_MemoryManager(memoryManager)
15 , m_UnmanagedMemory(nullptr)
18 , m_IsImportEnabled(false)
23 : m_TensorInfo(tensorInfo)
25 , m_UnmanagedMemory(nullptr)
26 , m_ImportFlags(importFlags)
28 , m_IsImportEnabled(true)
38 ::operator
delete(m_UnmanagedMemory);
45 if (!m_IsImportEnabled)
49 "TosaRefTensorHandle::Manage() called after Allocate()");
50 m_Pool = m_MemoryManager->Manage(m_TensorInfo.
GetNumBytes());
57 if (!m_IsImportEnabled)
60 if (!m_UnmanagedMemory)
65 m_UnmanagedMemory = ::operator
new(m_TensorInfo.
GetNumBytes());
69 m_MemoryManager->Allocate(m_Pool);
75 "that already has allocated memory.");
85 void* TosaRefTensorHandle::GetPointer()
const
87 if (m_UnmanagedMemory)
89 return m_UnmanagedMemory;
93 return m_MemoryManager->GetPointer(m_Pool);
97 throw NullPointerException(
"TosaRefTensorHandle::GetPointer called on unmanaged, unallocated tensor handle");
101 void TosaRefTensorHandle::CopyOutTo(
void* dest)
const
103 const void* src = GetPointer();
106 throw NullPointerException(
"TosaRefTensorHandle::CopyOutTo called with a null src pointer");
110 throw NullPointerException(
"TosaRefTensorHandle::CopyOutTo called with a null dest pointer");
115 void TosaRefTensorHandle::CopyInFrom(
const void* src)
117 void* dest = GetPointer();
120 throw NullPointerException(
"TosaRefTensorHandle::CopyInFrom called with a null dest pointer");
124 throw NullPointerException(
"TosaRefTensorHandle::CopyInFrom called with a null src pointer");
141 m_UnmanagedMemory =
nullptr;
147 if (!m_Imported && !m_UnmanagedMemory)
149 m_UnmanagedMemory = memory;
155 if (!m_Imported && m_UnmanagedMemory)
163 m_UnmanagedMemory = memory;
179 if (
reinterpret_cast<uintptr_t
>(memory) % alignment)
#define ARMNN_THROW_MSG_IF_FALSE(_cond, _except, _str)
unsigned int GetNumBytes() const
DataType GetDataType() const
TosaRefTensorHandle(const TensorInfo &tensorInfo, std::shared_ptr< TosaRefMemoryManager > &memoryManager)
const TensorInfo & GetTensorInfo() const
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
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.
Copyright (c) 2021 ARM Limited and Contributors.
MemorySource
Define the Memory Source to reduce copies.
unsigned int MemorySourceFlags
constexpr unsigned int GetDataTypeSize(DataType dataType)