| 112 | } |
| 113 | |
| 114 | bool MockTensorHandle::Import(void* memory, MemorySource source) |
| 115 | { |
| 116 | if (m_ImportFlags & static_cast<MemorySourceFlags>(source)) |
| 117 | { |
| 118 | if (m_IsImportEnabled && source == MemorySource::Malloc) |
| 119 | { |
| 120 | // Check memory alignment |
| 121 | if (!CanBeImported(memory, source)) |
| 122 | { |
| 123 | if (m_Imported) |
| 124 | { |
| 125 | m_Imported = false; |
| 126 | m_UnmanagedMemory = nullptr; |
| 127 | } |
| 128 | |
| 129 | return false; |
| 130 | } |
| 131 | |
| 132 | // m_UnmanagedMemory not yet allocated. |
| 133 | if (!m_Imported && !m_UnmanagedMemory) |
| 134 | { |
| 135 | m_UnmanagedMemory = memory; |
| 136 | m_Imported = true; |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | // m_UnmanagedMemory initially allocated with Allocate(). |
| 141 | if (!m_Imported && m_UnmanagedMemory) |
| 142 | { |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | // m_UnmanagedMemory previously imported. |
| 147 | if (m_Imported) |
| 148 | { |
| 149 | m_UnmanagedMemory = memory; |
| 150 | return true; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | return false; |
| 156 | } |
| 157 | |
| 158 | bool MockTensorHandle::CanBeImported(void* memory, MemorySource source) |
| 159 | { |
no outgoing calls
no test coverage detected