10 #ifndef vtk_m_cont_internal_DeviceAdapterMemoryManager_h
11 #define vtk_m_cont_internal_DeviceAdapterMemoryManager_h
34 struct TransferredBuffer;
39 struct BufferInfoInternals;
65 VTKM_CONT BufferInfo(
const BufferInfo& src);
68 VTKM_CONT BufferInfo& operator=(
const BufferInfo& src);
69 VTKM_CONT BufferInfo& operator=(BufferInfo&& src);
80 using Deleter = void(
void* container);
84 using Reallocater = void(
void*& memory,
98 Reallocater reallocater);
110 VTKM_CONT TransferredBuffer TransferOwnership();
113 detail::BufferInfoInternals* Internals;
127 struct TransferredBuffer
131 BufferInfo::Deleter* Delete;
132 BufferInfo::Reallocater* Reallocate;
149 VTKM_CONT virtual ~DeviceAdapterMemoryManagerBase();
157 VTKM_CONT void Reallocate(vtkm::cont::internal::BufferInfo& buffer,
161 VTKM_CONT BufferInfo ManageArray(
void* memory,
164 vtkm::cont::internal::BufferInfo::Deleter deleter,
165 vtkm::cont::internal::BufferInfo::Reallocater reallocater)
const;
172 VTKM_CONT virtual vtkm::cont::internal::BufferInfo CopyHostToDevice(
173 const vtkm::cont::internal::BufferInfo& src)
const = 0;
177 VTKM_CONT virtual void CopyHostToDevice(
const vtkm::cont::internal::BufferInfo& src,
178 const vtkm::cont::internal::BufferInfo& dest)
const = 0;
182 VTKM_CONT virtual vtkm::cont::internal::BufferInfo CopyDeviceToHost(
183 const vtkm::cont::internal::BufferInfo& src)
const = 0;
187 VTKM_CONT virtual void CopyDeviceToHost(
const vtkm::cont::internal::BufferInfo& src,
188 const vtkm::cont::internal::BufferInfo& dest)
const = 0;
192 VTKM_CONT virtual vtkm::cont::internal::BufferInfo CopyDeviceToDevice(
193 const vtkm::cont::internal::BufferInfo& src)
const = 0;
197 VTKM_CONT virtual void CopyDeviceToDevice(
const vtkm::cont::internal::BufferInfo& src,
198 const vtkm::cont::internal::BufferInfo& dest)
const = 0;
217 VTKM_CONT virtual void CopyDeviceToDeviceRawPointer(
const void* src,
229 VTKM_CONT virtual void DeleteRawPointer(
void*)
const = 0;
238 template <
typename DeviceAdapterTag>
239 class DeviceAdapterMemoryManager;
256 template <
typename T>
257 VTKM_CONT inline void SimpleArrayDeleter(
void* container_)
259 T* container =
reinterpret_cast<T*
>(container_);
265 template <
typename T>
266 VTKM_CONT inline void SimpleArrayReallocater(
void*& memory,
272 VTKM_ASSERT(
static_cast<std::size_t
>(newSize) %
sizeof(T) == 0);
276 if ((newSize > ((3 * oldSize) / 4)) && (newSize <= oldSize))
281 void* newBuffer =
new T[
static_cast<std::size_t
>(newSize) /
sizeof(T)];
282 std::memcpy(newBuffer, memory,
static_cast<std::size_t
>(newSize < oldSize ? newSize : oldSize));
284 if (memory !=
nullptr)
286 SimpleArrayDeleter<T>(memory);
289 memory = container = newBuffer;
294 template <
typename T>
295 VTKM_CONT inline void CastDeleter(
void* container_)
297 T* container =
reinterpret_cast<T*
>(container_);
301 template <
typename T,
typename Allocator>
302 VTKM_CONT inline void StdVectorDeleter(
void* container)
304 CastDeleter<std::vector<T, Allocator>>(container);
307 template <
typename T,
typename Allocator>
308 VTKM_CONT inline void StdVectorReallocater(
void*& memory,
313 using vector_type = std::vector<T, Allocator>;
314 vector_type* vector =
reinterpret_cast<vector_type*
>(container);
315 VTKM_ASSERT(vector->empty() || (memory == vector->data()));
318 vector->resize(
static_cast<std::size_t
>(newSize));
319 memory = vector->data();
325 #endif //vtk_m_cont_internal_DeviceAdapterMemoryManager_h