12 std::shared_ptr<SampleMemoryManager> &memoryManager)
13 : m_TensorInfo(tensorInfo),
14 m_MemoryManager(memoryManager),
16 m_UnmanagedMemory(nullptr),
25 : m_TensorInfo(tensorInfo),
26 m_MemoryManager(nullptr),
28 m_UnmanagedMemory(nullptr),
29 m_ImportFlags(importFlags),
42 ::operator
delete(m_UnmanagedMemory);
49 m_Pool = m_MemoryManager->Manage(m_TensorInfo.
GetNumBytes());
54 if (!m_UnmanagedMemory)
59 m_UnmanagedMemory = ::operator
new(m_TensorInfo.
GetNumBytes());
63 m_MemoryManager->Allocate(m_Pool);
69 "SampleTensorHandle that already has allocated "
79 void* SampleTensorHandle::GetPointer()
const
81 if (m_UnmanagedMemory)
83 return m_UnmanagedMemory;
87 return m_MemoryManager->GetPointer(m_Pool);
99 constexpr uintptr_t alignment =
sizeof(size_t);
100 if (
reinterpret_cast<uintptr_t
>(memory) % alignment)
105 m_UnmanagedMemory =
nullptr;
112 if (!m_Imported && !m_UnmanagedMemory)
114 m_UnmanagedMemory = memory;
120 if (!m_Imported && m_UnmanagedMemory)
128 m_UnmanagedMemory = memory;
137 void SampleTensorHandle::CopyOutTo(
void* dest)
const
139 const void* src = GetPointer();
142 throw armnn::Exception(
"SampleTensorHandle:CopyOutTo: Destination Ptr is null");
151 void SampleTensorHandle::CopyInFrom(
const void* src)
153 void* dest = GetPointer();
156 throw armnn::Exception(
"SampleTensorHandle:CopyInFrom: Source Ptr is null");
160 throw armnn::Exception(
"SampleTensorHandle:CopyInFrom: Destination Ptr is null");
Base class for all ArmNN exceptions so that users can filter to just those.
unsigned int GetNumBytes() const
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
virtual bool Import(void *memory, armnn::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.
SampleTensorHandle(const armnn::TensorInfo &tensorInfo, std::shared_ptr< SampleMemoryManager > &memoryManager)
Copyright (c) 2021 ARM Limited and Contributors.
MemorySource
Define the Memory Source to reduce copies.
unsigned int MemorySourceFlags