Legion Runtime
legion_c_util.h
Go to the documentation of this file.
1 /* Copyright 2024 Stanford University
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 
17 #ifndef __LEGION_C_UTIL_H__
18 #define __LEGION_C_UTIL_H__
19 
25 #include "legion.h"
26 #include "legion/legion_c.h"
27 #include "legion/legion_mapping.h"
28 #include "mappers/mapping_utilities.h"
29 
30 #include <stdlib.h>
31 #include <string.h>
32 #include <algorithm>
33 
34 static inline bool operator<(const legion_ptr_t &lhs, const legion_ptr_t &rhs)
35 { return lhs.value < rhs.value; }
36 
37 namespace Legion {
38 
39  class CContext;
40  class TaskMut;
41 
42  struct ColoredPoints {
43  public:
44  std::set<legion_ptr_t> points;
45  std::set<std::pair<legion_ptr_t,legion_ptr_t> > ranges;
46  };
47  typedef std::map<Color,ColoredPoints> Coloring;
48  typedef std::map<Color,Domain> DomainColoring;
49  typedef std::map<DomainPoint,ColoredPoints> PointColoring;
50  typedef std::map<DomainPoint,Domain> DomainPointColoring;
51  typedef std::map<DomainPoint,std::set<Domain> > MultiDomainPointColoring;
52 
54  public:
55 #define ARRAY_ACCESSOR(DIM) \
56  typedef Legion::UnsafeFieldAccessor<char,DIM,coord_t, \
57  Realm::AffineAccessor<char,DIM,coord_t> > ArrayAccessor##DIM##D;
58  LEGION_FOREACH_N(ARRAY_ACCESSOR)
59 #undef ARRAY_ACCESSOR
60 
61 #define RECT_ITERATOR(DIM) \
62  typedef RectInDomainIterator<DIM,coord_t> RectInDomainIterator##DIM##D;
63  LEGION_FOREACH_N(RECT_ITERATOR)
64 #undef RECT_ITERATOR
65 
66 #define BUFFER_CHAR(DIM) \
67  typedef DeferredBuffer<char,DIM> DeferredBufferChar##DIM##D;
68  LEGION_FOREACH_N(BUFFER_CHAR)
69 #undef BUFFER_CHAR
70 
71 #ifdef __ICC
72 // icpc complains about "error #858: type qualifier on return type is meaningless"
73 // but it's pretty annoying to get this macro to handle all the cases right
74 #pragma warning (push)
75 #pragma warning (disable: 858)
76 #endif
77 #ifdef __PGIC__
78 #pragma warning (push)
79 #pragma diag_suppress 191
80 #pragma diag_suppress 816
81 #endif
82 #define NEW_OPAQUE_WRAPPER(T_, T) \
83  static T_ wrap(T t) { \
84  T_ t_; \
85  t_.impl = static_cast<void *>(t); \
86  return t_; \
87  } \
88  static const T_ wrap_const(const T t) { \
89  T_ t_; \
90  t_.impl = const_cast<void *>(static_cast<const void *>(t)); \
91  return t_; \
92  } \
93  static T unwrap(T_ t_) { \
94  return static_cast<T>(t_.impl); \
95  } \
96  static const T unwrap_const(const T_ t_) { \
97  return static_cast<const T>(t_.impl); \
98  }
99 
100  NEW_OPAQUE_WRAPPER(legion_runtime_t, Runtime *);
101  NEW_OPAQUE_WRAPPER(legion_context_t, CContext *);
102  NEW_OPAQUE_WRAPPER(legion_domain_point_iterator_t, Domain::DomainPointIterator *);
103 #define RECT_ITERATOR(DIM) \
104  NEW_OPAQUE_WRAPPER(legion_rect_in_domain_iterator_##DIM##d_t, RectInDomainIterator##DIM##D *);
105  LEGION_FOREACH_N(RECT_ITERATOR)
106 #undef RECT_ITERATOR
107  NEW_OPAQUE_WRAPPER(legion_coloring_t, Coloring *);
108  NEW_OPAQUE_WRAPPER(legion_domain_coloring_t, DomainColoring *);
109  NEW_OPAQUE_WRAPPER(legion_point_coloring_t, PointColoring *);
110  NEW_OPAQUE_WRAPPER(legion_domain_point_coloring_t, DomainPointColoring *);
111  NEW_OPAQUE_WRAPPER(legion_multi_domain_point_coloring_t, MultiDomainPointColoring *);
112  NEW_OPAQUE_WRAPPER(legion_index_space_allocator_t, IndexSpaceAllocator *);
113  NEW_OPAQUE_WRAPPER(legion_field_allocator_t, FieldAllocator *);
114  NEW_OPAQUE_WRAPPER(legion_argument_map_t, ArgumentMap *);
115  NEW_OPAQUE_WRAPPER(legion_predicate_t, Predicate *);
116  NEW_OPAQUE_WRAPPER(legion_future_t, Future *);
117  NEW_OPAQUE_WRAPPER(legion_future_map_t, FutureMap *);
118 #define BUFFER_CHAR(DIM) \
119  NEW_OPAQUE_WRAPPER(legion_deferred_buffer_char_##DIM##d_t, DeferredBufferChar##DIM##D *);
120  LEGION_FOREACH_N(BUFFER_CHAR)
121 #undef BUFFER_CHAR
122  NEW_OPAQUE_WRAPPER(legion_task_launcher_t, TaskLauncher *);
123  NEW_OPAQUE_WRAPPER(legion_index_launcher_t, IndexTaskLauncher *);
124  NEW_OPAQUE_WRAPPER(legion_inline_launcher_t, InlineLauncher *);
125  NEW_OPAQUE_WRAPPER(legion_copy_launcher_t, CopyLauncher *);
126  NEW_OPAQUE_WRAPPER(legion_index_copy_launcher_t, IndexCopyLauncher *);
127  NEW_OPAQUE_WRAPPER(legion_fill_launcher_t, FillLauncher *);
128  NEW_OPAQUE_WRAPPER(legion_index_fill_launcher_t, IndexFillLauncher *);
129  NEW_OPAQUE_WRAPPER(legion_discard_launcher_t, DiscardLauncher *);
130  NEW_OPAQUE_WRAPPER(legion_acquire_launcher_t, AcquireLauncher *);
131  NEW_OPAQUE_WRAPPER(legion_release_launcher_t, ReleaseLauncher *);
132  NEW_OPAQUE_WRAPPER(legion_attach_launcher_t, AttachLauncher *);
133  NEW_OPAQUE_WRAPPER(legion_index_attach_launcher_t, IndexAttachLauncher *);
134  NEW_OPAQUE_WRAPPER(legion_must_epoch_launcher_t, MustEpochLauncher *);
135  NEW_OPAQUE_WRAPPER(legion_physical_region_t, PhysicalRegion *);
136  NEW_OPAQUE_WRAPPER(legion_external_resources_t, ExternalResources *);
137 #define ACCESSOR_ARRAY(DIM) \
138  NEW_OPAQUE_WRAPPER(legion_accessor_array_##DIM##d_t, ArrayAccessor##DIM##D *);
139  LEGION_FOREACH_N(ACCESSOR_ARRAY)
140 #undef ACCESSOR_ARRAY
141  NEW_OPAQUE_WRAPPER(legion_task_t, Task *);
142  NEW_OPAQUE_WRAPPER(legion_task_mut_t, TaskMut *);
143  NEW_OPAQUE_WRAPPER(legion_copy_t, Copy *);
144  NEW_OPAQUE_WRAPPER(legion_fill_t, Fill *);
145  NEW_OPAQUE_WRAPPER(legion_inline_t, InlineMapping *);
146  NEW_OPAQUE_WRAPPER(legion_mappable_t, Mappable *);
147  NEW_OPAQUE_WRAPPER(legion_region_requirement_t , RegionRequirement *);
148  NEW_OPAQUE_WRAPPER(legion_output_requirement_t , OutputRequirement *);
149  NEW_OPAQUE_WRAPPER(legion_machine_t, Machine *);
150  NEW_OPAQUE_WRAPPER(legion_logger_t, Realm::Logger *);
151  NEW_OPAQUE_WRAPPER(legion_mapper_t, Mapping::Mapper *);
152  NEW_OPAQUE_WRAPPER(legion_processor_query_t, Machine::ProcessorQuery *);
153  NEW_OPAQUE_WRAPPER(legion_memory_query_t, Machine::MemoryQuery *);
154  NEW_OPAQUE_WRAPPER(legion_machine_query_interface_t,
155  Mapping::Utilities::MachineQueryInterface *);
156  NEW_OPAQUE_WRAPPER(legion_default_mapper_t, Mapping::DefaultMapper *);
157  NEW_OPAQUE_WRAPPER(legion_execution_constraint_set_t, ExecutionConstraintSet *);
158  NEW_OPAQUE_WRAPPER(legion_layout_constraint_set_t, LayoutConstraintSet *);
159  NEW_OPAQUE_WRAPPER(legion_task_layout_constraint_set_t, TaskLayoutConstraintSet *);
160  NEW_OPAQUE_WRAPPER(legion_map_task_input_t, Mapping::Mapper::MapTaskInput *);
161  NEW_OPAQUE_WRAPPER(legion_map_task_output_t, Mapping::Mapper::MapTaskOutput *);
162  NEW_OPAQUE_WRAPPER(legion_slice_task_output_t, Mapping::Mapper::SliceTaskOutput *);
163  NEW_OPAQUE_WRAPPER(legion_physical_instance_t, Mapping::PhysicalInstance *);
164  NEW_OPAQUE_WRAPPER(legion_mapper_runtime_t, Mapping::MapperRuntime *);
165  // nvcc wrongly complains about a meaningless qualifer on the return type,
166  // probably due to it not chasing the typedefs when doing the check.
167  // here we inline the type alias to suppress the warning
168  NEW_OPAQUE_WRAPPER(legion_mapper_context_t, Internal::MappingCallInfo *);
169  typedef std::map<FieldID, const char *> FieldMap;
170  NEW_OPAQUE_WRAPPER(legion_field_map_t, FieldMap *);
171  NEW_OPAQUE_WRAPPER(legion_point_transform_functor_t, PointTransformFunctor *);
172 #undef NEW_OPAQUE_WRAPPER
173 #ifdef __ICC
174 // icpc complains about "error #858: type qualifier on return type is meaningless"
175 // but it's pretty annoying to get this macro to handle all the cases right
176 #pragma warning (pop)
177 #endif
178 #ifdef __PGIC__
179 #pragma warning (pop)
180 #endif
181 
182 #define NEW_POINT_WRAPPER(DIM) \
183  typedef Point<DIM,coord_t> Point##DIM##D; \
184  static legion_point_##DIM##d_t wrap(Point##DIM##D t) { \
185  legion_point_##DIM##d_t t_; \
186  for (int i = 0; i < DIM; i++) \
187  t_.x[i] = t[i]; \
188  return t_; \
189  } \
190  static Point##DIM##D unwrap(legion_point_##DIM##d_t t_) { \
191  Point##DIM##D t; \
192  for (int i = 0; i < DIM; i++) \
193  t[i] = t_.x[i]; \
194  return t; \
195  }
196  LEGION_FOREACH_N(NEW_POINT_WRAPPER)
197 #undef NEW_POINT_WRAPPER
198 
199 #define NEW_RECT_WRAPPER(DIM) \
200  typedef Rect<DIM,coord_t> Rect##DIM##D; \
201  static legion_rect_##DIM##d_t wrap(Rect##DIM##D t) { \
202  legion_rect_##DIM##d_t t_; \
203  t_.lo = wrap(Point##DIM##D(t.lo)); \
204  t_.hi = wrap(Point##DIM##D(t.hi)); \
205  return t_; \
206  } \
207  static Rect##DIM##D unwrap(legion_rect_##DIM##d_t t_) { \
208  Rect##DIM##D t(unwrap(t_.lo), unwrap(t_.hi)); \
209  return t; \
210  }
211  LEGION_FOREACH_N(NEW_RECT_WRAPPER)
212 #undef NEW_RECT_WRAPPER
213 
214 #define NEW_BLOCKIFY_WRAPPER(DIM) \
215  static Blockify<DIM> unwrap(legion_blockify_##DIM##d_t t_) { \
216  Blockify<DIM> t(unwrap(t_.block_size), unwrap(t_.offset)); \
217  return t; \
218  }
219  template<int DIM>
220  struct Blockify {
221  public:
222  Blockify(Point<DIM,coord_t> b,
223  Point<DIM,coord_t> o)
224  : block_size(b), offset(o) { }
225  public:
226  Point<DIM,coord_t> block_size, offset;
227  };
228  LEGION_FOREACH_N(NEW_BLOCKIFY_WRAPPER)
229 #undef NEW_BLOCKIFY_WRAPPER
230 
231 #define NEW_TRANSFORM_WRAPPER(D1,D2) \
232  typedef Transform<D1,D2,coord_t> Transform##D1##x##D2; \
233  static legion_transform_##D1##x##D2##_t wrap(Transform##D1##x##D2 t) { \
234  legion_transform_##D1##x##D2##_t t_; \
235  for (int i = 0; i < D1; i++) \
236  for (int j = 0; j < D2; j++) \
237  t_.trans[i][j] = t[i][j]; \
238  return t_; \
239  } \
240  static Transform##D1##x##D2 unwrap(legion_transform_##D1##x##D2##_t t_) { \
241  Transform##D1##x##D2 t; \
242  for (int i = 0; i < D1; i++) \
243  for (int j = 0; j < D2; j++) \
244  t[i][j] = t_.trans[i][j]; \
245  return t; \
246  }
247  LEGION_FOREACH_NN(NEW_TRANSFORM_WRAPPER)
248 #undef NEW_TRANSFORM_WRAPPER
249 
250 #define NEW_AFFINE_TRANSFORM_WRAPPER(D1,D2) \
251  typedef AffineTransform<D1,D2,coord_t> AffineTransform##D1##x##D2; \
252  static legion_affine_transform_##D1##x##D2##_t wrap(AffineTransform##D1##x##D2 t) { \
253  legion_affine_transform_##D1##x##D2##_t t_; \
254  t_.transform = wrap(t.transform); \
255  t_.offset = wrap(t.offset); \
256  return t_; \
257  } \
258  static AffineTransform##D1##x##D2 unwrap(legion_affine_transform_##D1##x##D2##_t t_) { \
259  AffineTransform##D1##x##D2 t; \
260  t.transform = unwrap(t_.transform); \
261  t.offset = unwrap(t_.offset); \
262  return t; \
263  }
264  LEGION_FOREACH_NN(NEW_AFFINE_TRANSFORM_WRAPPER)
265 #undef NEW_AFFINE_TRANSFORM_WRAPPER
266 
267  static legion_domain_t
268  wrap(Domain domain) {
269  legion_domain_t domain_;
270  domain_.is_id = domain.is_id;
271  domain_.is_type = domain.is_type;
272  domain_.dim = domain.dim;
273  std::copy(domain.rect_data, domain.rect_data + 2 * LEGION_MAX_DIM, domain_.rect_data);
274  return domain_;
275  }
276 
277  static Domain
278  unwrap(legion_domain_t domain_) {
279  Domain domain;
280  domain.is_id = domain_.is_id;
281  domain.is_type = domain_.is_type;
282  domain.dim = domain_.dim;
283  std::copy(domain_.rect_data, domain_.rect_data + 2 * LEGION_MAX_DIM, domain.rect_data);
284  return domain;
285  }
286 
287  static legion_domain_point_t
288  wrap(DomainPoint dp) {
290  dp_.dim = dp.dim;
291  std::copy(dp.point_data, dp.point_data + LEGION_MAX_DIM, dp_.point_data);
292  return dp_;
293  }
294 
295  static DomainPoint
296  unwrap(legion_domain_point_t dp_) {
297  DomainPoint dp;
298  dp.dim = dp_.dim;
299  std::copy(dp_.point_data, dp_.point_data + LEGION_MAX_DIM, dp.point_data);
300  return dp;
301  }
302 
304  wrap(DomainTransform transform) {
305  legion_domain_transform_t transform_;
306  transform_.m = transform.m;
307  transform_.n = transform.n;
308  std::copy(transform.matrix, transform.matrix + LEGION_MAX_DIM * LEGION_MAX_DIM, transform_.matrix);
309  return transform_;
310  }
311 
312  static DomainTransform
313  unwrap(legion_domain_transform_t transform_) {
314  DomainTransform transform;
315  transform.m = transform_.m;
316  transform.n = transform_.n;
317  std::copy(transform_.matrix, transform_.matrix + LEGION_MAX_DIM * LEGION_MAX_DIM, transform.matrix);
318  return transform;
319  }
320 
322  wrap(DomainAffineTransform transform) {
324  transform_.transform = wrap(transform.transform);
325  transform_.offset = wrap(transform.offset);
326  return transform_;
327  }
328 
329  static DomainAffineTransform
330  unwrap(legion_domain_affine_transform_t transform_) {
331  DomainAffineTransform transform;
332  transform.transform = unwrap(transform_.transform);
333  transform.offset = unwrap(transform_.offset);
334  return transform;
335  }
336 
337  static legion_index_space_t
338  wrap(IndexSpace is)
339  {
341  is_.id = is.id;
342  is_.tid = is.tid;
343  is_.type_tag = is.type_tag;
344  return is_;
345  }
346 
347  static IndexSpace
348  unwrap(legion_index_space_t is_)
349  {
350  IndexSpace is;
351  is.id = is_.id;
352  is.tid = is_.tid;
353  is.type_tag = is_.type_tag;
354  return is;
355  }
356 
358  wrap(IndexPartition ip)
359  {
361  ip_.id = ip.id;
362  ip_.tid = ip.tid;
363  ip_.type_tag = ip.type_tag;
364  return ip_;
365  }
366 
367  static IndexPartition
368  unwrap(legion_index_partition_t ip_)
369  {
370  IndexPartition ip;
371  ip.id = ip_.id;
372  ip.tid = ip_.tid;
373  ip.type_tag = ip_.type_tag;
374  return ip;
375  }
376 
377  static legion_field_space_t
378  wrap(FieldSpace fs)
379  {
381  fs_.id = fs.id;
382  return fs_;
383  }
384 
385  static FieldSpace
386  unwrap(legion_field_space_t fs_)
387  {
388  FieldSpace fs(fs_.id);
389  return fs;
390  }
391 
393  wrap(LogicalRegion r)
394  {
396  r_.tree_id = r.tree_id;
397  r_.index_space = wrap(r.index_space);
398  r_.field_space = wrap(r.field_space);
399  return r_;
400  }
401 
402  static LogicalRegion
403  unwrap(legion_logical_region_t r_)
404  {
405  LogicalRegion r(r_.tree_id,
406  unwrap(r_.index_space),
407  unwrap(r_.field_space));
408  return r;
409  }
410 
412  wrap(LogicalPartition r)
413  {
415  r_.tree_id = r.tree_id;
416  r_.index_partition = wrap(r.index_partition);
417  r_.field_space = wrap(r.field_space);
418  return r_;
419  }
420 
421  static LogicalPartition
422  unwrap(legion_logical_partition_t r_)
423  {
424  LogicalPartition r(r_.tree_id,
425  unwrap(r_.index_partition),
426  unwrap(r_.field_space));
427  return r;
428  }
429 
431  wrap(UntypedBuffer arg)
432  {
434  arg_.args = arg.get_ptr();
435  arg_.arglen = arg.get_size();
436  return arg_;
437  }
438 
439  static UntypedBuffer
440  unwrap(legion_untyped_buffer_t arg_)
441  {
442  return UntypedBuffer(arg_.args, arg_.arglen);
443  }
444 
445  static const legion_byte_offset_t
446  wrap(const ptrdiff_t offset)
447  {
448  legion_byte_offset_t offset_;
449  offset_.offset = offset;
450  return offset_;
451  }
452 
453  static ptrdiff_t
454  unwrap(const legion_byte_offset_t offset_)
455  {
456  return offset_.offset;
457  }
458 
459  static const legion_input_args_t
460  wrap_const(const InputArgs arg)
461  {
462  legion_input_args_t arg_;
463  arg_.argv = arg.argv;
464  arg_.argc = arg.argc;
465  return arg_;
466  }
467 
468  static const InputArgs
469  unwrap_const(const legion_input_args_t args_)
470  {
471  InputArgs args;
472  args.argv = args_.argv;
473  args.argc = args_.argc;
474  return args;
475  }
476 
478  wrap(TaskConfigOptions options)
479  {
481  options_.leaf = options.leaf;
482  options_.inner = options.inner;
483  options_.idempotent = options.idempotent;
484  return options_;
485  }
486 
487  static TaskConfigOptions
488  unwrap(legion_task_config_options_t options_)
489  {
490  TaskConfigOptions options(options_.leaf,
491  options_.inner,
492  options_.idempotent);
493  return options;
494  }
495 
496  static legion_processor_t
497  wrap(Processor proc)
498  {
499  legion_processor_t proc_;
500  proc_.id = proc.id;
501  return proc_;
502  }
503 
504  static Processor
505  unwrap(legion_processor_t proc_)
506  {
507  Processor proc;
508  proc.id = proc_.id;
509  return proc;
510  }
511 
512  static legion_processor_kind_t
513  wrap(Processor::Kind options)
514  {
515  return static_cast<legion_processor_kind_t>(options);
516  }
517 
518  static Processor::Kind
519  unwrap(legion_processor_kind_t options_)
520  {
521  return static_cast<Processor::Kind>(options_);
522  }
523 
524  static legion_memory_t
525  wrap(Memory mem)
526  {
527  legion_memory_t mem_;
528  mem_.id = mem.id;
529  return mem_;
530  }
531 
532  static Memory
533  unwrap(legion_memory_t mem_)
534  {
535  Memory mem;
536  mem.id = mem_.id;
537  return mem;
538  }
539 
540  static legion_memory_kind_t
541  wrap(Memory::Kind options)
542  {
543  return static_cast<legion_memory_kind_t>(options);
544  }
545 
546  static Memory::Kind
547  unwrap(legion_memory_kind_t options_)
548  {
549  return static_cast<Memory::Kind>(options_);
550  }
551 
552  static legion_task_slice_t
553  wrap(Mapping::Mapper::TaskSlice task_slice) {
554  legion_task_slice_t task_slice_;
555  task_slice_.domain = wrap(task_slice.domain);
556  task_slice_.proc = wrap(task_slice.proc);
557  task_slice_.recurse = task_slice.recurse;
558  task_slice_.stealable = task_slice.stealable;
559  return task_slice_;
560  }
561 
562  static Mapping::Mapper::TaskSlice
563  unwrap(legion_task_slice_t task_slice_) {
564  Mapping::Mapper::TaskSlice task_slice;
565  task_slice.domain = unwrap(task_slice_.domain);
566  task_slice.proc = unwrap(task_slice_.proc);
567  task_slice.recurse = task_slice_.recurse;
568  task_slice.stealable = task_slice_.stealable;
569  return task_slice;
570  }
571 
573  wrap(PhaseBarrier barrier) {
574  legion_phase_barrier_t barrier_;
575  barrier_.id = barrier.get_barrier().id;
576  barrier_.timestamp = barrier.get_barrier().timestamp;
577  return barrier_;
578  }
579 
580  static PhaseBarrier
581  unwrap(legion_phase_barrier_t barrier_) {
582  PhaseBarrier barrier;
583  barrier.phase_barrier.id = barrier_.id;
584  barrier.phase_barrier.timestamp = barrier_.timestamp;
585  return barrier;
586  }
587 
589  wrap(DynamicCollective collective) {
590  legion_dynamic_collective_t collective_;
591  collective_.id = collective.get_barrier().id;
592  collective_.timestamp = collective.get_barrier().timestamp;
593  collective_.redop = collective.redop;
594  return collective_;
595  }
596 
597  static DynamicCollective
598  unwrap(legion_dynamic_collective_t collective_) {
599  DynamicCollective collective;
600  collective.phase_barrier.id = collective_.id;
601  collective.phase_barrier.timestamp = collective_.timestamp;
602  collective.redop = collective_.redop;
603  return collective;
604  }
605 
606  static legion_task_options_t
607  wrap(Mapping::Mapper::TaskOptions& options) {
608  legion_task_options_t options_;
609  options_.initial_proc = CObjectWrapper::wrap(options.initial_proc);
610  options_.inline_task = options.inline_task;
611  options_.stealable = options.stealable;
612  options_.map_locally = options.map_locally;
613  options_.valid_instances = options.valid_instances;
614  options_.memoize = options.memoize;
615  options_.replicate = options.replicate;
616  options_.parent_priority = options.parent_priority;
617  return options_;
618  }
619 
620  static Mapping::Mapper::TaskOptions
621  unwrap(legion_task_options_t& options_) {
622  Mapping::Mapper::TaskOptions options;
623  options.initial_proc = CObjectWrapper::unwrap(options_.initial_proc);
624  options.inline_task = options_.inline_task;
625  options.stealable = options_.stealable;
626  options.map_locally = options_.map_locally;
627  options.valid_instances = options_.valid_instances;
628  options.memoize = options_.memoize;
629  options.replicate = options_.replicate;
630  options.parent_priority = options_.parent_priority;
631  return options;
632  }
633 
635  wrap(Mapping::Mapper::SliceTaskInput& input) {
637  input_.domain = CObjectWrapper::wrap(input.domain);
638  return input_;
639  }
640 
642  wrap_const(const Mapping::Mapper::SliceTaskInput& input) {
644  input_.domain = CObjectWrapper::wrap(input.domain);
645  return input_;
646  }
647 
648  static Mapping::Mapper::SliceTaskInput
649  unwrap(legion_slice_task_input_t& input_) {
650  Mapping::Mapper::SliceTaskInput input;
651  input.domain = CObjectWrapper::unwrap(input_.domain);
652  return input;
653  }
654  };
655 
656  class CContext {
657  public:
658  CContext(Context _ctx)
659  : ctx(_ctx)
660  {}
661 
662  CContext(Context _ctx, const std::vector<PhysicalRegion>& _physical_regions)
663  : ctx(_ctx)
664  , physical_regions(_physical_regions.size())
665  {
666  for (size_t i = 0; i < _physical_regions.size(); i++) {
667  physical_regions[i] =
668  CObjectWrapper::wrap(new PhysicalRegion(_physical_regions[i]));
669  }
670  }
671 
672  ~CContext(void)
673  {
674  for (size_t i = 0; i < physical_regions.size(); i++) {
675  delete CObjectWrapper::unwrap(physical_regions[i]);
676  }
677  }
678 
679  Context context(void) const
680  {
681  return ctx;
682  }
683 
684  const legion_physical_region_t *regions(void) const
685  {
686  if(physical_regions.empty())
687  return 0;
688  else
689  return &physical_regions[0];
690  }
691 
692  size_t num_regions(void) const
693  {
694  return physical_regions.size();
695  }
696 
697  protected:
698  Context ctx;
699  std::vector<legion_physical_region_t> physical_regions;
700  };
701 
702  class TaskMut : public Task {
703  public:
704  virtual ~TaskMut() {}
705  virtual UniqueID get_unique_id(void) const {
706  assert(false);
707  return 0;
708  }
709  virtual uint64_t get_context_index(void) const {
710  assert(false);
711  return 0;
712  }
713  virtual int get_depth(void) const {
714  assert(false);
715  return 0;
716  }
717  virtual const Task* get_parent_task(void) const {
718  assert(false);
719  return NULL;
720  }
721  virtual const std::string& get_provenance_string(bool human=true) const {
722  assert(false);
723  return (*new std::string());
724  }
725  virtual bool has_parent_task(void) const {
726  assert(false);
727  return false;
728  }
729  virtual const char* get_task_name(void) const {
730  assert(false);
731  return NULL;
732  }
733  virtual Domain get_slice_domain(void) const {
734  assert(false);
735  return Domain::NO_DOMAIN;
736  }
737  virtual ShardID get_shard_id(void) const {
738  assert(false);
739  return 0;
740  }
741  virtual size_t get_total_shards(void) const {
742  assert(false);
743  return 1;
744  };
745  virtual DomainPoint get_shard_point(void) const {
746  assert(false);
747  return DomainPoint();
748  };
749  virtual Domain get_shard_domain(void) const {
750  assert(false);
751  return Domain();
752  }
753  };
754 };
755 
756 #endif // __LEGION_C_UTIL_H__
Definition: legion.h:552
Definition: legion_c_util.h:656
Definition: legion_c_util.h:53
Definition: legion.h:4401
Definition: legion_domain.h:351
Definition: legion_domain.h:253
Definition: legion_domain.h:132
Definition: legion.h:2683
Definition: legion.h:373
Definition: legion.h:4518
Definition: legion.h:1172
Definition: legion.h:1374
Definition: legion.h:4430
Definition: legion.h:4259
Definition: legion.h:2537
Definition: legion.h:4968
Definition: legion.h:645
Definition: legion.h:5008
Definition: legion.h:4330
Definition: legion_c_util.h:702
#define ACCESSOR_ARRAY(DIM)
Definition: legion_c.h:5193
Definition: legion.h:3999
Definition: legion.h:2188
Definition: legion_c_util.h:220
Definition: legion_c_util.h:42
Definition: legion.h:1811
Definition: legion.h:2147
Definition: legion.h:1980
Definition: legion.h:2280
Definition: legion.h:1892
Definition: legion.h:2040
Definition: legion.h:1626
Definition: legion.h:1751
Definition: legion.h:4106
Definition: legion.h:1067
Definition: legion.h:864
Definition: legion.h:4047
Definition: legion.h:1523
Definition: legion_c.h:299
Definition: legion_c.h:240
Definition: legion_c.h:195
Definition: legion_c.h:156
Definition: legion_c.h:203
Definition: legion_c.h:358
Definition: legion_c.h:266
Definition: legion_c.h:257
Definition: legion_c.h:248
Definition: legion_c.h:306
Definition: legion_c.h:282
Definition: legion_c.h:273
Definition: legion_c.h:331
Definition: legion_c.h:348
Definition: legion_c.h:324
Definition: legion_c.h:122
Definition: legion_c.h:382
Definition: legion_c.h:314
Definition: legion_c.h:371
Definition: legion_c.h:338
Definition: legion_c.h:291