10 std::shared_ptr<GpuFsaMemoryManager>& memoryManager)
11 : m_TensorInfo(tensorInfo)
12 , m_MemoryManager(memoryManager)
14 , m_UnmanagedMemory(nullptr)
17 , m_IsImportEnabled(false)
22 : m_TensorInfo(tensorInfo)
24 , m_UnmanagedMemory(nullptr)
25 , m_ImportFlags(importFlags)
27 , m_IsImportEnabled(true)
30 GpuFsaTensorHandle::~GpuFsaTensorHandle()
37 ::operator
delete(m_UnmanagedMemory);
44 if (!m_IsImportEnabled)
46 if (m_Pool ==
nullptr)
48 throw MemoryValidationException(
"GpuFsaTensorHandle::Manage() called twice");
50 if (m_UnmanagedMemory ==
nullptr)
52 throw MemoryValidationException(
"GpuFsaTensorHandle::Manage() called after Allocate()");
55 m_Pool = m_MemoryManager->Manage(m_TensorInfo.GetNumBytes());
62 if (!m_IsImportEnabled)
65 if (!m_UnmanagedMemory)
70 m_UnmanagedMemory = ::operator
new(m_TensorInfo.GetNumBytes());
74 m_MemoryManager->Allocate(m_Pool);
79 throw InvalidArgumentException(
"GpuFsaTensorHandle::Allocate Trying to allocate a GpuFsaTensorHandle"
80 "that already has allocated memory.");
90 void* GpuFsaTensorHandle::GetPointer()
const
92 if (m_UnmanagedMemory)
94 return m_UnmanagedMemory;
98 return m_MemoryManager->GetPointer(m_Pool);
102 throw NullPointerException(
"GpuFsaTensorHandle::GetPointer called on unmanaged, unallocated tensor handle");
106 void GpuFsaTensorHandle::CopyOutTo(
void* dest)
const
111 throw MemoryValidationException(
"GpuFsaTensorhandle: CopyOutTo: Invalid memory src pointer");
113 memcpy(dest, src, m_TensorInfo.GetNumBytes());
116 void GpuFsaTensorHandle::CopyInFrom(
const void* src)
121 throw MemoryValidationException(
"GpuFsaTensorhandle: CopyInFrom: Invalid memory dest pointer");
123 memcpy(dest, src, m_TensorInfo.GetNumBytes());
133 if(!CanBeImported(memory, source))
138 m_UnmanagedMemory =
nullptr;
144 if (!m_Imported && !m_UnmanagedMemory)
146 m_UnmanagedMemory = memory;
152 if (!m_Imported && m_UnmanagedMemory)
160 m_UnmanagedMemory = memory;
176 if (
reinterpret_cast<uintptr_t
>(memory) % alignment)