28 using auto_const_t =
typename Base::template auto_const_t<U>;
30 auto_const_t<T>* m_data;
42 MUDA_GENERIC
Dense2DBase() MUDA_NOEXCEPT : m_data(
nullptr) {}
44 MUDA_GENERIC
Dense2DBase(auto_const_t<T>* p,
const int2& offset,
const int2& dim,
int pitch_bytes) MUDA_NOEXCEPT
48 m_pitch_bytes(pitch_bytes)
52 MUDA_GENERIC
auto as_const()
const MUDA_NOEXCEPT
54 return ConstViewer{m_data, m_offset, m_dim, m_pitch_bytes};
57 MUDA_GENERIC
operator ConstViewer()
const MUDA_NOEXCEPT
63 MUDA_GENERIC auto_const_t<T>& operator()(
int x,
int y) MUDA_NOEXCEPT
71 reinterpret_cast<auto_const_t<std::byte>*
>(m_data) + x * m_pitch_bytes;
72 return *((auto_const_t<T>*)(height_begin) + y);
75 MUDA_GENERIC auto_const_t<T>& operator()(
const int2& xy) MUDA_NOEXCEPT
77 return operator()(xy.x, xy.y);
80 MUDA_GENERIC auto_const_t<T>& flatten(
int i)
82 if constexpr(DEBUG_VIEWER)
84 MUDA_KERNEL_ASSERT(i >= 0 && i < total_size(),
85 "Dense2D[%s:%s]: out of range, index=%d, total_size=%d. %s(%d)",
95 return operator()(x, y);
98 MUDA_GENERIC auto_const_t<T>* data() MUDA_NOEXCEPT {
return m_data; }
101 MUDA_GENERIC
const T& operator()(
const int2& xy)
const MUDA_NOEXCEPT
103 return remove_const(*
this)(xy);
107 MUDA_GENERIC
const T& operator()(
int x,
int y)
const MUDA_NOEXCEPT
109 return remove_const(*
this)(x, y);
112 MUDA_GENERIC
const T& flatten(
int i)
const
114 return remove_const(*this).flatten(i);
117 MUDA_GENERIC
const T* data()
const MUDA_NOEXCEPT {
return m_data; }
119 MUDA_GENERIC
auto total_size()
const MUDA_NOEXCEPT
121 return m_dim.x * m_dim.y;
124 MUDA_GENERIC
auto area()
const MUDA_NOEXCEPT {
return total_size(); }
126 MUDA_GENERIC
auto dim()
const MUDA_NOEXCEPT {
return m_dim; }
128 MUDA_GENERIC
auto pitch_bytes()
const MUDA_NOEXCEPT
130 return m_pitch_bytes;
134 MUDA_INLINE MUDA_GENERIC
void check_range(
int x,
int y)
const MUDA_NOEXCEPT
136 if constexpr(DEBUG_VIEWER)
137 if(!(x >= 0 && x < m_dim.x && y >= 0 && y < m_dim.y))
139 MUDA_KERNEL_ERROR(
"Dense2D[%s:%s]: out of range, index=(%d,%d) dim=(%d,%d). %s(%d)",
147 this->kernel_line());
151 MUDA_INLINE MUDA_GENERIC
void check()
const MUDA_NOEXCEPT
153 if constexpr(DEBUG_VIEWER)
155 MUDA_KERNEL_ASSERT(m_data,
156 "Dense2D[%s:%s]: m_data is null. %s(%d)",
160 this->kernel_line());
195 return Dense2D<T>{data, make_int2(0, 0), dim,
static_cast<int>(dim.y *
sizeof(T))};