1#include <muda/buffer/buffer_launch.h>
6DeviceBuffer3D<T>::DeviceBuffer3D(
const Extent3D& n)
14DeviceBuffer3D<T>::DeviceBuffer3D()
17 , m_pitch_bytes_area(0)
18 , m_extent(Extent3D::Zero())
19 , m_capacity(Extent3D::Zero())
24DeviceBuffer3D<T>::DeviceBuffer3D(
const DeviceBuffer3D<T>& other)
27 .resize(*
this, other.extent())
28 .copy(view(), other.view())
33DeviceBuffer3D<T>::DeviceBuffer3D(DeviceBuffer3D<T>&& other) MUDA_NOEXCEPT
34 : m_data(other.m_data),
35 m_pitch_bytes(other.m_pitch_bytes),
36 m_pitch_bytes_area(other.m_pitch_bytes_area),
37 m_extent(other.m_extent),
38 m_capacity(other.m_capacity)
40 other.m_data =
nullptr;
41 other.m_pitch_bytes = 0;
42 other.m_pitch_bytes_area = 0;
43 other.m_extent = Extent3D::Zero();
44 other.m_capacity = Extent3D::Zero();
48DeviceBuffer3D<T>& DeviceBuffer3D<T>::operator=(
const DeviceBuffer3D<T>& other)
54 .resize(*
this, other.extent())
55 .copy(view(), other.view())
62DeviceBuffer3D<T>& DeviceBuffer3D<T>::operator=(DeviceBuffer3D<T>&& other)
68 BufferLaunch().free(*this).wait();
70 m_data = other.m_data;
71 m_pitch_bytes = other.m_pitch_bytes;
72 m_pitch_bytes_area = other.m_pitch_bytes_area;
73 m_extent = other.m_extent;
74 m_capacity = other.m_capacity;
76 other.m_data =
nullptr;
77 other.m_pitch_bytes = 0;
78 other.m_pitch_bytes_area = 0;
79 other.m_extent = Extent3D::Zero();
80 other.m_capacity = Extent3D::Zero();
86DeviceBuffer3D<T>::DeviceBuffer3D(CBuffer3DView<T> other)
89 .alloc(*
this, other.extent())
95DeviceBuffer3D<T>& DeviceBuffer3D<T>::operator=(CBuffer3DView<T> other)
98 .resize(*
this, other.extent())
106void DeviceBuffer3D<T>::copy_to(std::vector<T>& host)
const
108 host.resize(total_size());
109 view().copy_to(host.data());
113void DeviceBuffer3D<T>::copy_from(
const std::vector<T>& host)
115 MUDA_ASSERT(host.size() == total_size(),
116 "Need eqaul total size, host_size=%d, total_size=%d",
120 view().copy_from(host.data());
124void DeviceBuffer3D<T>::resize(Extent3D new_extent)
127 .resize(*
this, new_extent)
132void DeviceBuffer3D<T>::resize(Extent3D new_extent,
const T& value)
135 .resize(*
this, new_extent, value)
140void DeviceBuffer3D<T>::reserve(Extent3D new_capacity)
143 .reserve(*
this, new_capacity)
148void DeviceBuffer3D<T>::clear()
150 BufferLaunch().clear(*this).wait();
154void DeviceBuffer3D<T>::shrink_to_fit()
156 BufferLaunch().shrink_to_fit(*this).wait();
160void DeviceBuffer3D<T>::fill(
const T& v)
162 BufferLaunch().fill(view(), v).wait();
166DeviceBuffer3D<T>::~DeviceBuffer3D()
169 BufferLaunch().free(*this).wait();