MUDA
Loading...
Searching...
No Matches
device_buffer_3d.h
Go to the documentation of this file.
1/*****************************************************************/
11#pragma once
12#include <cuda.h>
13#include <cuda_runtime.h>
14#include <cuda_runtime_api.h>
15#include <vector>
16#include <muda/viewer/dense.h>
17#include <muda/buffer/buffer_3d_view.h>
18
19namespace muda
20{
21template <typename T>
23{
24 private:
25 friend class BufferLaunch;
26 friend class NDReshaper;
27
28 T* m_data = nullptr;
29 size_t m_pitch_bytes = 0;
30 size_t m_pitch_bytes_area = 0;
31 Extent3D m_extent = Extent3D::Zero();
32 Extent3D m_capacity = Extent3D::Zero();
33
34 public:
35 using value_type = T;
36
37 DeviceBuffer3D(const Extent3D& n);
39
41 DeviceBuffer3D(DeviceBuffer3D&& other) MUDA_NOEXCEPT;
42 DeviceBuffer3D& operator=(const DeviceBuffer3D<T>& other);
43 DeviceBuffer3D& operator=(DeviceBuffer3D<T>&& other);
44
46 DeviceBuffer3D& operator=(CBuffer3DView<T> other);
47
48 void copy_to(std::vector<T>& host) const;
49 void copy_from(const std::vector<T>& host);
50
51 void resize(Extent3D new_size);
52 void resize(Extent3D new_size, const T& value);
53 void reserve(Extent3D new_capacity);
54 void clear();
55 void shrink_to_fit();
56 void fill(const T& v);
57
58 Dense3D<T> viewer() MUDA_NOEXCEPT { return view().viewer(); }
59 CDense3D<T> cviewer() const MUDA_NOEXCEPT { return view().viewer(); }
60
61 Buffer3DView<T> view(Offset3D offset, Extent3D extent = {}) MUDA_NOEXCEPT
62 {
63 return view().subview(offset, extent);
64 }
65 Buffer3DView<T> view() MUDA_NOEXCEPT
66 {
67 return Buffer3DView<T>{
68 m_data, m_pitch_bytes, m_pitch_bytes_area, Offset3D::Zero(), m_extent};
69 }
70 operator Buffer3DView<T>() MUDA_NOEXCEPT { return view(); }
71
72 CBuffer3DView<T> view(Offset3D offset, Extent3D extent = {}) const MUDA_NOEXCEPT
73 {
74 return view().subview(offset, extent);
75 }
76
77 CBuffer3DView<T> view() const MUDA_NOEXCEPT
78 {
79 return CBuffer3DView<T>{
80 m_data, m_pitch_bytes, m_pitch_bytes_area, Offset3D::Zero(), m_extent};
81 }
82 operator CBuffer3DView<T>() const MUDA_NOEXCEPT { return view(); }
83
85
86 auto extent() const MUDA_NOEXCEPT { return m_extent; }
87 auto capacity() const MUDA_NOEXCEPT { return m_capacity; }
88 auto pitch_bytes() const MUDA_NOEXCEPT { return m_pitch_bytes; }
89 auto pitch_bytes_area() const MUDA_NOEXCEPT { return m_pitch_bytes_area; }
90 auto total_size() const MUDA_NOEXCEPT
91 {
92 return m_extent.width() * m_extent.height() * m_extent.depth();
93 }
94 T* data() MUDA_NOEXCEPT { return m_data; }
95 const T* data() const MUDA_NOEXCEPT { return m_data; }
96};
97} // namespace muda
98
99#include "details/device_buffer_3d.inl"
Definition buffer_3d_view.h:15
Definition buffer_launch.h:13
Definition dense_3d.h:20
Definition device_buffer_3d.h:23
Definition extent.h:40
Definition nd_reshaper.h:16
Definition extent.h:103