Repository navigation
Expand file tree
/
Copy pathextent.h
More file actions
237 lines (193 loc) · 8.28 KB
/
Copy pathextent.h
File metadata and controls
237 lines (193 loc) · 8.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#pragma once
#include <cuda.h>
#include <muda/muda_def.h>
#include <cinttypes>
#undef min
#undef max
namespace muda
{
class Extent2D
{
size_t m_extent[2];
public:
MUDA_GENERIC Extent2D() MUDA_NOEXCEPT : m_extent{0, 0} {}
MUDA_GENERIC Extent2D(size_t height, size_t width) MUDA_NOEXCEPT
: m_extent{height, width}
{
}
MUDA_GENERIC size_t height() const MUDA_NOEXCEPT { return m_extent[0]; }
MUDA_GENERIC size_t width() const MUDA_NOEXCEPT { return m_extent[1]; }
template <typename T>
MUDA_GENERIC cudaExtent cuda_extent() const MUDA_NOEXCEPT
{
return cudaExtent{width() * sizeof(T), height(), 1};
}
MUDA_GENERIC bool valid() const
{
return m_extent[0] != ~0ull && m_extent[1] != ~0ull;
}
static MUDA_GENERIC Extent2D Zero() MUDA_NOEXCEPT { return Extent2D{0, 0}; }
};
class Extent3D
{
size_t m_extent[3];
public:
MUDA_GENERIC Extent3D() MUDA_NOEXCEPT : m_extent{0, 0, 0} {}
MUDA_GENERIC Extent3D(size_t depth, size_t height, size_t width) MUDA_NOEXCEPT
: m_extent{depth, height, width}
{
}
MUDA_GENERIC size_t depth() const MUDA_NOEXCEPT { return m_extent[0]; }
MUDA_GENERIC size_t height() const MUDA_NOEXCEPT { return m_extent[1]; }
MUDA_GENERIC size_t width() const MUDA_NOEXCEPT { return m_extent[2]; }
template <typename T>
MUDA_GENERIC cudaExtent cuda_extent() const MUDA_NOEXCEPT
{
return cudaExtent{width() * sizeof(T), height(), depth()};
}
MUDA_GENERIC bool valid() const
{
return m_extent[0] != ~0ull && m_extent[1] != ~0ull && m_extent[2] != ~0ull;
}
static MUDA_GENERIC Extent3D Zero() MUDA_NOEXCEPT
{
return Extent3D{0, 0, 0};
}
};
class Offset2D
{
size_t m_offset[2];
public:
MUDA_GENERIC Offset2D() MUDA_NOEXCEPT : m_offset{0, 0} {}
static MUDA_GENERIC Offset2D Zero() MUDA_NOEXCEPT { return Offset2D{0, 0}; }
MUDA_GENERIC Offset2D(size_t offset_in_height, size_t offset_in_width) MUDA_NOEXCEPT
: m_offset{offset_in_height, offset_in_width}
{
}
MUDA_GENERIC size_t offset_in_height() const MUDA_NOEXCEPT
{
return m_offset[0];
}
MUDA_GENERIC size_t offset_in_width() const MUDA_NOEXCEPT
{
return m_offset[1];
}
template <typename T>
MUDA_GENERIC cudaPos cuda_pos() const MUDA_NOEXCEPT
{
return cudaPos{offset_in_width() * sizeof(T), offset_in_height(), 0};
}
};
class Offset3D
{
size_t m_offset[3];
public:
MUDA_GENERIC Offset3D() MUDA_NOEXCEPT : m_offset{0, 0, 0} {}
static MUDA_GENERIC Offset3D Zero() MUDA_NOEXCEPT
{
return Offset3D{0, 0, 0};
}
MUDA_GENERIC Offset3D(size_t offset_in_depth, size_t offset_in_height, size_t offset_in_width) MUDA_NOEXCEPT
: m_offset{offset_in_depth, offset_in_height, offset_in_width}
{
}
MUDA_GENERIC size_t offset_in_depth() const MUDA_NOEXCEPT
{
return m_offset[0];
}
MUDA_GENERIC size_t offset_in_height() const MUDA_NOEXCEPT
{
return m_offset[1];
}
MUDA_GENERIC size_t offset_in_width() const MUDA_NOEXCEPT
{
return m_offset[2];
}
template <typename T>
MUDA_GENERIC cudaPos cuda_pos() const MUDA_NOEXCEPT
{
return cudaPos{offset_in_width() * sizeof(T), offset_in_height(), offset_in_depth()};
}
};
MUDA_INLINE MUDA_GENERIC Extent2D as_extent(const Offset2D& offset) MUDA_NOEXCEPT
{
return Extent2D{offset.offset_in_height(), offset.offset_in_width()};
}
MUDA_INLINE MUDA_GENERIC Extent3D as_extent(const Offset3D& offset) MUDA_NOEXCEPT
{
return Extent3D{offset.offset_in_depth(), offset.offset_in_height(), offset.offset_in_width()};
}
MUDA_INLINE MUDA_GENERIC Offset2D as_offset(const Extent2D& extent) MUDA_NOEXCEPT
{
return Offset2D{extent.height(), extent.width()};
}
MUDA_INLINE MUDA_GENERIC Offset3D as_offset(const Extent3D& extent) MUDA_NOEXCEPT
{
return Offset3D{extent.depth(), extent.height(), extent.width()};
}
MUDA_INLINE MUDA_GENERIC Offset2D min(const Offset2D& lhs, const Offset2D& rhs)
{
return Offset2D{std::min(lhs.offset_in_height(), rhs.offset_in_height()),
std::min(lhs.offset_in_width(), rhs.offset_in_width())};
}
MUDA_INLINE MUDA_GENERIC Offset3D min(const Offset3D& lhs, const Offset3D& rhs)
{
return Offset3D{std::min(lhs.offset_in_depth(), rhs.offset_in_depth()),
std::min(lhs.offset_in_height(), rhs.offset_in_height()),
std::min(lhs.offset_in_width(), rhs.offset_in_width())};
}
MUDA_INLINE MUDA_GENERIC Extent2D max(const Extent2D& lhs, const Extent2D& rhs)
{
return Extent2D{std::max(lhs.height(), rhs.height()),
std::max(lhs.width(), rhs.width())};
}
MUDA_INLINE MUDA_GENERIC Extent3D max(const Extent3D& lhs, const Extent3D& rhs)
{
return Extent3D{std::max(lhs.depth(), rhs.depth()),
std::max(lhs.height(), rhs.height()),
std::max(lhs.width(), rhs.width())};
}
#define MUDA_DEFINE_COMPARISON_OPERATOR(op) \
MUDA_INLINE MUDA_GENERIC bool operator op(const Extent2D& lhs, const Extent2D& rhs) MUDA_NOEXCEPT \
{ \
return (lhs.height() op rhs.height()) && (lhs.width() op rhs.width()); \
} \
MUDA_INLINE MUDA_GENERIC bool operator op(const Extent3D& lhs, const Extent3D& rhs) MUDA_NOEXCEPT \
{ \
return (lhs.depth() op rhs.depth()) && (lhs.height() op rhs.height()) \
&& (lhs.width() op rhs.width()); \
}
MUDA_DEFINE_COMPARISON_OPERATOR(<=);
MUDA_DEFINE_COMPARISON_OPERATOR(<);
MUDA_DEFINE_COMPARISON_OPERATOR(==);
#undef MUDA_DEFINE_COMPARISON_OPERATOR
#define MUDA_DEFINE_ARITHMATIC_OPERATOR(op) \
MUDA_INLINE MUDA_GENERIC Extent2D operator op(const Extent2D& lhs, \
const Extent2D& rhs) MUDA_NOEXCEPT \
{ \
return Extent2D{lhs.height() op rhs.height(), lhs.width() op rhs.width()}; \
} \
MUDA_INLINE MUDA_GENERIC Extent3D operator op(const Extent3D& lhs, \
const Extent3D& rhs) MUDA_NOEXCEPT \
{ \
return Extent3D{lhs.depth() op rhs.depth(), \
lhs.height() op rhs.height(), \
lhs.width() op rhs.width()}; \
} \
MUDA_INLINE MUDA_GENERIC Offset2D operator op(const Offset2D& lhs, \
const Offset2D& rhs) MUDA_NOEXCEPT \
{ \
return Offset2D{lhs.offset_in_height() op rhs.offset_in_height(), \
lhs.offset_in_width() op rhs.offset_in_width()}; \
} \
MUDA_INLINE MUDA_GENERIC Offset3D operator op(const Offset3D& lhs, \
const Offset3D& rhs) MUDA_NOEXCEPT \
{ \
return Offset3D{lhs.offset_in_depth() op rhs.offset_in_depth(), \
lhs.offset_in_height() op rhs.offset_in_height(), \
lhs.offset_in_width() op rhs.offset_in_width()}; \
}
MUDA_DEFINE_ARITHMATIC_OPERATOR(+);
MUDA_DEFINE_ARITHMATIC_OPERATOR(-);
#undef MUDA_DEFINE_ARITHMATIC_OPERATOR
} // namespace muda