1#include <muda/buffer/buffer_launch.h>
6DeviceBuffer2D<T>::DeviceBuffer2D(
const Extent2D& n)
14DeviceBuffer2D<T>::DeviceBuffer2D()
17 , m_extent(Extent2D::Zero())
18 , m_capacity(Extent2D::Zero())
23DeviceBuffer2D<T>::DeviceBuffer2D(
const DeviceBuffer2D<T>& other)
26 .resize(*
this, other.extent())
27 .copy(view(), other.view())
32DeviceBuffer2D<T>::DeviceBuffer2D(DeviceBuffer2D<T>&& other) MUDA_NOEXCEPT
33 : m_data(other.m_data),
34 m_pitch_bytes(other.m_pitch_bytes),
35 m_extent(other.m_extent),
36 m_capacity(other.m_capacity)
38 other.m_data =
nullptr;
39 other.m_pitch_bytes = 0;
40 other.m_extent = Extent2D::Zero();
41 other.m_capacity = Extent2D::Zero();
45DeviceBuffer2D<T>& DeviceBuffer2D<T>::operator=(
const DeviceBuffer2D<T>& other)
51 .resize(*
this, other.extent())
52 .copy(view(), other.view())
59DeviceBuffer2D<T>& DeviceBuffer2D<T>::operator=(DeviceBuffer2D<T>&& other)
65 BufferLaunch().free(*this).wait();
67 m_data = other.m_data;
68 m_pitch_bytes = other.m_pitch_bytes;
69 m_extent = other.m_extent;
70 m_capacity = other.m_capacity;
72 other.m_data =
nullptr;
73 other.m_pitch_bytes = 0;
74 other.m_extent = Extent2D::Zero();
75 other.m_capacity = Extent2D::Zero();
81DeviceBuffer2D<T>::DeviceBuffer2D(CBuffer2DView<T> other)
84 .alloc(*
this, other.extent())
90DeviceBuffer2D<T>& DeviceBuffer2D<T>::operator=(CBuffer2DView<T> other)
93 .resize(*
this, other.extent())
102void DeviceBuffer2D<T>::copy_to(std::vector<T>& host)
const
104 host.resize(total_size());
105 view().copy_to(host.data());
110void DeviceBuffer2D<T>::copy_from(
const std::vector<T>& host)
112 MUDA_ASSERT(host.size() == total_size(),
113 "Need eqaul total size, host_size=%d, total_size=%d",
117 view().copy_from(host.data());
121void DeviceBuffer2D<T>::resize(Extent2D new_extent)
124 .resize(*
this, new_extent)
129void DeviceBuffer2D<T>::resize(Extent2D new_extent,
const T& value)
132 .resize(*
this, new_extent, value)
137void DeviceBuffer2D<T>::reserve(Extent2D new_capacity)
140 .reserve(*
this, new_capacity)
145void DeviceBuffer2D<T>::clear()
147 BufferLaunch().clear(*this).wait();
151void DeviceBuffer2D<T>::shrink_to_fit()
153 BufferLaunch().shrink_to_fit(*this).wait();
157void DeviceBuffer2D<T>::fill(
const T& v)
159 BufferLaunch().fill(view(), v).wait();
163DeviceBuffer2D<T>::~DeviceBuffer2D()
166 BufferLaunch().free(*this).wait();