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)
48 ARMNN_ASSERT_MSG(!m_UnmanagedMemory,
"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();
108 void TosaRefTensorHandle::CopyInFrom(
const void* src)
110 void *dest = GetPointer();
117 if (m_ImportFlags & static_cast<MemorySourceFlags>(source))
127 m_UnmanagedMemory =
nullptr;
133 if (!m_Imported && !m_UnmanagedMemory)
135 m_UnmanagedMemory = memory;
141 if (!m_Imported && m_UnmanagedMemory)
149 m_UnmanagedMemory = memory;
160 if (m_ImportFlags & static_cast<MemorySourceFlags>(source))
165 if (reinterpret_cast<uintptr_t>(memory) % alignment)
virtual const void * Map(bool) const override
Map the tensor data for access.
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
virtual bool CanBeImported(void *memory, MemorySource source) override
Implementations must determine if this memory block can be imported.
TosaRefTensorHandle(const TensorInfo &tensorInfo, std::shared_ptr< TosaRefMemoryManager > &memoryManager)
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.
virtual void Manage() override
Indicate to the memory manager that this resource is active.
#define ARMNN_ASSERT_MSG(COND, MSG)
DataType GetDataType() const
#define ARMNN_ASSERT(COND)
MemorySource
Define the Memory Source to reduce copies.
constexpr unsigned int GetDataTypeSize(DataType dataType)