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)