12 : m_TensorInfo(tensorInfo)
13 , m_MemoryManager(memoryManager)
15 , m_UnmanagedMemory(nullptr)
18 , m_IsImportEnabled(false)
22 : m_TensorInfo(tensorInfo)
24 , m_UnmanagedMemory(nullptr)
25 , m_ImportFlags(importFlags)
27 , m_IsImportEnabled(true)
37 ::operator
delete(m_UnmanagedMemory);
44 if (!m_IsImportEnabled)
47 ARMNN_ASSERT_MSG(!m_UnmanagedMemory,
"MockTensorHandle::Manage() called after Allocate()");
49 m_Pool = m_MemoryManager->Manage(m_TensorInfo.
GetNumBytes());
56 if (!m_IsImportEnabled)
59 if (!m_UnmanagedMemory)
64 m_UnmanagedMemory = ::operator
new(m_TensorInfo.
GetNumBytes());
68 m_MemoryManager->Allocate(m_Pool);
74 "that already has allocated memory.");
84 void* MockTensorHandle::GetPointer()
const 86 if (m_UnmanagedMemory)
88 return m_UnmanagedMemory;
92 return m_MemoryManager->GetPointer(m_Pool);
96 throw NullPointerException(
"MockTensorHandle::GetPointer called on unmanaged, unallocated tensor handle");
100 void MockTensorHandle::CopyOutTo(
void* dest)
const 102 const void* src = GetPointer();
107 void MockTensorHandle::CopyInFrom(
const void* src)
109 void* dest = GetPointer();
116 if (m_ImportFlags & static_cast<MemorySourceFlags>(source))
126 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)
~MockTensorHandle() override
unsigned int GetNumBytes() const
MockTensorHandle(const TensorInfo &tensorInfo, std::shared_ptr< MockMemoryManager > &memoryManager)
unsigned int MemorySourceFlags
Copyright (c) 2021 ARM Limited and Contributors.
bool CanBeImported(void *memory, MemorySource source) override
Implementations must determine if this memory block can be imported.
const void * Map(bool) const override
Map the tensor data for access.
#define ARMNN_ASSERT_MSG(COND, MSG)
DataType GetDataType() const
#define ARMNN_ASSERT(COND)
void Allocate() override
Indicate to the memory manager that this resource is no longer active.
MemorySource
Define the Memory Source to reduce copies.
bool Import(void *memory, MemorySource source) override
Import externally allocated memory.
void Manage() override
Indicate to the memory manager that this resource is active.
constexpr unsigned int GetDataTypeSize(DataType dataType)