Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
subgraph.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// subgraphs for Realm
19
20#ifndef REALM_SUBGRAPH_H
21#define REALM_SUBGRAPH_H
22
23#include "realm/realm_c.h"
24
25#include "realm/event.h"
26#include "realm/indexspace.h"
27#include "realm/processor.h"
28#include "realm/profiling.h"
29#include "realm/reservation.h"
30
31namespace Realm {
32
33 // TODO: C equivalent: realm_subgraph_defn_t
34 struct SubgraphDefinition;
35
37 public:
39
41 bool operator<(const Subgraph &rhs) const { return id < rhs.id; }
42 bool operator==(const Subgraph &rhs) const { return id == rhs.id; }
43 bool operator!=(const Subgraph &rhs) const { return id != rhs.id; }
44
45 static const Subgraph NO_SUBGRAPH;
46
47 bool exists(void) const { return id != 0; }
48
49 static Event create_subgraph(Subgraph &subgraph, const SubgraphDefinition &defn,
50 const ProfilingRequestSet &prs,
51 Event wait_on = Event::NO_EVENT);
52
53 // TODO: collective construction
54
55 void destroy(Event wait_on = Event::NO_EVENT) const;
56
57 Event instantiate(const void *args, size_t arglen, const ProfilingRequestSet &prs,
58 Event wait_on = Event::NO_EVENT, int priority_adjust = 0) const;
59
60 Event instantiate(const void *args, size_t arglen, const ProfilingRequestSet &prs,
61 const std::vector<Event> &preconditions,
62 std::vector<Event> &postconditions, Event wait_on = Event::NO_EVENT,
63 int priority_adjust = 0) const;
64
65 // TODO: collective instantiation
66 };
67
70
71 // operations permitted in a subgraph:
72 // task spawn
73 // copy/fill
74 // barrier arrival
75 // subgraph instantiation
76 // reservation acquire/release
77
78 // operations not permitted in a subgraph:
79 // instance creation/destruction
80 // subgraph creation/destruction
81 // reservation creation/destruction
82 // barrier creation/destruction
83 // user event creation/triggering
84 // barrier wait (use a precondition)
85 // task registration
86
87 struct TaskDesc {
88 TaskDesc(); // initializes all fields
89
90 // interpolatable: args
94 int priority /*= 0*/;
96 };
97
98 struct CopyDesc {
99 CopyDesc(); // initializes all fields
100
101 // interpolatable: none?
102 IndexSpaceGeneric space; // type-erase here to avoid template explosion
103 std::vector<CopySrcDstField> srcs;
104 std::vector<CopySrcDstField> dsts;
106 ReductionOpID redop_id /*= 0*/;
107 bool red_fold /*= false*/;
108 int priority /*= 0*/;
109 };
110
111 struct ArrivalDesc {
112 ArrivalDesc(); // initializes all fields
113
114 // interpolatable: { barrier, reduce_value }
116 unsigned count /*= 1*/;
118 };
119
121 InstantiationDesc(); // initializes all fields
122
123 // interpolatable: args
128 };
129
130 struct AcquireDesc {
131 AcquireDesc(); // initializes all fields
132
133 // interpolatable: none?
135 unsigned mode /*= 0*/;
136 bool exclusive /*= true*/;
137 };
138
139 struct ReleaseDesc {
140 ReleaseDesc(); // initializes all fields
141
142 // interpolatable: none?
144 };
145
146 std::vector<TaskDesc> tasks;
147 std::vector<CopyDesc> copies;
148 std::vector<ArrivalDesc> arrivals;
149 std::vector<InstantiationDesc> instantiations;
150 std::vector<AcquireDesc> acquires;
151 std::vector<ReleaseDesc> releases;
152
153 // dependencies between subgraph operations and/or external
154 // pre/post-conditions
155 // operations are defined by their kind and their index
156 // most operations have exactly one input "port" and output "port", but:
157 // arrivals and releases have zero outputs
158 // an instantiation has as many ports as it was defined with (including
159 // the "default port" 0)
160 // the same target op/port may be subject to multiple dependencies - the
161 // equivalent of event merging happens behind the scenes
162
177
178 struct Dependency {
179 Dependency(); // initializes all fields
180
182 unsigned src_op_index;
183 unsigned src_op_port;
185 unsigned tgt_op_index;
186 unsigned tgt_op_port;
187 };
188
189 std::vector<Dependency> dependencies;
190
191 // interpolation allows values provided at subgraph instantiation time to
192 // overwrite/combine with argument values provided at subgraph creation
193 // time
194 // TODO: could use this to allow looking at barrier values?
195 // TODO: allow _all_ operation parameters to be interpolated, even if
196 // it means subgraph cannot be pre-compiled?
197
199 Interpolation(); // initializes all fields
200
202 {
204
205 TARGET_TASK_BASE = OPKIND_TASK << 8,
207
208 TARGET_COPY_BASE = OPKIND_COPY << 8,
209
210 TARGET_ARRIVAL_BASE = OPKIND_ARRIVAL << 8,
213
214 TARGET_INSTANCE_BASE = OPKIND_INSTANTIATION << 8,
216
217 TARGET_ACQUIRE_BASE = OPKIND_ACQUIRE << 8,
218
219 TARGET_RELEASE_BASE = OPKIND_RELEASE << 8,
220 };
221
222 size_t offset; // offset within instantiation args
223 size_t bytes; // size within instantiation args
225 unsigned target_index; // index of operation within its list
226 size_t target_offset; // offset within target field
227 ReductionOpID redop_id; // overwrite if 0, reduce apply otherwise
228 };
229
230 std::vector<Interpolation> interpolations;
231
232 // concurrency mode - more serial versions may allow the compiled form to
233 // pre-allocate and reuse resources, improving efficiency
235 {
236 ONE_SHOT, // can only be executed once (e.g. probably not
237 // worth optimizing)
238 INSTANTIATION_ORDER, // implementation may serialize instantiations in
239 // in the order they were instantiated
240 SERIALIZABLE, // implementations may be serialized, but a later
241 // instatiation must be able to run even if
242 // earlier instantiations are waiting for
243 // satisfaction of their default precondition
244 CONCURRENT, // concurrent execution of instantiations is
245 // required for correctness
246 };
247
249
250 // longer term possibilites:
251 // conditional execution
252 // loops
253 // local "scratchpad" for small-value-communication
254 };
255
256}; // namespace Realm
257
258#include "realm/subgraph.inl"
259
260#endif // ifndef REALM_SUBGRAPH_H
Definition event.h:242
Definition bytearray.h:53
Definition event.h:50
Definition indexspace.h:1115
Definition processor.h:37
::realm_task_func_id_t TaskFuncID
Definition processor.h:58
Definition profiling.h:363
Definition reservation.h:30
Definition subgraph.h:36
::realm_id_t id_t
Definition subgraph.h:38
bool operator!=(const Subgraph &rhs) const
Definition subgraph.h:43
id_t id
Definition subgraph.h:40
bool operator==(const Subgraph &rhs) const
Definition subgraph.h:42
bool operator<(const Subgraph &rhs) const
Definition subgraph.h:41
static Event create_subgraph(Subgraph &subgraph, const SubgraphDefinition &defn, const ProfilingRequestSet &prs, Event wait_on=Event::NO_EVENT)
Event instantiate(const void *args, size_t arglen, const ProfilingRequestSet &prs, const std::vector< Event > &preconditions, std::vector< Event > &postconditions, Event wait_on=Event::NO_EVENT, int priority_adjust=0) const
static const Subgraph NO_SUBGRAPH
Definition subgraph.h:45
Event instantiate(const void *args, size_t arglen, const ProfilingRequestSet &prs, Event wait_on=Event::NO_EVENT, int priority_adjust=0) const
void destroy(Event wait_on=Event::NO_EVENT) const
bool exists(void) const
Definition subgraph.h:47
#define REALM_PUBLIC_API
Definition compiler_support.h:217
Definition activemsg.h:38
::realm_reduction_op_id_t ReductionOpID
Definition event.h:38
unsigned long long realm_id_t
Definition realm_c.h:64
Reservation rsrv
Definition subgraph.h:134
Barrier barrier
Definition subgraph.h:115
ByteArray reduce_value
Definition subgraph.h:117
Definition subgraph.h:98
IndexSpaceGeneric space
Definition subgraph.h:102
std::vector< CopySrcDstField > srcs
Definition subgraph.h:103
std::vector< CopySrcDstField > dsts
Definition subgraph.h:104
ProfilingRequestSet prs
Definition subgraph.h:105
Definition subgraph.h:178
unsigned src_op_index
Definition subgraph.h:182
unsigned src_op_port
Definition subgraph.h:183
unsigned tgt_op_port
Definition subgraph.h:186
OpKind src_op_kind
Definition subgraph.h:181
unsigned tgt_op_index
Definition subgraph.h:185
OpKind tgt_op_kind
Definition subgraph.h:184
ProfilingRequestSet prs
Definition subgraph.h:126
ByteArray args
Definition subgraph.h:125
Subgraph subgraph
Definition subgraph.h:124
int priority_adjust
Definition subgraph.h:127
TargetKind
Definition subgraph.h:202
@ TARGET_INSTANCE_ARGS
Definition subgraph.h:215
@ TARGET_TASK_ARGS
Definition subgraph.h:206
@ TARGET_ARRIVAL_BARRIER
Definition subgraph.h:211
@ TARGET_INVALID
Definition subgraph.h:203
@ TARGET_ARRIVAL_VALUE
Definition subgraph.h:212
TargetKind target_kind
Definition subgraph.h:224
ReductionOpID redop_id
Definition subgraph.h:227
size_t bytes
Definition subgraph.h:223
size_t target_offset
Definition subgraph.h:226
size_t offset
Definition subgraph.h:222
unsigned target_index
Definition subgraph.h:225
Reservation rsrv
Definition subgraph.h:143
Definition subgraph.h:87
Processor::TaskFuncID task_id
Definition subgraph.h:92
ByteArray args
Definition subgraph.h:93
ProfilingRequestSet prs
Definition subgraph.h:95
Processor proc
Definition subgraph.h:91
Definition subgraph.h:68
std::vector< AcquireDesc > acquires
Definition subgraph.h:150
std::vector< Interpolation > interpolations
Definition subgraph.h:230
ConcurrencyMode concurrency_mode
Definition subgraph.h:248
OpKind
Definition subgraph.h:164
@ OPKIND_INVALID
Definition subgraph.h:165
@ OPKIND_ARRIVAL
Definition subgraph.h:168
@ OPKIND_COPY
Definition subgraph.h:167
@ OPKIND_INSTANTIATION
Definition subgraph.h:169
@ OPKIND_EXT_PRECOND
Definition subgraph.h:172
@ OPKIND_COLL_PRECOND
Definition subgraph.h:174
@ OPKIND_COLL_POSTCOND
Definition subgraph.h:175
@ OPKIND_TASK
Definition subgraph.h:166
@ OPKIND_ACQUIRE
Definition subgraph.h:170
@ OPKIND_RELEASE
Definition subgraph.h:171
@ OPKIND_EXT_POSTCOND
Definition subgraph.h:173
std::vector< CopyDesc > copies
Definition subgraph.h:147
std::vector< TaskDesc > tasks
Definition subgraph.h:146
std::vector< ArrivalDesc > arrivals
Definition subgraph.h:148
std::vector< InstantiationDesc > instantiations
Definition subgraph.h:149
ConcurrencyMode
Definition subgraph.h:235
@ ONE_SHOT
Definition subgraph.h:236
@ INSTANTIATION_ORDER
Definition subgraph.h:238
@ SERIALIZABLE
Definition subgraph.h:240
@ CONCURRENT
Definition subgraph.h:244
std::vector< Dependency > dependencies
Definition subgraph.h:189
std::vector< ReleaseDesc > releases
Definition subgraph.h:151