3 #include <muda/muda_def.h> 14 MUDA_GENERIC
Extent2D() MUDA_NOEXCEPT : m_extent{~0ull, ~0ull} {}
16 MUDA_GENERIC
Extent2D(
size_t height,
size_t width) MUDA_NOEXCEPT
17 : m_extent{height, width}
21 MUDA_GENERIC
size_t height()
const MUDA_NOEXCEPT {
return m_extent[0]; }
22 MUDA_GENERIC
size_t width()
const MUDA_NOEXCEPT {
return m_extent[1]; }
25 MUDA_GENERIC cudaExtent cuda_extent()
const MUDA_NOEXCEPT
27 return cudaExtent{width() *
sizeof(T), height(), 1};
30 MUDA_GENERIC
bool valid()
const 32 return m_extent[0] != ~0ull && m_extent[1] != ~0ull;
44 MUDA_GENERIC
Extent3D() MUDA_NOEXCEPT : m_extent{~0ull, ~0ull, ~0ull} {}
45 MUDA_GENERIC
Extent3D(
size_t depth,
size_t height,
size_t width) MUDA_NOEXCEPT
46 : m_extent{depth, height, width}
50 MUDA_GENERIC
size_t depth()
const MUDA_NOEXCEPT {
return m_extent[0]; }
51 MUDA_GENERIC
size_t height()
const MUDA_NOEXCEPT {
return m_extent[1]; }
52 MUDA_GENERIC
size_t width()
const MUDA_NOEXCEPT {
return m_extent[2]; }
55 MUDA_GENERIC cudaExtent cuda_extent()
const MUDA_NOEXCEPT
57 return cudaExtent{width() *
sizeof(T), height(), depth()};
60 MUDA_GENERIC
bool valid()
const 62 return m_extent[0] != ~0ull && m_extent[1] != ~0ull && m_extent[2] != ~0ull;
65 static MUDA_GENERIC
Extent3D Zero() MUDA_NOEXCEPT
76 MUDA_GENERIC
Offset2D() MUDA_NOEXCEPT : m_offset{~0ull, ~0ull} {}
80 MUDA_GENERIC
Offset2D(
size_t offset_in_height,
size_t offset_in_width) MUDA_NOEXCEPT
81 : m_offset{offset_in_height, offset_in_width}
85 MUDA_GENERIC
size_t offset_in_height()
const MUDA_NOEXCEPT
90 MUDA_GENERIC
size_t offset_in_width()
const MUDA_NOEXCEPT
96 MUDA_GENERIC cudaPos cuda_pos()
const MUDA_NOEXCEPT
98 return cudaPos{offset_in_width() *
sizeof(T), offset_in_height(), 0};
107 MUDA_GENERIC
Offset3D() MUDA_NOEXCEPT : m_offset{~0ull, ~0ull, ~0ull} {}
109 static MUDA_GENERIC
Offset3D Zero() MUDA_NOEXCEPT
114 MUDA_GENERIC
Offset3D(
size_t offset_in_depth,
size_t offset_in_height,
size_t offset_in_width) MUDA_NOEXCEPT
115 : m_offset{offset_in_depth, offset_in_height, offset_in_width}
119 MUDA_GENERIC
size_t offset_in_depth()
const MUDA_NOEXCEPT
124 MUDA_GENERIC
size_t offset_in_height()
const MUDA_NOEXCEPT
129 MUDA_GENERIC
size_t offset_in_width()
const MUDA_NOEXCEPT
134 template <
typename T>
135 MUDA_GENERIC cudaPos cuda_pos()
const MUDA_NOEXCEPT
137 return cudaPos{offset_in_width() *
sizeof(T), offset_in_height(), offset_in_depth()};
141 MUDA_INLINE MUDA_GENERIC
Extent2D as_extent(
const Offset2D& offset) MUDA_NOEXCEPT
143 return Extent2D{offset.offset_in_height(), offset.offset_in_width()};
146 MUDA_INLINE MUDA_GENERIC
Extent3D as_extent(
const Offset3D& offset) MUDA_NOEXCEPT
148 return Extent3D{offset.offset_in_depth(), offset.offset_in_height(), offset.offset_in_width()};
151 MUDA_INLINE MUDA_GENERIC
Offset2D as_offset(
const Extent2D& extent) MUDA_NOEXCEPT
153 return Offset2D{extent.height(), extent.width()};
156 MUDA_INLINE MUDA_GENERIC
Offset3D as_offset(
const Extent3D& extent) MUDA_NOEXCEPT
158 return Offset3D{extent.depth(), extent.height(), extent.width()};
163 return Offset2D{std::min(lhs.offset_in_height(), rhs.offset_in_height()),
164 std::min(lhs.offset_in_width(), rhs.offset_in_width())};
169 return Offset3D{std::min(lhs.offset_in_depth(), rhs.offset_in_depth()),
170 std::min(lhs.offset_in_height(), rhs.offset_in_height()),
171 std::min(lhs.offset_in_width(), rhs.offset_in_width())};
176 return Extent2D{std::max(lhs.height(), rhs.height()),
177 std::max(lhs.width(), rhs.width())};
182 return Extent3D{std::max(lhs.depth(), rhs.depth()),
183 std::max(lhs.height(), rhs.height()),
184 std::max(lhs.width(), rhs.width())};
187 #define MUDA_DEFINE_COMPARISON_OPERATOR(op) \ 188 MUDA_INLINE MUDA_GENERIC bool operator op(const Extent2D& lhs, const Extent2D& rhs) MUDA_NOEXCEPT \ 190 return (lhs.height() op rhs.height()) && (lhs.width() op rhs.width()); \ 192 MUDA_INLINE MUDA_GENERIC bool operator op(const Extent3D& lhs, const Extent3D& rhs) MUDA_NOEXCEPT \ 194 return (lhs.depth() op rhs.depth()) && (lhs.height() op rhs.height()) \ 195 && (lhs.width() op rhs.width()); \ 198 MUDA_DEFINE_COMPARISON_OPERATOR(<=);
199 MUDA_DEFINE_COMPARISON_OPERATOR(<);
200 MUDA_DEFINE_COMPARISON_OPERATOR(==);
202 #undef MUDA_DEFINE_COMPARISON_OPERATOR 205 #define MUDA_DEFINE_ARITHMATIC_OPERATOR(op) \ 206 MUDA_INLINE MUDA_GENERIC Extent2D operator op(const Extent2D& lhs, \ 207 const Extent2D& rhs) MUDA_NOEXCEPT \ 209 return Extent2D{lhs.height() op rhs.height(), lhs.width() op rhs.width()}; \ 211 MUDA_INLINE MUDA_GENERIC Extent3D operator op(const Extent3D& lhs, \ 212 const Extent3D& rhs) MUDA_NOEXCEPT \ 214 return Extent3D{lhs.depth() op rhs.depth(), \ 215 lhs.height() op rhs.height(), \ 216 lhs.width() op rhs.width()}; \ 218 MUDA_INLINE MUDA_GENERIC Offset2D operator op(const Offset2D& lhs, \ 219 const Offset2D& rhs) MUDA_NOEXCEPT \ 221 return Offset2D{lhs.offset_in_height() op rhs.offset_in_height(), \ 222 lhs.offset_in_width() op rhs.offset_in_width()}; \ 224 MUDA_INLINE MUDA_GENERIC Offset3D operator op(const Offset3D& lhs, \ 225 const Offset3D& rhs) MUDA_NOEXCEPT \ 227 return Offset3D{lhs.offset_in_depth() op rhs.offset_in_depth(), \ 228 lhs.offset_in_height() op rhs.offset_in_height(), \ 229 lhs.offset_in_width() op rhs.offset_in_width()}; \ 232 MUDA_DEFINE_ARITHMATIC_OPERATOR(+);
233 MUDA_DEFINE_ARITHMATIC_OPERATOR(-);
234 #undef MUDA_DEFINE_ARITHMATIC_OPERATOR