12 std::shared_ptr<SampleMemoryManager> &memoryManager)
13 : m_TensorInfo(tensorInfo),
14 m_MemoryManager(memoryManager),
16 m_UnmanagedMemory(nullptr),
24 std::shared_ptr<SampleMemoryManager> &memoryManager,
26 : m_TensorInfo(tensorInfo),
27 m_MemoryManager(memoryManager),
29 m_UnmanagedMemory(nullptr),
30 m_ImportFlags(importFlags),
43 ::operator
delete(m_UnmanagedMemory);
50 m_Pool = m_MemoryManager->Manage(m_TensorInfo.
GetNumBytes());
55 if (!m_UnmanagedMemory)
60 m_UnmanagedMemory = ::operator
new(m_TensorInfo.
GetNumBytes());
64 m_MemoryManager->Allocate(m_Pool);
70 "that already has allocated memory.");
79 void* SampleTensorHandle::GetPointer()
const 81 if (m_UnmanagedMemory)
83 return m_UnmanagedMemory;
87 return m_MemoryManager->GetPointer(m_Pool);
94 if (m_ImportFlags & static_cast<MemorySourceFlags>(source))
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;
virtual const void * Map(bool) const override
Map the tensor data for access.
SampleTensorHandle(const TensorInfo &tensorInfo, std::shared_ptr< SampleMemoryManager > &memoryManager)
unsigned int GetNumBytes() const
unsigned int MemorySourceFlags
Copyright (c) 2020 ARM Limited.
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
virtual void Manage() override
Indicate to the memory manager that this resource is active.
virtual bool Import(void *memory, MemorySource source) override
Import externally allocated memory.