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
118 template <int N, typename T, typename T2>
120 template <int N, typename T, typename T2>
122 template <int N, typename T, typename T2>
124 template <int N, typename T, typename T2>
126 template <int N, typename T, typename T2>
128 template <int N, typename T, typename T2>
130 template <int N, typename T, typename T2>
132 template <int N, typename T, typename T2>
134 template <int N, typename T, typename T2>
136 template <int N, typename T, typename T2>
138
139 // a Rect is a pair of points defining the lower and upper bounds of an N-D rectangle
140 // the bounds are INCLUSIVE
141
142 template <int N, typename T>
144 typedef ONLY_IF_INTEGRAL(T) value_type;
146
148 Rect(void);
150 Rect(const Point<N, T> &_lo, const Point<N, T> &_hi);
151 // copies allow type coercion (assuming the underlying type does)
152 template <typename T2>
153 REALM_CUDA_HD Rect(const Rect<N, T2> &copy_from);
154 template <typename T2>
156
157 // constructs a guaranteed-empty rectangle
159 static Rect<N, T> make_empty(void);
160
162 bool empty(void) const;
164 size_t volume(void) const;
165
167 bool contains(const Point<N, T> &p) const;
168
169 // true if all points in other are in this rectangle
171 bool contains(const Rect<N, T> &other) const;
173 bool contains(const IndexSpace<N, T> &is) const;
174
175 // true if there are any points in the intersection of the two rectangles
177 bool overlaps(const Rect<N, T> &other) const;
178
180 Rect<N, T> intersection(const Rect<N, T> &other) const;
181
182 // returns the _bounding box_ of the union of two rectangles (the actual union
183 // might not be a rectangle)
185 Rect<N, T> union_bbox(const Rect<N, T> &other) const;
186
187 template <int N2, typename T2>
189 const Point<N2, T2> &offset) const;
190
191 // copy and fill operations (wrappers for IndexSpace versions)
192 Event fill(const std::vector<CopySrcDstField> &dsts,
193 const ProfilingRequestSet &requests, const void *fill_value,
194 size_t fill_value_size, Event wait_on = Event::NO_EVENT,
195 int priority = 0) const;
196
197 Event copy(const std::vector<CopySrcDstField> &srcs,
198 const std::vector<CopySrcDstField> &dsts,
199 const ProfilingRequestSet &requests, Event wait_on = Event::NO_EVENT,
200 int priority = 0) const;
201
202 Event copy(const std::vector<CopySrcDstField> &srcs,
203 const std::vector<CopySrcDstField> &dsts, const IndexSpace<N, T> &mask,
204 const ProfilingRequestSet &requests, Event wait_on = Event::NO_EVENT,
205 int priority = 0) const;
206 };
207
208 template <int N, typename T>
209 std::ostream &operator<<(std::ostream &os, const Rect<N, T> &p);
210
211 template <int M, int N, typename T>
212 std::ostream &operator<<(std::ostream &os, const Matrix<M, N, T> &p);
213
214 template <int N, typename T, typename T2>
215 REALM_CUDA_HD bool operator==(const Rect<N, T> &lhs, const Rect<N, T2> &rhs);
216 template <int N, typename T, typename T2>
217 REALM_CUDA_HD bool operator!=(const Rect<N, T> &lhs, const Rect<N, T2> &rhs);
218
219 // rectangles may be displaced by a vector (i.e. point)
220 template <int N, typename T, typename T2>
222 template <int N, typename T, typename T2>
224 template <int N, typename T, typename T2>
226 template <int N, typename T, typename T2>
228
229 template <int M, int N, typename T>
231 typedef ONLY_IF_INTEGRAL(T) value_type;
232 Point<N, T> rows[M];
233
235 Matrix(void);
236 // copies allow type coercion (assuming the underlying type does)
237 template <typename T2>
239 template <typename T2>
241
245 const Point<N, T> &operator[](int index) const;
246 };
247
248 template <int M, int N, typename T, typename T2>
250 template <int M, int P, int N, typename T, typename T2>
252 const Matrix<P, N, T2> &n);
253 template <int M, int N, typename T, typename T2>
255 template <int M, int N, typename T, typename T2>
257
258 template <int N, typename T>
260 public:
262 bool valid;
265
269 PointInRectIterator(const Rect<N, T> &_r, bool _fortran_order = true);
271 void reset(const Rect<N, T> &_r, bool _fortran_order = true);
273 bool step(void);
274 };
275
276}; // namespace Realm
277
278// specializations of std::less<T> for Point/Rect<N,T> allow
279// them to be used in STL containers
280namespace std {
281 template <int N, typename T>
282 struct less<Realm::Point<N, T>> {
283 bool operator()(const Realm::Point<N, T> &p1, const Realm::Point<N, T> &p2) const;
284 };
285
286 template <int N, typename T>
287 struct less<Realm::Rect<N, T>> {
288 bool operator()(const Realm::Rect<N, T> &r1, const Realm::Rect<N, T> &r2) const;
289 };
290}; // namespace std
291
292#include "realm/point.inl"
293
294#undef ONLY_IF_INTEGRAL
295
296#endif // ifndef REALM_POINT_H
Definition event.h:50
Definition point.h:259
bool valid
Definition point.h:262
REALM_CUDA_HD bool step(void)
Point< N, T > p
Definition point.h:261
REALM_CUDA_HD PointInRectIterator(void)
Rect< N, T > rect
Definition point.h:263
REALM_CUDA_HD void reset(const Rect< N, T > &_r, bool _fortran_order=true)
bool fortran_order
Definition point.h:264
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:539
Realm::PointInRectIterator< N, T > PointInRectIterator
Definition prealm.h:582
Realm::Matrix< M, N, T > Matrix
Definition prealm.h:584
Definition activemsg.h:38
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
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)
Definition indexspace.h:1279
#define ONLY_IF_INTEGRAL(Type)
Definition point.h:49
Definition indexspace.h:323
Definition point.h:230
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:143
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:145
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)
bool operator()(const Realm::Point< N, T > &p1, const Realm::Point< N, T > &p2) const
bool operator()(const Realm::Rect< N, T > &r1, const Realm::Rect< N, T > &r2) const