MUDA
Loading...
Searching...
No Matches
buffer_2d_view.h
1#pragma once
2#include <cuda.h>
3#include <cuda_runtime.h>
4#include <cuda_runtime_api.h>
5#include <cinttypes>
6#include <muda/type_traits/type_modifier.h>
7#include <muda/viewer/dense/dense_2d.h>
8#include <muda/tools/extent.h>
9#include <muda/buffer/buffer_info_accessor.h>
10#include <muda/view/view_base.h>
11namespace muda
12{
13template <bool IsConst, typename T>
14class Buffer2DViewT : public ViewBase<IsConst>
15{
16 using Base = ViewBase<IsConst>;
17
18 template <typename U>
19 using auto_const_t = typename Base::template auto_const_t<T>;
20
21 friend class BufferLaunch;
22
23 template <bool OtherIsConst, typename U>
24 friend class Buffer2DViewT;
25
26
27 public:
28 static_assert(!std::is_const_v<T>, "Ty must be non-const");
31
32 using CViewer = CDense2D<T>;
33 using Viewer = Dense2D<T>;
34 using ThisViewer = std::conditional_t<IsConst, CViewer, Viewer>;
35
36 private:
38
39 protected:
40 auto_const_t<T>* m_data = nullptr;
41 size_t m_pitch_bytes = ~0;
42 size_t m_origin_width = 0;
43 size_t m_origin_height = 0;
44 Offset2D m_offset;
45 Extent2D m_extent;
46
47 public:
48 MUDA_GENERIC Buffer2DViewT() MUDA_NOEXCEPT = default;
49
50 MUDA_GENERIC Buffer2DViewT(const Buffer2DViewT&) MUDA_NOEXCEPT = default;
51
52 template <bool OtherIsConst>
53 MUDA_GENERIC Buffer2DViewT(const Buffer2DViewT<OtherIsConst, T>& other) MUDA_NOEXCEPT
54 MUDA_REQUIRES(!OtherIsConst);
55
56 MUDA_GENERIC Buffer2DViewT(auto_const_t<T>* data,
57 size_t pitch_bytes,
58 size_t origin_width,
59 size_t origin_height,
60 const Offset2D& offset,
61 const Extent2D& extent) MUDA_NOEXCEPT;
62
63 MUDA_GENERIC Buffer2DViewT(auto_const_t<T>* data,
64 size_t pitch_bytes,
65 const Offset2D& offset,
66 const Extent2D& extent) MUDA_NOEXCEPT;
67
68 ConstView as_const() const MUDA_NOEXCEPT;
69
70 MUDA_GENERIC auto_const_t<T>* data(size_t x, size_t y) const MUDA_NOEXCEPT;
71
72 MUDA_GENERIC auto_const_t<T>* data(size_t flatten_i) const MUDA_NOEXCEPT;
73
74 MUDA_GENERIC auto_const_t<T>* origin_data() const MUDA_NOEXCEPT;
75
76 MUDA_GENERIC ThisView subview(Offset2D offset, Extent2D extent = {}) const MUDA_NOEXCEPT;
77
78 MUDA_GENERIC Extent2D extent() const MUDA_NOEXCEPT;
79
80 MUDA_GENERIC size_t pitch_bytes() const MUDA_NOEXCEPT;
81
82 MUDA_GENERIC Offset2D offset() const MUDA_NOEXCEPT;
83
84 MUDA_GENERIC size_t total_size() const MUDA_NOEXCEPT;
85
86 MUDA_GENERIC CViewer cviewer() const MUDA_NOEXCEPT;
87
88 MUDA_GENERIC ThisViewer viewer() const MUDA_NOEXCEPT;
89
90 MUDA_HOST void copy_to(T* host) const;
91
92 MUDA_HOST void fill(const T& v) MUDA_REQUIRES(!IsConst);
93
94 MUDA_HOST void copy_from(const Buffer2DViewT<true, T>& other) MUDA_REQUIRES(!IsConst);
95
96 MUDA_HOST void copy_from(const T* host) MUDA_REQUIRES(!IsConst);
97
98 private:
99 MUDA_GENERIC cudaPitchedPtr cuda_pitched_ptr() const MUDA_NOEXCEPT;
100};
101
102template <typename T>
104
105template <typename T>
107
108template <typename T>
110{
111 using type = CBuffer2DView<T>;
112};
113
114template <typename T>
116{
117 using type = Buffer2DView<T>;
118};
119} // namespace muda
120
121#include "details/buffer_2d_view.inl"
Definition buffer_2d_view.h:15
Definition buffer_launch.h:13
Definition dense_2d.h:20
Definition extent.h:10
Definition extent.h:72
Definition view_base.h:8
Definition buffer_info_accessor.h:6
Definition type_modifier.h:22
Definition type_modifier.h:28