Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
partitions.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// index space partitioning for Realm
19
20#ifndef REALM_PARTITIONS_H
21#define REALM_PARTITIONS_H
22
23#include "realm/indexspace.h"
24#include "realm/sparsity.h"
25#include "realm/activemsg.h"
26#include "realm/id.h"
27#include "realm/operation.h"
28#include "realm/threads.h"
29#include "realm/cmdline.h"
30#include "realm/pri_queue.h"
31#include "realm/nodeset.h"
32#include "realm/interval_tree.h"
36#include "realm/bgwork.h"
37
38namespace Realm {
39
40 class PartitioningMicroOp;
41 class PartitioningOperation;
42
43
44 template <int N, typename T>
46 public:
49
50 void add_index_space(int label, const IndexSpace<N,T>& space, bool use_approx = true);
51
52 void construct(void);
53
54 void test_overlap(const Rect<N,T>* rects, size_t count, std::set<int>& overlaps);
55 void test_overlap(const IndexSpace<N,T>& space, std::set<int>& overlaps, bool approx);
56 void test_overlap(const SparsityMapImpl<N,T> *sparsity, std::set<int>& overlaps, bool approx);
57
58 protected:
59 std::vector<int> labels;
60 std::vector<IndexSpace<N,T> > spaces;
61 std::vector<bool> approxs;
62 };
63
64 template <typename T>
65 class OverlapTester<1,T> {
66 public:
69
70 void add_index_space(int label, const IndexSpace<1,T>& space, bool use_approx = true);
71
72 void construct(void);
73
74 void test_overlap(const Rect<1,T>* rects, size_t count, std::set<int>& overlaps);
75 void test_overlap(const IndexSpace<1,T>& space, std::set<int>& overlaps, bool approx);
76 void test_overlap(const SparsityMapImpl<1,T> *sparsity, std::set<int>& overlaps, bool approx);
77
78 protected:
80 };
81
82
84
86 public:
89
90 virtual void request_cancellation(void);
91
92 virtual void print(std::ostream& os) const;
93
94 protected:
96 };
97
99 public:
101 virtual ~PartitioningMicroOp(void);
102
103 virtual void execute(void) = 0;
104
105 void mark_started(void);
106 void mark_finished(void);
107
108 template <int N, typename T>
109 void sparsity_map_ready(SparsityMapImpl<N,T> *sparsity, bool precise);
110
114
115 protected:
116 PartitioningMicroOp(NodeID _requestor, AsyncMicroOp *_async_microop);
117
118 void finish_dispatch(PartitioningOperation *op, bool inline_ok);
119
120 atomic<int> wait_count; // how many sparsity maps are we still waiting for?
123
124 // helper code to ship a microop to another node
125 template <typename T>
126 static void forward_microop(NodeID target,
127 PartitioningOperation *op, T *microop);
128 };
129
130 template <int N, typename T>
132 public:
133 // tied to the ImageOperation * - cannot be moved around the system
136
137 void add_input_space(const IndexSpace<N,T>& input_space);
138 void add_extra_dependency(const IndexSpace<N,T>& dep_space);
139
140 virtual void execute(void);
141
142 void dispatch(PartitioningOperation *op, bool inline_ok);
143
144 protected:
146 std::vector<IndexSpace<N,T> > input_spaces;
147 std::vector<SparsityMapImpl<N,T> *> extra_deps;
148 };
149
151 //
152
154 public:
156 GenEventImpl *_finish_event,
157 EventImpl::gen_t _finish_gen);
158
159 virtual void execute(void) = 0;
160
161 // the type of 'tester' depends on which operation it is, so erase the type here...
162 virtual void set_overlap_tester(void *tester);
163
164 void launch(Event wait_for);
165
166 // some partitioning operations are handled inline for simple cases
167 // these cases must still supply all the requested profiling responses
169 long long inline_start_time);
170
174
176 public:
177 void defer(PartitioningOperation *_op, Event wait_on);
178
179 virtual void event_triggered(bool poisoned, TimeLimit work_until);
180 virtual void print(std::ostream& os) const;
181 virtual Event get_finish_event(void) const;
182
183 protected:
185 };
187 };
188
189
191 //
192
222
223
225 //
226 // active messages
227
228
229 template <typename T>
233
234 static void handle_message(NodeID sender,
235 const RemoteMicroOpMessage<T> &msg,
236 const void *data, size_t datalen)
237 {
239 T *uop = new T(sender, msg.async_microop, fbd);
240 uop->dispatch(msg.operation, false /*not ok to run in this thread*/);
241 }
242 };
243
244
247
248 static void handle_message(NodeID sender,
250 const void *data, size_t datalen);
251
253 };
254
255
256};
257
258#include "realm/deppart/partitions.inl"
259
260#endif // REALM_PARTITIONS_H
261
Definition activemsg.h:303
Definition partitions.h:85
PartitioningMicroOp * uop
Definition partitions.h:95
AsyncMicroOp(Operation *_op, PartitioningMicroOp *_uop)
virtual void request_cancellation(void)
virtual void print(std::ostream &os) const
Definition bgwork.h:129
Definition bgwork.h:36
Definition partitions.h:131
std::vector< IndexSpace< N, T > > input_spaces
Definition partitions.h:146
void add_input_space(const IndexSpace< N, T > &input_space)
void add_extra_dependency(const IndexSpace< N, T > &dep_space)
void dispatch(PartitioningOperation *op, bool inline_ok)
ComputeOverlapMicroOp(PartitioningOperation *_op)
PartitioningOperation * op
Definition partitions.h:145
virtual ~ComputeOverlapMicroOp(void)
std::vector< SparsityMapImpl< N, T > * > extra_deps
Definition partitions.h:147
virtual void execute(void)
Definition threads.h:382
Definition threads.h:342
Definition threads.h:428
unsigned gen_t
Definition event_impl.h:87
Definition event_impl.h:49
Definition event.h:50
Definition event_impl.h:198
Definition interval_tree.h:29
Definition lists.h:66
Definition operation.h:75
Definition operation.h:32
void test_overlap(const SparsityMapImpl< 1, T > *sparsity, std::set< int > &overlaps, bool approx)
IntervalTree< T, int > interval_tree
Definition partitions.h:79
void add_index_space(int label, const IndexSpace< 1, T > &space, bool use_approx=true)
void test_overlap(const IndexSpace< 1, T > &space, std::set< int > &overlaps, bool approx)
void test_overlap(const Rect< 1, T > *rects, size_t count, std::set< int > &overlaps)
Definition partitions.h:45
void test_overlap(const Rect< N, T > *rects, size_t count, std::set< int > &overlaps)
std::vector< IndexSpace< N, T > > spaces
Definition partitions.h:60
void add_index_space(int label, const IndexSpace< N, T > &space, bool use_approx=true)
std::vector< bool > approxs
Definition partitions.h:61
void test_overlap(const IndexSpace< N, T > &space, std::set< int > &overlaps, bool approx)
std::vector< int > labels
Definition partitions.h:59
void test_overlap(const SparsityMapImpl< N, T > *sparsity, std::set< int > &overlaps, bool approx)
Definition partitions.h:98
static void forward_microop(NodeID target, PartitioningOperation *op, T *microop)
NodeID requestor
Definition partitions.h:121
AsyncMicroOp * async_microop
Definition partitions.h:122
IntrusiveList< PartitioningMicroOp, REALM_PMTA_USE(PartitioningMicroOp, uop_link), DummyLock > MicroOpList
Definition partitions.h:113
REALM_PMTA_DEFN(PartitioningMicroOp, IntrusiveListLink< PartitioningMicroOp >, uop_link)
void sparsity_map_ready(SparsityMapImpl< N, T > *sparsity, bool precise)
virtual void execute(void)=0
PartitioningMicroOp(NodeID _requestor, AsyncMicroOp *_async_microop)
virtual ~PartitioningMicroOp(void)
IntrusiveListLink< PartitioningMicroOp > uop_link
Definition partitions.h:111
void finish_dispatch(PartitioningOperation *op, bool inline_ok)
atomic< int > wait_count
Definition partitions.h:120
Definition partitions.h:193
static void stop_worker_threads(void)
CoreReservation * rsrv
Definition partitions.h:214
void enqueue_partitioning_microop(PartitioningMicroOp *uop)
static void start_worker_threads(CoreReservationSet &crs, BackgroundWorkManager *_bgwork)
PartitioningOperation::OpList op_list
Definition partitions.h:215
PartitioningOpQueue(CoreReservation *_rsrv, BackgroundWorkManager *_bgwork)
void enqueue_partitioning_operation(PartitioningOperation *op)
std::vector< Thread * > workers
Definition partitions.h:219
bool do_work(TimeLimit work_until)
PartitioningMicroOp::MicroOpList uop_list
Definition partitions.h:216
virtual ~PartitioningOpQueue(void)
static void configure_from_cmdline(std::vector< std::string > &cmdline)
bool work_advertised
Definition partitions.h:220
atomic< bool > shutdown_flag
Definition partitions.h:213
Mutex mutex
Definition partitions.h:217
Mutex::CondVar condvar
Definition partitions.h:218
PartitioningOperation * op
Definition partitions.h:184
virtual Event get_finish_event(void) const
void defer(PartitioningOperation *_op, Event wait_on)
virtual void event_triggered(bool poisoned, TimeLimit work_until)
virtual void print(std::ostream &os) const
Definition partitions.h:153
DeferredLaunch deferred_launch
Definition partitions.h:186
PartitioningOperation(const ProfilingRequestSet &reqs, GenEventImpl *_finish_event, EventImpl::gen_t _finish_gen)
virtual void set_overlap_tester(void *tester)
IntrusiveListLink< PartitioningOperation > op_link
Definition partitions.h:171
void launch(Event wait_for)
REALM_PMTA_DEFN(PartitioningOperation, IntrusiveListLink< PartitioningOperation >, op_link)
virtual void execute(void)=0
IntrusiveList< PartitioningOperation, REALM_PMTA_USE(PartitioningOperation, op_link), DummyLock > OpList
Definition partitions.h:173
static void do_inline_profiling(const ProfilingRequestSet &reqs, long long inline_start_time)
Definition profiling.h:363
Definition sparsity_impl.h:105
Definition timers.h:129
Definition mutex.h:325
Definition mutex.h:223
Definition atomics.h:31
#define REALM_PMTA_USE(structtype, name)
Definition lists.h:42
Definition activemsg.h:38
int NodeID
Definition nodeset.h:40
Definition indexspace.h:323
Definition point.h:143
Definition partitions.h:245
static ActiveMessageHandlerReg< RemoteMicroOpCompleteMessage > areg
Definition partitions.h:252
AsyncMicroOp * async_microop
Definition partitions.h:246
static void handle_message(NodeID sender, const RemoteMicroOpCompleteMessage &msg, const void *data, size_t datalen)
Definition partitions.h:230
static void handle_message(NodeID sender, const RemoteMicroOpMessage< T > &msg, const void *data, size_t datalen)
Definition partitions.h:234
AsyncMicroOp * async_microop
Definition partitions.h:232
PartitioningOperation * operation
Definition partitions.h:231