Legion Runtime
Loading...
Searching...
No Matches
legion_domain.h
Go to the documentation of this file.
1/* Copyright 2024 Stanford University, NVIDIA Corporation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef __LEGION_DOMAIN_H__
17#define __LEGION_DOMAIN_H__
18
19#include "realm.h"
20#include "legion/legion_types.h"
21
29namespace Legion {
30
31 template<int DIM, typename T = coord_t>
32 using Point = Realm::Point<DIM,T>;
33 template<int DIM, typename T = coord_t>
34 using Rect = Realm::Rect<DIM,T>;
35 template<int M, int N, typename T = coord_t>
36 using Transform = Realm::Matrix<M,N,T>;
37
45 template<int M, int N, typename T = coord_t>
47 private:
48 static_assert(M > 0, "M must be positive");
49 static_assert(N > 0, "N must be positive");
50 static_assert(std::is_integral<T>::value, "must be integral type");
51 public:
52 __CUDA_HD__
53 AffineTransform(void); // default to identity transform
54 // allow type coercions where possible
55 template<typename T2> __CUDA_HD__
56 AffineTransform(const AffineTransform<M,N,T2> &rhs);
57 template<typename T2, typename T3> __CUDA_HD__
58 AffineTransform(const Transform<M,N,T2> transform,
59 const Point<M,T3> offset);
60 public:
61 template<typename T2> __CUDA_HD__
62 AffineTransform<M,N,T>& operator=(const AffineTransform<M,N,T2> &rhs);
63 public:
64 // Apply the transformation to a point
65 template<typename T2> __CUDA_HD__
66 Point<M,T> operator[](const Point<N,T2> point) const;
67 // Compose the transform with another transform
68 template<int P> __CUDA_HD__
69 AffineTransform<M,P,T> operator()(const AffineTransform<N,P,T> &rhs) const;
70 // Test whether this is the identity transform
71 __CUDA_HD__
72 bool is_identity(void) const;
73 public:
74 // Transform = Ax + b
75 Transform<M,N,T> transform; // A
76 Point<M,T> offset; // b
77 };
78
91 template<int M, int N, typename T = coord_t>
93 private:
94 static_assert(M > 0, "M must be positive");
95 static_assert(M > 0, "N must be positive");
96 static_assert(std::is_integral<T>::value, "must be integral type");
97 public:
98 __CUDA_HD__
99 ScaleTransform(void); // default to identity transform
100 // allow type coercions where possible
101 template<typename T2> __CUDA_HD__
102 ScaleTransform(const ScaleTransform<M,N,T2> &rhs);
103 template<typename T2, typename T3, typename T4> __CUDA_HD__
104 ScaleTransform(const Transform<M,N,T2> transform,
105 const Rect<M,T3> extent,
106 const Point<M,T4> divisor);
107 public:
108 template<typename T2> __CUDA_HD__
109 ScaleTransform<M,N,T>& operator=(const ScaleTransform<M,N,T2> &rhs);
110 public:
111 // Apply the transformation to a point
112 template<typename T2> __CUDA_HD__
113 Rect<M,T> operator[](const Point<N,T2> point) const;
114 // Test whether this is the identity transform
115 __CUDA_HD__
116 bool is_identity(void) const;
117 public:
118 Transform<M,N,T> transform; // A
119 Rect<M,T> extent; // [b=lo, c=hi]
120 Point<M,T> divisor; // d
121 };
122
123 // If we've got c++11 we can just include this directly
124 template<int DIM, typename T = coord_t>
125 using DomainT = Realm::IndexSpace<DIM,T>;
126
133 public:
134 static constexpr int MAX_POINT_DIM = LEGION_MAX_DIM;
135
136 __CUDA_HD__
137 DomainPoint(void);
138 __CUDA_HD__
139 DomainPoint(coord_t index);
140 __CUDA_HD__
141 DomainPoint(const DomainPoint &rhs);
142 template<int DIM, typename T> __CUDA_HD__
143 DomainPoint(const Point<DIM,T> &rhs);
144
145 template<int DIM, typename T> __CUDA_HD__
146 operator Point<DIM,T>(void) const;
147
148 __CUDA_HD__
149 DomainPoint& operator=(const DomainPoint &rhs);
150 template<int DIM, typename T> __CUDA_HD__
151 DomainPoint& operator=(const Point<DIM,T> &rhs);
152 __CUDA_HD__
153 bool operator==(const DomainPoint &rhs) const;
154 __CUDA_HD__
155 bool operator!=(const DomainPoint &rhs) const;
156 __CUDA_HD__
157 bool operator<(const DomainPoint &rhs) const;
158
159 __CUDA_HD__
160 DomainPoint operator+(coord_t scalar) const;
161 __CUDA_HD__
162 DomainPoint operator+(const DomainPoint &rhs) const;
163 __CUDA_HD__
164 DomainPoint& operator+=(coord_t scalar);
165 __CUDA_HD__
166 DomainPoint& operator+=(const DomainPoint &rhs);
167
168 __CUDA_HD__
169 DomainPoint operator-(coord_t scalar) const;
170 __CUDA_HD__
171 DomainPoint operator-(const DomainPoint &rhs) const;
172 __CUDA_HD__
173 DomainPoint& operator-=(coord_t scalar);
174 __CUDA_HD__
175 DomainPoint& operator-=(const DomainPoint &rhs);
176
177 __CUDA_HD__
178 DomainPoint operator*(coord_t scalar) const;
179 __CUDA_HD__
180 DomainPoint operator*(const DomainPoint &rhs) const;
181 __CUDA_HD__
182 DomainPoint& operator*=(coord_t scalar);
183 __CUDA_HD__
184 DomainPoint& operator*=(const DomainPoint &rhs);
185
186 __CUDA_HD__
187 DomainPoint operator/(coord_t scalar) const;
188 __CUDA_HD__
189 DomainPoint operator/(const DomainPoint &rhs) const;
190 __CUDA_HD__
191 DomainPoint& operator/=(coord_t scalar);
192 __CUDA_HD__
193 DomainPoint& operator/=(const DomainPoint &rhs);
194
195 __CUDA_HD__
196 DomainPoint operator%(coord_t scalar) const;
197 __CUDA_HD__
198 DomainPoint operator%(const DomainPoint &rhs) const;
199 __CUDA_HD__
200 DomainPoint& operator%=(coord_t scalar);
201 __CUDA_HD__
202 DomainPoint& operator%=(const DomainPoint &rhs);
203
204 __CUDA_HD__
205 coord_t& operator[](unsigned index);
206 __CUDA_HD__
207 const coord_t& operator[](unsigned index) const;
208
210 __CUDA_HD__
211 bool operator()(const DomainPoint& a, const DomainPoint& b) const
212 {
213 if(a.dim < b.dim) return true;
214 if(a.dim > b.dim) return false;
215 for(int i = 0; (i == 0) || (i < a.dim); i++) {
216 if(a.point_data[i] < b.point_data[i]) return true;
217 if(a.point_data[i] > b.point_data[i]) return false;
218 }
219 return false;
220 }
221 };
222
223 __CUDA_HD__
224 Color get_color(void) const;
225 __CUDA_HD__
226 coord_t get_index(void) const;
227 __CUDA_HD__
228 int get_dim(void) const;
229 __CUDA_HD__
230 inline bool exists(void) const { return (get_dim() > 0); }
231
232 __CUDA_HD__
233 bool is_null(void) const;
234
235 __CUDA_HD__
236 static DomainPoint nil(void);
237
238 protected:
239 template<typename T> __CUDA_HD__
240 static inline coord_t check_for_overflow(const T &value);
241 public:
242 int dim;
243 coord_t point_data[MAX_POINT_DIM];
244
245 friend std::ostream& operator<<(std::ostream& os, const DomainPoint& dp);
246 };
247
253 class Domain {
254 public:
255 typedef ::realm_id_t IDType;
256 // Keep this in sync with legion_domain_max_rect_dim_t
257 // in legion_config.h
258 static constexpr int MAX_RECT_DIM = LEGION_MAX_DIM;
259 __CUDA_HD__
260 Domain(void);
261 __CUDA_HD__
262 Domain(const Domain& other);
263 __CUDA_HD__
264 Domain(Domain &&other) noexcept;
265 __CUDA_HD__
266 Domain(const DomainPoint &lo, const DomainPoint &hi);
267
268 template<int DIM, typename T> __CUDA_HD__
269 Domain(const Rect<DIM,T> &other);
270
271 template<int DIM, typename T> __CUDA_HD__
272 Domain(const DomainT<DIM,T> &other);
273
274 __CUDA_HD__
275 Domain& operator=(const Domain& other);
276 __CUDA_HD__
277 Domain& operator=(Domain &&other) noexcept;
278 template<int DIM, typename T> __CUDA_HD__
279 Domain& operator=(const Rect<DIM,T> &other);
280 template<int DIM, typename T> __CUDA_HD__
281 Domain& operator=(const DomainT<DIM,T> &other);
282
283 __CUDA_HD__
284 bool operator==(const Domain &rhs) const;
285 __CUDA_HD__
286 bool operator!=(const Domain &rhs) const;
287 __CUDA_HD__
288 bool operator<(const Domain &rhs) const;
289
290 __CUDA_HD__
291 Domain operator+(const DomainPoint &point) const;
292 __CUDA_HD__
293 Domain& operator+=(const DomainPoint &point);
294
295 __CUDA_HD__
296 Domain operator-(const DomainPoint &point) const;
297 __CUDA_HD__
298 Domain& operator-=(const DomainPoint &point);
299
300 static const Domain NO_DOMAIN;
301
302 __CUDA_HD__
303 bool exists(void) const;
304 __CUDA_HD__
305 bool dense(void) const;
306
307 template<int DIM, typename T> __CUDA_HD__
308 Rect<DIM,T> bounds(void) const;
309
310 template<int DIM, typename T> __CUDA_HD__
311 operator Rect<DIM,T>(void) const;
312
313 template<int DIM, typename T>
314 operator DomainT<DIM,T>(void) const;
315
316 // Only works for structured DomainPoint.
317 static Domain from_domain_point(const DomainPoint &p);
318
319 // No longer supported
320 //Realm::IndexSpace get_index_space(void) const;
321
322 __CUDA_HD__
323 bool is_valid(void) const;
324
325 bool contains(const DomainPoint &point) const;
326
327 // This will only check the bounds and not the sparsity map
328 __CUDA_HD__
329 bool contains_bounds_only(const DomainPoint &point) const;
330
331 __CUDA_HD__
332 int get_dim(void) const;
333
334 bool empty(void) const;
335
336 // Will destroy the underlying Realm index space
337 void destroy(Realm::Event wait_on = Realm::Event::NO_EVENT);
338
339 size_t get_volume(void) const;
340
341 __CUDA_HD__
342 DomainPoint lo(void) const;
343
344 __CUDA_HD__
345 DomainPoint hi(void) const;
346
347 // Intersects this Domain with another Domain and returns the result.
348 Domain intersection(const Domain &other) const;
349
350 // Returns the bounding box for this Domain and a point.
351 // WARNING: only works with structured Domain.
352 Domain convex_hull(const DomainPoint &p) const;
353
355 public:
356 DomainPointIterator(const Domain& d);
358
359 bool step(void);
360
361 operator bool(void) const;
362 DomainPoint& operator*(void);
363 DomainPointIterator& operator=(const DomainPointIterator &rhs);
364 DomainPointIterator& operator++(void);
365 DomainPointIterator operator++(int /*i am postfix*/);
366 public:
367 DomainPoint p;
368 // Realm's iterators are copyable by value so we can just always
369 // copy them in and out of some buffers
370 static_assert(std::is_trivially_copyable<
371 Realm::IndexSpaceIterator<MAX_RECT_DIM,coord_t> >::value);
372 static_assert(std::is_trivially_copyable<
373 Realm::PointInRectIterator<MAX_RECT_DIM,coord_t> >::value);
374 uint8_t is_iterator[
375 sizeof(Realm::IndexSpaceIterator<MAX_RECT_DIM,coord_t>)];
376 uint8_t rect_iterator[
377 sizeof(Realm::PointInRectIterator<MAX_RECT_DIM,coord_t>)];
378 TypeTag is_type;
379 bool is_valid, rect_valid;
380 };
381 protected:
382 public:
383 IDType is_id;
384 // For Realm index spaces we need to have a type tag to know
385 // what the type of the original sparsity map was
386 // Without it you can get undefined behavior trying to interpret
387 // the sparsity map incorrectly. This doesn't matter for the bounds
388 // data because we've done the conversion for ourselves.
389 // Technically this is redundant with the dimension since it also
390 // encodes the dimension, but we'll keep them separate for now for
391 // backwards compatibility
392 TypeTag is_type;
393#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__)
394 // Work around an internal nvcc bug by marking this volatile
395 volatile
396#endif
397 int dim;
398 coord_t rect_data[2 * MAX_RECT_DIM];
399 private:
400 // Helper functor classes for demux-ing templates when we have
401 // non-trivial sparsity maps with unusual types
402 // User's should never need to look at these hence they are private
403 template<typename T> __CUDA_HD__
404 static inline coord_t check_for_overflow(const T &value);
405 struct ContainsFunctor {
406 public:
407 ContainsFunctor(const Domain &d, const DomainPoint &p, bool &res)
408 : domain(d), point(p), result(res) { }
409 template<typename N, typename T>
410 static inline void demux(ContainsFunctor *functor)
411 {
412 DomainT<N::N,T> is = functor->domain;
413 Point<N::N,T> p = functor->point;
414 functor->result = is.contains(p);
415 }
416 public:
417 const Domain &domain;
418 const DomainPoint &point;
419 bool &result;
420 };
421 struct VolumeFunctor {
422 public:
423 VolumeFunctor(const Domain &d, size_t &r)
424 : domain(d), result(r) { }
425 template<typename N, typename T>
426 static inline void demux(VolumeFunctor *functor)
427 {
428 DomainT<N::N,T> is = functor->domain;
429 functor->result = is.volume();
430 }
431 public:
432 const Domain &domain;
433 size_t &result;
434 };
435 struct DestroyFunctor {
436 public:
437 DestroyFunctor(const Domain &d, Realm::Event e) : domain(d), event(e) { }
438 template<typename N, typename T>
439 static inline void demux(DestroyFunctor *functor)
440 {
441 DomainT<N::N,T> is = functor->domain;
442 is.destroy(functor->event);
443 }
444 public:
445 const Domain &domain;
446 const Realm::Event event;
447 };
448 struct IntersectionFunctor {
449 public:
450 IntersectionFunctor(const Domain &l, const Domain &r, Domain &res)
451 : lhs(l), rhs(r), result(res) { }
452 public:
453 template<typename N, typename T>
454 static inline void demux(IntersectionFunctor *functor)
455 {
456 DomainT<N::N,T> is1 = functor->lhs;
457 DomainT<N::N,T> is2 = functor->rhs;
458 assert(is1.dense() || is2.dense());
459 // Intersect the index spaces
460 DomainT<N::N,T> result;
461 result.bounds = is1.bounds.intersection(is2.bounds);
462 if (!result.bounds.empty())
463 {
464 if (!is1.dense())
465 result.sparsity = is1.sparsity;
466 else if (!is2.dense())
467 result.sparsity = is2.sparsity;
468 else
469 result.sparsity.id = 0;
470 }
471 else
472 result.sparsity.id = 0;
473 functor->result = Domain(result);
474 }
475 public:
476 const Domain &lhs;
477 const Domain &rhs;
478 Domain &result;
479 };
480 struct IteratorInitFunctor {
481 public:
482 IteratorInitFunctor(const Domain &d, DomainPointIterator &i)
483 : domain(d), iterator(i) { }
484 public:
485 template<typename N, typename T>
486 static inline void demux(IteratorInitFunctor *functor)
487 {
488 DomainT<N::N,T> is = functor->domain;
489 Realm::IndexSpaceIterator<N::N,T> is_itr(is);
490 static_assert(sizeof(is_itr) <=
491 sizeof(functor->iterator.is_iterator));
492 functor->iterator.is_valid = is_itr.valid;
493 if (is_itr.valid)
494 {
495 // Always use coord_t for the rect so we don't demux unnecessarily
496 Realm::Rect<N::N,coord_t> rect = is_itr.rect;
497 Realm::PointInRectIterator<N::N,coord_t> rect_itr(rect);
498 static_assert(sizeof(rect_itr) <=
499 sizeof(functor->iterator.rect_iterator));
500 assert(rect_itr.valid);
501 functor->iterator.rect_valid = true;
502 functor->iterator.p = rect_itr.p;
503 memcpy(functor->iterator.rect_iterator, &rect_itr, sizeof(rect_itr));
504 memcpy(functor->iterator.is_iterator, &is_itr, sizeof(is_itr));
505 }
506 else
507 functor->iterator.rect_valid = false;
508 }
509 public:
510 const Domain &domain;
511 DomainPointIterator &iterator;
512 };
513 struct IteratorStepFunctor {
514 public:
515 IteratorStepFunctor(DomainPointIterator &i)
516 : iterator(i) { }
517 public:
518 template<typename N, typename T>
519 static inline void demux(IteratorStepFunctor *functor)
520 {
521 // We already know the rect iterator is not valid here
522#ifdef DEBUG_LEGION
523 assert(!functor->iterator.rect_valid);
524#endif
525 Realm::IndexSpaceIterator<N::N,T> is_itr;
526 memcpy(&is_itr, functor->iterator.is_iterator, sizeof(is_itr));
527 is_itr.step(); \
528 functor->iterator.is_valid = is_itr.valid;
529 if (is_itr.valid)
530 {
531 // Convert to rect with coord_t
532 Realm::Rect<N::N,coord_t> rect = is_itr.rect;
533 Realm::PointInRectIterator<N::N,coord_t> new_rectitr(rect);
534#ifdef DEBUG_LEGION
535 assert(new_rectitr.valid);
536#endif
537 functor->iterator.rect_valid = true;
538 functor->iterator.p = new_rectitr.p;
539 memcpy(functor->iterator.rect_iterator, &new_rectitr,
540 sizeof(new_rectitr));
541 memcpy(functor->iterator.is_iterator, &is_itr, sizeof(is_itr));
542 }
543 }
544 public:
545 DomainPointIterator &iterator;
546 };
547 };
548
549 template<int DIM, typename COORD_T = coord_t>
551 private:
552 static_assert(DIM > 0, "DIM must be positive");
553 static_assert(std::is_integral<COORD_T>::value, "must be integral type");
554 public:
555 __CUDA_HD__
557 __CUDA_HD__
558 PointInRectIterator(const Rect<DIM,COORD_T> &r,
559 bool column_major_order = true);
560 public:
561 __CUDA_HD__
562 inline bool valid(void) const;
563 __CUDA_HD__
564 inline bool step(void);
565 public:
566 __CUDA_HD__
567 inline bool operator()(void) const;
568 __CUDA_HD__
569 inline Point<DIM,COORD_T> operator*(void) const;
570 __CUDA_HD__
571 inline COORD_T operator[](unsigned index) const;
572 __CUDA_HD__
573 inline const Point<DIM,COORD_T>* operator->(void) const;
574 __CUDA_HD__
575 inline PointInRectIterator<DIM,COORD_T>& operator++(void);
576 __CUDA_HD__
577 inline PointInRectIterator<DIM,COORD_T> operator++(int/*postfix*/);
578 protected:
579 Realm::PointInRectIterator<DIM,COORD_T> itr;
580 };
581
582 template<int DIM, typename COORD_T = coord_t>
584 private:
585 static_assert(DIM > 0, "DIM must be positive");
586 static_assert(std::is_integral<COORD_T>::value, "must be integral type");
587 public:
589 RectInDomainIterator(const DomainT<DIM,COORD_T> &d);
590 public:
591 inline bool valid(void) const;
592 inline bool step(void);
593 public:
594 inline bool operator()(void) const;
595 inline Rect<DIM,COORD_T> operator*(void) const;
596 inline const Rect<DIM,COORD_T>* operator->(void) const;
597 inline RectInDomainIterator<DIM,COORD_T>& operator++(void);
598 inline RectInDomainIterator<DIM,COORD_T> operator++(int/*postfix*/);
599 protected:
600 Realm::IndexSpaceIterator<DIM,COORD_T> itr;
601 };
602
603 template<int DIM, typename COORD_T = coord_t>
605 private:
606 static_assert(DIM > 0, "DIM must be positive");
607 static_assert(std::is_integral<COORD_T>::value, "must be integral type");
608 public:
610 PointInDomainIterator(const DomainT<DIM,COORD_T> &d,
611 bool column_major_order = true);
612 public:
613 inline bool valid(void) const;
614 inline bool step(void);
615 public:
616 inline bool operator()(void) const;
617 inline Point<DIM,COORD_T> operator*(void) const;
618 inline COORD_T operator[](unsigned index) const;
619 inline const Point<DIM,COORD_T>* operator->(void) const;
620 inline PointInDomainIterator& operator++(void);
621 inline PointInDomainIterator operator++(int /*postfix*/);
622 protected:
623 RectInDomainIterator<DIM,COORD_T> rect_itr;
624 PointInRectIterator<DIM,COORD_T> point_itr;
625 bool column_major;
626 };
627
634 public:
635 __CUDA_HD__
636 DomainTransform(void);
637 __CUDA_HD__
639 template<int M, int N, typename T> __CUDA_HD__
640 DomainTransform(const Transform<M,N,T> &rhs);
641 public:
642 __CUDA_HD__
643 DomainTransform& operator=(const DomainTransform &rhs);
644 template<int M, int N, typename T> __CUDA_HD__
645 DomainTransform& operator=(const Transform<M,N,T> &rhs);
646 __CUDA_HD__
647 bool operator==(const DomainTransform &rhs) const;
648 __CUDA_HD__
649 bool operator!=(const DomainTransform &rhs) const;
650 public:
651 template<int M, int N, typename T> __CUDA_HD__
652 operator Transform<M,N,T>(void) const;
653 public:
654 __CUDA_HD__
655 DomainPoint operator*(const DomainPoint &p) const;
656 __CUDA_HD__
657 Domain operator*(const Domain &domain) const;
658 __CUDA_HD__
659 DomainTransform operator*(const DomainTransform &transform) const;
660 public:
661 __CUDA_HD__
662 bool is_identity(void) const;
663 public:
664 int m, n;
665 coord_t matrix[LEGION_MAX_DIM * LEGION_MAX_DIM];
666 };
667
674 public:
675 __CUDA_HD__
677 __CUDA_HD__
679 __CUDA_HD__
681 template<int M, int N, typename T> __CUDA_HD__
682 DomainAffineTransform(const AffineTransform<M,N,T> &transform);
683 public:
684 __CUDA_HD__
685 DomainAffineTransform& operator=(const DomainAffineTransform &rhs);
686 template<int M, int N, typename T> __CUDA_HD__
687 DomainAffineTransform& operator=(const AffineTransform<M,N,T> &rhs);
688 __CUDA_HD__
689 bool operator==(const DomainAffineTransform &rhs) const;
690 __CUDA_HD__
691 bool operator!=(const DomainAffineTransform &rhs) const;
692 public:
693 template<int M, int N, typename T> __CUDA_HD__
694 operator AffineTransform<M,N,T>(void) const;
695 public:
696 // Apply the transformation to a point
697 __CUDA_HD__
698 DomainPoint operator[](const DomainPoint &p) const;
699 // Test for the identity
700 __CUDA_HD__
701 bool is_identity(void) const;
702 public:
703 DomainTransform transform;
704 DomainPoint offset;
705 };
706
713 public:
714 __CUDA_HD__
716 __CUDA_HD__
718 __CUDA_HD__
719 DomainScaleTransform(const DomainTransform &transform,
720 const Domain &extent, const DomainPoint &divisor);
721 template<int M, int N, typename T> __CUDA_HD__
722 DomainScaleTransform(const ScaleTransform<M,N,T> &transform);
723 public:
724 __CUDA_HD__
725 DomainScaleTransform& operator=(const DomainScaleTransform &rhs);
726 template<int M, int N, typename T> __CUDA_HD__
727 DomainScaleTransform& operator=(const ScaleTransform<M,N,T> &rhs);
728 __CUDA_HD__
729 bool operator==(const DomainScaleTransform &rhs) const;
730 __CUDA_HD__
731 bool operator!=(const DomainScaleTransform &rhs) const;
732 public:
733 template<int M, int N, typename T> __CUDA_HD__
734 operator ScaleTransform<M,N,T>(void) const;
735 public:
736 // Apply the transformation to a point
737 __CUDA_HD__
738 Domain operator[](const DomainPoint &p) const;
739 // Test for the identity
740 __CUDA_HD__
741 bool is_identity(void) const;
742 public:
743 DomainTransform transform;
744 Domain extent;
745 DomainPoint divisor;
746 };
747
756 template<typename FT, PrivilegeMode PM = LEGION_READ_WRITE>
757 class Span {
758 public:
759 class iterator {
760 public:
761 // explicitly set iterator traits
762 typedef std::random_access_iterator_tag iterator_category;
763 typedef FT value_type;
764 typedef std::ptrdiff_t difference_type;
765 typedef FT *pointer;
766 typedef FT& reference;
767
768 iterator(void) : ptr(NULL), stride(0) { }
769 private:
770 iterator(uint8_t *p, size_t s) : ptr(p), stride(s) { }
771 public:
772 inline iterator& operator=(const iterator &rhs)
773 { ptr = rhs.ptr; stride = rhs.stride; return *this; }
774 inline iterator& operator+=(int rhs) { ptr += stride; return *this; }
775 inline iterator& operator-=(int rhs) { ptr -= stride; return *this; }
776 inline FT& operator*(void) const
777 {
778 FT *result = NULL;
779 static_assert(sizeof(result) == sizeof(ptr));
780 memcpy(&result, &ptr, sizeof(result));
781 return *result;
782 }
783 inline FT* operator->(void) const
784 {
785 FT *result = NULL;
786 static_assert(sizeof(result) == sizeof(ptr));
787 memcpy(&result, &ptr, sizeof(result));
788 return result;
789 }
790 inline FT& operator[](int rhs) const
791 {
792 FT *result = NULL;
793 uint8_t *ptr2 = ptr + rhs * stride;
794 static_assert(sizeof(result) == sizeof(ptr2));
795 memcpy(&result, &ptr2, sizeof(result));
796 return *result;
797 }
798 public:
799 inline iterator& operator++(void) { ptr += stride; return *this; }
800 inline iterator& operator--(void) { ptr -= stride; return *this; }
801 inline iterator operator++(int)
802 { iterator it(ptr, stride); ptr += stride; return it; }
803 inline iterator operator--(int)
804 { iterator it(ptr, stride); ptr -= stride; return it; }
805 inline iterator operator+(int rhs) const
806 { return iterator(ptr + stride * rhs, stride); }
807 inline iterator operator-(int rhs) const
808 { return iterator(ptr - stride * rhs, stride); }
809 public:
810 inline bool operator==(const iterator &rhs) const
811 { return (ptr == rhs.ptr); }
812 inline bool operator!=(const iterator &rhs) const
813 { return (ptr != rhs.ptr); }
814 inline bool operator<(const iterator &rhs) const
815 { return (ptr < rhs.ptr); }
816 inline bool operator>(const iterator &rhs) const
817 { return (ptr > rhs.ptr); }
818 inline bool operator<=(const iterator &rhs) const
819 { return (ptr <= rhs.ptr); }
820 inline bool operator>=(const iterator &rhs) const
821 { return (ptr >= rhs.ptr); }
822 private:
823 uint8_t *ptr;
824 size_t stride;
825 };
827 public:
828 // explicitly set iterator traits
829 typedef std::random_access_iterator_tag iterator_category;
830 typedef FT value_type;
831 typedef std::ptrdiff_t difference_type;
832 typedef FT *pointer;
833 typedef FT& reference;
834
835 reverse_iterator(void) : ptr(NULL), stride(0) { }
836 private:
837 reverse_iterator(uint8_t *p, size_t s) : ptr(p), stride(s) { }
838 public:
839 inline reverse_iterator& operator=(const reverse_iterator &rhs)
840 { ptr = rhs.ptr; stride = rhs.stride; return *this; }
841 inline reverse_iterator& operator+=(int rhs)
842 { ptr -= stride; return *this; }
843 inline reverse_iterator& operator-=(int rhs)
844 { ptr += stride; return *this; }
845 inline FT& operator*(void) const
846 {
847 FT *result = NULL;
848 static_assert(sizeof(result) == sizeof(ptr));
849 memcpy(&result, &ptr, sizeof(result));
850 return *result;
851 }
852 inline FT* operator->(void) const
853 {
854 FT *result = NULL;
855 static_assert(sizeof(result) == sizeof(ptr));
856 memcpy(&result, &ptr, sizeof(result));
857 return result;
858 }
859 inline FT& operator[](int rhs) const
860 {
861 FT *result = NULL;
862 uint8_t *ptr2 = ptr - rhs * stride;
863 static_assert(sizeof(result) == sizeof(ptr2));
864 memcpy(&result, &ptr2, sizeof(result));
865 return *result;
866 }
867 public:
868 inline reverse_iterator& operator++(void)
869 { ptr -= stride; return *this; }
870 inline reverse_iterator& operator--(void)
871 { ptr += stride; return *this; }
872 inline reverse_iterator operator++(int)
873 { reverse_iterator it(ptr, stride); ptr -= stride; return it; }
874 inline reverse_iterator operator--(int)
875 { reverse_iterator it(ptr, stride); ptr += stride; return it; }
876 inline reverse_iterator operator+(int rhs) const
877 { return reverse_iterator(ptr - stride * rhs, stride); }
878 inline reverse_iterator operator-(int rhs) const
879 { return reverse_iterator(ptr + stride * rhs, stride); }
880 public:
881 inline bool operator==(const reverse_iterator &rhs) const
882 { return (ptr == rhs.ptr); }
883 inline bool operator!=(const reverse_iterator &rhs) const
884 { return (ptr != rhs.ptr); }
885 inline bool operator<(const reverse_iterator &rhs) const
886 { return (ptr > rhs.ptr); }
887 inline bool operator>(const reverse_iterator &rhs) const
888 { return (ptr < rhs.ptr); }
889 inline bool operator<=(const reverse_iterator &rhs) const
890 { return (ptr >= rhs.ptr); }
891 inline bool operator>=(const reverse_iterator &rhs) const
892 { return (ptr <= rhs.ptr); }
893 private:
894 uint8_t *ptr;
895 size_t stride;
896 };
897 public:
898 Span(void) : base(NULL), extent(0), stride(0) { }
899 Span(FT *b, size_t e, size_t s = sizeof(FT))
900 : base(NULL), extent(e), stride(s)
901 {
902 static_assert(sizeof(base) == sizeof(b));
903 memcpy(&base, &b, sizeof(base));
904 }
905 public:
906 inline iterator begin(void) const { return iterator(base, stride); }
907 inline iterator end(void) const
908 { return iterator(base + extent*stride, stride); }
909 inline reverse_iterator rbegin(void) const
910 { return reverse_iterator(base + (extent-1) * stride, stride); }
911 inline reverse_iterator rend(void) const
912 { return reverse_iterator(base - stride, stride); }
913 public:
914 inline FT& front(void) const
915 {
916 FT *result = NULL;
917 static_assert(sizeof(result) == sizeof(base));
918 memcpy(&result, &base, sizeof(result));
919 return *result;
920 }
921 inline FT& back(void) const
922 {
923 FT *result = NULL;
924 uint8_t *ptr = base + (extent-1)*stride;
925 static_assert(sizeof(result) == sizeof(ptr));
926 memcpy(&result, &ptr, sizeof(result));
927 return *result;
928 }
929 inline FT& operator[](int index) const
930 {
931 FT *result = NULL;
932 uint8_t *ptr = base + index * stride;
933 static_assert(sizeof(result) == sizeof(ptr));
934 memcpy(&result, &ptr, sizeof(result));
935 return *result;
936 }
937 inline FT* data(void) const
938 {
939 FT *result = NULL;
940 static_assert(sizeof(result) == sizeof(base));
941 memcpy(&result, &base, sizeof(result));
942 return result;
943 }
944 inline uintptr_t get_base(void) const { return uintptr_t(base); }
945 public:
946 inline size_t size(void) const { return extent; }
947 inline size_t step(void) const { return stride; }
948 inline bool empty(void) const { return (extent == 0); }
949 private:
950 uint8_t *base;
951 size_t extent; // number of elements
952 size_t stride; // byte stride
953 };
954
955}; // namespace Legion
956
957#include "legion/legion_domain.inl"
958
959#endif // __LEGION_DOMAIN_H__
960
Definition legion_domain.h:354
Definition legion_domain.h:673
Definition legion_domain.h:253
Definition legion_domain.h:132
Definition legion_domain.h:712
Definition legion_domain.h:633
Definition legion_domain.h:604
Definition legion_domain.h:550
Definition legion_domain.h:583
Definition legion_domain.h:759
Definition legion_domain.h:826
Definition legion_domain.h:757
Definition legion_domain.h:46
Definition legion_domain.h:209
Definition legion_domain.h:92