Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
point.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// points and rects (i.e. dense index spaces) in Realm
19
20#ifndef REALM_POINT_H
21#define REALM_POINT_H
22
23#include "realm/realm_config.h"
24
25#include "realm/event.h"
26#include "realm/utils.h"
27
28#include <iostream>
29#include <type_traits>
30
31namespace Realm {
32
33 template <int N, typename T = int>
34 struct Point;
35 template <int N, typename T = int>
36 struct Rect;
37 template <int N, typename T = int>
39 template <int M, int N, typename T = int>
40 struct Matrix;
41 template <int N, typename T = int>
42 struct IndexSpace;
43
44 struct CopySrcDstField;
45 class ProfilingRequestSet;
46
47 // adding this as a parameter to a templated method uses SFINAE to only allow
48 // the template to be instantiated with an integral type
49#define ONLY_IF_INTEGRAL(Type) std::enable_if_t<std::is_integral<Type>::value, Type>
50
51 // a Point is a tuple describing a point in an N-dimensional space - the default "base
52 // type"
53 // for each dimension is int, but 64-bit indices are supported as well
54 template <int N, typename T>
56
57 typedef ONLY_IF_INTEGRAL(T) value_type;
58 value_type values[N]; // use operator[] instead
59
60 Point(void) = default;
62 explicit Point(value_type val);
63 template <typename Arg0, typename Arg1, typename... Args>
64 REALM_CUDA_HD Point(Arg0 val0, Arg1 val1, Args... vals);
65 // construct from any integral value, same for all dimensions
66 template <typename T2, std::enable_if_t<std::is_integral<T2>::value, bool> = true>
67 REALM_CUDA_HD explicit Point(T2 val);
68 template <typename T2, std::enable_if_t<std::is_integral<T2>::value, bool> = true>
69 REALM_CUDA_HD explicit Point(T2 vals[N]);
70 // copies allow type coercion (assuming the underlying type does)
71 template <typename T2>
72 REALM_CUDA_HD Point(const Point<N, T2> &copy_from);
73 template <typename T2>
75
77 T &operator[](int index);
79 const T &operator[](int index) const;
80
81 template <typename T2>
82 REALM_CUDA_HD T dot(const Point<N, T2> &rhs) const;
83
84 // 1-4D accessors. These will only be available if the class's dimensioned allow for
85 // it, otherwise it is a compiler error to use them
90 REALM_CUDA_HD const T &x() const;
91 REALM_CUDA_HD const T &y() const;
92 REALM_CUDA_HD const T &z() const;
93 REALM_CUDA_HD const T &w() const;
94
96 static constexpr Point<N, T> ZEROES(void);
98 static constexpr Point<N, T> ONES(void);
99 };
100
103 template <typename T = int, typename... U>
104 [[nodiscard]] constexpr auto make_point(const U &...rest) -> Point<sizeof...(rest), T>
105 {
106 return Point<sizeof...(rest), ONLY_IF_INTEGRAL(T)>(rest...);
107 }
108
109 template <int N, typename T>
110 std::ostream &operator<<(std::ostream &os, const Point<N, T> &p);
111
112 // component-wise operators defined on Point<N,T> (with optional coercion)
113 template <int N, typename T, typename T2>
114 REALM_CUDA_HD bool operator==(const Point<N, T> &lhs, const Point<N, T2> &rhs);
115 template <int N, typename T, typename T2>
116 REALM_CUDA_HD bool operator!=(const Point<N, T> &lhs, const Point<N, T2> &rhs);
117 // lexicographic ordering, allows Point<N,T> to be used in STL containers
118 template <int N, typename T>
119 REALM_CUDA_HD bool operator<(const Point<N, T> &lhs, const Point<N, T> &rhs);
120
121 template <int N, typename T, typename T2>
123 template <int N, typename T, typename T2>
125 template <int N, typename T, typename T2>
127 template <int N, typename T, typename T2>
129 template <int N, typename T, typename T2>
131 template <int N, typename T, typename T2>
133 template <int N, typename T, typename T2>
135 template <int N, typename T, typename T2>
137 template <int N, typename T, typename T2>
139 template <int N, typename T, typename T2>
141
142 // a Rect is a pair of points defining the lower and upper bounds of an N-D rectangle
143 // the bounds are INCLUSIVE
144
145 template <int N, typename T>
147 typedef ONLY_IF_INTEGRAL(T) value_type;
149
151 Rect(void);
153 Rect(const Point<N, T> &_lo, const Point<N, T> &_hi);
154 // copies allow type coercion (assuming the underlying type does)
155 template <typename T2>
156 REALM_CUDA_HD Rect(const Rect<N, T2> &copy_from);
157 template <typename T2>
159
160 // constructs a guaranteed-empty rectangle
162 static Rect<N, T> make_empty(void);
163
165 bool empty(void) const;
167 size_t volume(void) const;
168
170 bool contains(const Point<N, T> &p) const;
171
172 // true if all points in other are in this rectangle
174 bool contains(const Rect<N, T> &other) const;
176 bool contains(const IndexSpace<N, T> &is) const;
177
178 // true if there are any points in the intersection of the two rectangles
180 bool overlaps(const Rect<N, T> &other) const;
181
183 Rect<N, T> intersection(const Rect<N, T> &other) const;
184
185 // returns the _bounding box_ of the union of two rectangles (the actual union
186 // might not be a rectangle)
188 Rect<N, T> union_bbox(const Rect<N, T> &other) const;
189
190 template <int N2, typename T2>
192 const Point<N2, T2> &offset) const;
193
194 // copy and fill operations (wrappers for IndexSpace versions)
195 Event fill(const std::vector<CopySrcDstField> &dsts,
196 const ProfilingRequestSet &requests, const void *fill_value,
197 size_t fill_value_size, Event wait_on = Event::NO_EVENT,
198 int priority = 0) const;
199
200 Event copy(const std::vector<CopySrcDstField> &srcs,
201 const std::vector<CopySrcDstField> &dsts,
202 const ProfilingRequestSet &requests, Event wait_on = Event::NO_EVENT,
203 int priority = 0) const;
204
205 Event copy(const std::vector<CopySrcDstField> &srcs,
206 const std::vector<CopySrcDstField> &dsts, const IndexSpace<N, T> &mask,
207 const ProfilingRequestSet &requests, Event wait_on = Event::NO_EVENT,
208 int priority = 0) const;
209 };
210
211 template <int N, typename T>
212 std::ostream &operator<<(std::ostream &os, const Rect<N, T> &p);
213
214 template <int M, int N, typename T>
215 std::ostream &operator<<(std::ostream &os, const Matrix<M, N, T> &p);
216
217 template <int N, typename T, typename T2>
218 REALM_CUDA_HD bool operator==(const Rect<N, T> &lhs, const Rect<N, T2> &rhs);
219 template <int N, typename T, typename T2>
220 REALM_CUDA_HD bool operator!=(const Rect<N, T> &lhs, const Rect<N, T2> &rhs);
221 // lexicographic ordering (by lo, then hi), allows Rect<N,T> to be used in STL
222 // containers
223 template <int N, typename T>
224 REALM_CUDA_HD bool operator<(const Rect<N, T> &lhs, const Rect<N, T> &rhs);
225
226 // rectangles may be displaced by a vector (i.e. point)
227 template <int N, typename T, typename T2>
229 template <int N, typename T, typename T2>
231 template <int N, typename T, typename T2>
233 template <int N, typename T, typename T2>
235
236 template <int M, int N, typename T>
238 typedef ONLY_IF_INTEGRAL(T) value_type;
239 Point<N, T> rows[M];
240
242 Matrix(void);
243 // copies allow type coercion (assuming the underlying type does)
244 template <typename T2>
246 template <typename T2>
248
252 const Point<N, T> &operator[](int index) const;
253 };
254
255 template <int M, int N, typename T, typename T2>
257 template <int M, int P, int N, typename T, typename T2>
259 const Matrix<P, N, T2> &n);
260 template <int M, int N, typename T, typename T2>
262 template <int M, int N, typename T, typename T2>
264
265 template <int N, typename T>
267 public:
269 bool valid;
272
276 PointInRectIterator(const Rect<N, T> &_r, bool _fortran_order = true);
278 void reset(const Rect<N, T> &_r, bool _fortran_order = true);
280 bool step(void);
281 };
282
283}; // namespace Realm
284
285#include "realm/point.inl"
286
287#undef ONLY_IF_INTEGRAL
288
289#endif // ifndef REALM_POINT_H
Definition event.h:50
Definition point.h:266
bool valid
Definition point.h:269
REALM_CUDA_HD bool step(void)
Point< N, T > p
Definition point.h:268
REALM_CUDA_HD PointInRectIterator(void)
Rect< N, T > rect
Definition point.h:270
REALM_CUDA_HD void reset(const Rect< N, T > &_r, bool _fortran_order=true)
bool fortran_order
Definition point.h:271
REALM_CUDA_HD PointInRectIterator(const Rect< N, T > &_r, bool _fortran_order=true)
Definition profiling.h:363
#define REALM_CUDA_HD
Definition compiler_support.h:95
#define REALM_PUBLIC_API
Definition compiler_support.h:217
Realm::Point< N, T > Point
Definition prealm.h:546
Realm::PointInRectIterator< N, T > PointInRectIterator
Definition prealm.h:589
Realm::Matrix< M, N, T > Matrix
Definition prealm.h:591
Definition activemsg.h:42
REALM_CUDA_HD Point< N, T > operator%(const Point< N, T > &lhs, const Point< N, T2 > &rhs)
REALM_CUDA_HD Point< N, T > operator+(const Point< N, T > &lhs, const Point< N, T2 > &rhs)
REALM_CUDA_HD Point< N, T > & operator+=(Point< N, T > &lhs, const Point< N, T2 > &rhs)
REALM_CUDA_HD Point< N, T > & operator*=(Point< N, T > &lhs, const Point< N, T2 > &rhs)
REALM_CUDA_HD Point< N, T > & operator/=(Point< N, T > &lhs, const Point< N, T2 > &rhs)
REALM_CUDA_HD bool operator!=(const Point< N, T > &lhs, const Point< N, T2 > &rhs)
REALM_CUDA_HD Point< N, T > & operator%=(Point< N, T > &lhs, const Point< N, T2 > &rhs)
constexpr auto make_point(const U &...rest) -> Point< sizeof...(rest), T >
Helper function to initialize Point from a list of types without needing to explicitly specify the di...
Definition point.h:104
bool operator<(const IndexSpace< N, T > &lhs, const IndexSpace< N, T > &rhs)
REALM_CUDA_HD bool operator==(const Point< N, T > &lhs, const Point< N, T2 > &rhs)
REALM_CUDA_HD Point< N, T > operator/(const Point< N, T > &lhs, const Point< N, T2 > &rhs)
REALM_CUDA_HD Point< N, T > operator*(const Point< N, T > &lhs, const Point< N, T2 > &rhs)
REALM_CUDA_HD Point< N, T > & operator-=(Point< N, T > &lhs, const Point< N, T2 > &rhs)
std::ostream & operator<<(std::ostream &os, const DenseRectangleList< N, T > &drl)
REALM_CUDA_HD Point< N, T > operator-(const Point< N, T > &lhs, const Point< N, T2 > &rhs)
#define ONLY_IF_INTEGRAL(Type)
Definition point.h:49
Definition indexspace.h:323
Definition point.h:237
REALM_CUDA_HD Matrix(void)
REALM_CUDA_HD Matrix(const Matrix< M, N, T2 > &copy_from)
REALM_CUDA_HD Matrix< M, N, T > & operator=(const Matrix< M, N, T2 > &copy_from)
REALM_CUDA_HD Point< N, T > & operator[](int index)
typedef ONLY_IF_INTEGRAL(T) value_type
REALM_CUDA_HD const Point< N, T > & operator[](int index) const
Definition point.h:55
REALM_CUDA_HD T & z()
REALM_CUDA_HD const T & x() const
Point(void)=default
REALM_CUDA_HD T & y()
REALM_CUDA_HD Point(T2 vals[N])
REALM_CUDA_HD const T & w() const
REALM_CUDA_HD Point< N, T > & operator=(const Point< N, T2 > &copy_from)
typedef ONLY_IF_INTEGRAL(T) value_type
REALM_CUDA_HD Point(T2 val)
REALM_CUDA_HD Point(const Point< N, T2 > &copy_from)
REALM_CUDA_HD T & w()
REALM_CUDA_HD T dot(const Point< N, T2 > &rhs) const
REALM_CUDA_HD const T & operator[](int index) const
REALM_CUDA_HD Point(value_type val)
REALM_CUDA_HD const T & y() const
static REALM_CUDA_HD constexpr Point< N, T > ONES(void)
REALM_CUDA_HD T & operator[](int index)
REALM_CUDA_HD Point(Arg0 val0, Arg1 val1, Args... vals)
static REALM_CUDA_HD constexpr Point< N, T > ZEROES(void)
REALM_CUDA_HD const T & z() const
REALM_CUDA_HD T & x()
Definition point.h:146
REALM_CUDA_HD bool contains(const IndexSpace< N, T > &is) const
REALM_CUDA_HD size_t volume(void) const
Event fill(const std::vector< CopySrcDstField > &dsts, const ProfilingRequestSet &requests, const void *fill_value, size_t fill_value_size, Event wait_on=Event::NO_EVENT, int priority=0) const
REALM_CUDA_HD Rect< N, T > intersection(const Rect< N, T > &other) const
REALM_CUDA_HD Rect(void)
typedef ONLY_IF_INTEGRAL(T) value_type
REALM_CUDA_HD bool contains(const Point< N, T > &p) const
REALM_CUDA_HD Rect< N, T > & operator=(const Rect< N, T2 > &copy_from)
Point< N, T > hi
Definition point.h:148
REALM_CUDA_HD bool empty(void) const
Event copy(const std::vector< CopySrcDstField > &srcs, const std::vector< CopySrcDstField > &dsts, const ProfilingRequestSet &requests, Event wait_on=Event::NO_EVENT, int priority=0) const
REALM_CUDA_HD bool contains(const Rect< N, T > &other) const
static REALM_CUDA_HD Rect< N, T > make_empty(void)
REALM_CUDA_HD bool overlaps(const Rect< N, T > &other) const
REALM_CUDA_HD Rect(const Rect< N, T2 > &copy_from)
REALM_CUDA_HD Rect< N, T > union_bbox(const Rect< N, T > &other) const
Rect< N2, T2 > REALM_CUDA_HD apply_transform(const Matrix< N2, N, T2 > &transform, const Point< N2, T2 > &offset) const
Event copy(const std::vector< CopySrcDstField > &srcs, const std::vector< CopySrcDstField > &dsts, const IndexSpace< N, T > &mask, const ProfilingRequestSet &requests, Event wait_on=Event::NO_EVENT, int priority=0) const
REALM_CUDA_HD Rect(const Point< N, T > &_lo, const Point< N, T > &_hi)