3 #include <cuda_runtime.h> 4 #include <cuda_runtime_api.h> 6 #include <muda/viewer/dense.h> 7 #include <muda/buffer/buffer_2d_view.h> 15 friend class BufferLaunch;
16 friend class NDReshaper;
18 size_t m_pitch_bytes = 0;
19 Extent2D m_extent = Extent2D::Zero();
20 Extent2D m_capacity = Extent2D::Zero();
25 DeviceBuffer2D(
const Extent2D& n);
28 DeviceBuffer2D(
const DeviceBuffer2D<T>& other);
29 DeviceBuffer2D(DeviceBuffer2D&& other) MUDA_NOEXCEPT;
30 DeviceBuffer2D& operator=(
const DeviceBuffer2D<T>& other);
31 DeviceBuffer2D& operator=(DeviceBuffer2D<T>&& other);
33 DeviceBuffer2D(CBuffer2DView<T> other);
34 DeviceBuffer2D& operator=(CBuffer2DView<T> other);
36 void copy_to(std::vector<T>& host)
const;
37 void copy_from(
const std::vector<T>& host);
39 void resize(Extent2D new_extent);
40 void resize(Extent2D new_extent,
const T& value);
41 void reserve(Extent2D new_capacity);
44 void fill(
const T& v);
46 Dense2D<T> viewer() MUDA_NOEXCEPT {
return view().viewer(); }
47 CDense2D<T> cviewer() const MUDA_NOEXCEPT {
return view().viewer(); }
49 Buffer2DView<T> view(Offset2D offset, Extent2D extent = {}) MUDA_NOEXCEPT
51 return view().subview(offset, extent);
53 Buffer2DView<T> view() MUDA_NOEXCEPT
55 return Buffer2DView<T>{m_data, m_pitch_bytes, Offset2D::Zero(), m_extent};
57 operator Buffer2DView<T>() MUDA_NOEXCEPT {
return view(); }
59 CBuffer2DView<T> view(Offset2D offset, Extent2D extent = {})
const MUDA_NOEXCEPT
61 return view().subview(offset, extent);
64 CBuffer2DView<T> view() const MUDA_NOEXCEPT
66 return CBuffer2DView<T>{m_data, m_pitch_bytes, Offset2D::Zero(), m_extent};
68 operator CBuffer2DView<T>()
const MUDA_NOEXCEPT {
return view(); }
72 auto extent() const MUDA_NOEXCEPT {
return m_extent; }
73 auto capacity() const MUDA_NOEXCEPT {
return m_capacity; }
74 auto pitch_bytes() const MUDA_NOEXCEPT {
return m_pitch_bytes; }
75 auto total_size() const MUDA_NOEXCEPT
77 return m_extent.width() * m_extent.height();
79 T* data() MUDA_NOEXCEPT {
return m_data; }
80 const T* data() const MUDA_NOEXCEPT {
return m_data; }
84 #include "details/device_buffer_2d.inl"