Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
inst_impl.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// RegionInstance implementations for Realm
19
20#ifndef REALM_INST_IMPL_H
21#define REALM_INST_IMPL_H
22
23#include "realm/instance.h"
24#include "realm/id.h"
25#include "realm/inst_layout.h"
26
27#include "realm/mutex.h"
28
29#include "realm/rsrv_impl.h"
30#include "realm/metadata.h"
31#include "realm/event_impl.h"
32#include "realm/profiling.h"
33#include "realm/mem_impl.h"
34#include "realm/repl_heap.h"
35
36namespace Realm {
37
39 public:
42
43 virtual void *allocate_memory(size_t bytes);
44
45 virtual void commit_updates();
46
47 void reset();
48
49 void *program_base{nullptr};
50 size_t program_size{0};
52 };
53
55 public:
56 // RegionInstanceImpl creation/deletion is handled by MemoryImpl
58 MemoryImpl *_memory);
60
61 class DeferredCreate : public EventWaiter {
62 public:
63 void defer(RegionInstanceImpl *_inst, MemoryImpl *_mem, bool _need_alloc_result,
64 Event wait_on);
65 virtual void event_triggered(bool poisoned, TimeLimit work_until);
66 virtual void print(std::ostream &os) const;
67 virtual Event get_finish_event(void) const;
68
69 protected:
73 };
75
77 public:
78 void defer(RegionInstanceImpl *_inst, MemoryImpl *_mem, Event wait_on);
79 virtual void event_triggered(bool poisoned, TimeLimit work_until);
80 virtual void print(std::ostream &os) const;
81 virtual Event get_finish_event(void) const;
82
83 protected:
86 };
88
89 // Some help for when a deferred redistrict is performed on
90 // an instance that hasn't even been allocated yet
91 std::vector<RegionInstanceImpl *> deferred_redistrict;
92
93 public:
94 // entry point for both create_instance and create_external_instance
97 const ExternalInstanceResource *res,
98 const ProfilingRequestSet &prs, Event wait_on);
99
104 void release(Event wait_on);
105
107 size_t num_layouts, const ProfilingRequestSet *prs,
108 Event wait_on = Event::NO_EVENT);
109
110 // the life cycle of an instance is defined in part by when the
111 // allocation and deallocation of storage occurs, but that is managed
112 // by the memory, which uses these callbacks to notify us
114 TimeLimit work_until);
116
117 bool get_strided_parameters(void *&base, size_t &stride, off_t field_offset) const;
118
120
122 {
123 return metadata.request_data(int(ID(me).instance_creator_node()), me.id);
124 }
125
126 // ensures metadata is available on the specified node
128
129 // called once storage has been released and all remote metadata is invalidated
131
132 template <int N, typename T>
134 get_lookup_program(FieldID field_id, unsigned allowed_mask, uintptr_t &field_offset);
135
136 template <int N, typename T>
138 get_lookup_program(FieldID field_id, const Rect<N, T> &subrect, unsigned allowed_mask,
139 size_t &field_offset);
140
141 void read_untyped(size_t offset, void *data, size_t datalen) const;
142
143 void write_untyped(size_t offset, const void *data, size_t datalen);
144
145 void reduce_apply_untyped(size_t offset, ReductionOpID redop_id, const void *data,
146 size_t datalen, bool exclusive /*= false*/);
147
148 void reduce_fold_untyped(size_t offset, ReductionOpID redop_id, const void *data,
149 size_t datalen, bool exclusive /*= false*/);
150
151 void *pointer_untyped(size_t offset, size_t datalen);
152
153 public: // protected:
154 void send_metadata(const NodeSet &early_reqs);
155
156 friend class RegionInstance;
157
159 // not part of metadata because it's determined from ID alone
161 // Profiling info only needed on creation node
165
166 // several special values exist for the 'inst_offset' field below
167 static constexpr size_t INSTOFFSET_UNALLOCATED = size_t(-1);
168 static constexpr size_t INSTOFFSET_FAILED = size_t(-2);
169 static constexpr size_t INSTOFFSET_DELAYEDALLOC = size_t(-3);
170 static constexpr size_t INSTOFFSET_DELAYEDDESTROY = size_t(-4);
171 static constexpr size_t INSTOFFSET_DELAYEDREDISTRICT = size_t(-5);
172 static constexpr size_t INSTOFFSET_MAXVALID = size_t(-6);
173 class Metadata : public MetadataBase {
174 public:
176
177 void *serialize(size_t &out_size) const;
178
179 template <typename T>
180 void serialize_msg(T &s) const
181 {
182 bool ok = ((s << inst_offset) && (s << *layout));
183 assert(ok);
184 }
185
186 void deserialize(const void *in_data, size_t in_size);
187
188 protected:
189 virtual void do_invalidate(void);
190
191 public:
197 MemSpecificInfo *mem_specific; // a place for memory's to hang info
199
200 template <typename T>
202 {
204 while(info) {
205 T *downcast = dynamic_cast<T *>(info);
206 if(downcast)
207 return downcast;
208 info = info->next;
209 }
210 return 0;
211 }
212
213 template <typename T>
214 const T *find_mem_specific() const
215 {
216 const MemSpecificInfo *info = mem_specific;
217 while(info) {
218 const T *downcast = dynamic_cast<const T *>(info);
219 if(downcast)
220 return downcast;
221 info = info->next;
222 }
223 return 0;
224 }
225
227 };
228
229 // used for atomic access to metadata
232 // cache of prefetch events for other nodes
233 std::map<NodeID, Event> prefetch_events;
234
235 // used for serialized application access to contents of instance
237
238 private:
239 const RuntimeImpl *runtime_impl{nullptr};
240 };
241
242 // active messages
243
247
249 const void *data, size_t datalen, TimeLimit work_until);
250 };
251
252}; // namespace Realm
253
254#endif // ifndef REALM_INST_IMPL_H
Definition inst_impl.h:38
ReplicatedHeap * repl_heap
Definition inst_impl.h:51
void * program_base
Definition inst_impl.h:49
CompiledInstanceLayout(ReplicatedHeap *_repl_heap)
virtual void * allocate_memory(size_t bytes)
size_t program_size
Definition inst_impl.h:50
Definition event_impl.h:49
Definition event.h:50
static const Event NO_EVENT
The value should be usued to initialize an event handle. NO_EVENT is always in has triggered state .
Definition event.h:71
Definition instance.h:405
Definition id.h:30
Definition inst_layout.h:164
Definition mem_impl.h:212
MemSpecificInfo * next
Definition mem_impl.h:217
Definition mem_impl.h:50
AllocationResult
Definition mem_impl.h:89
Definition metadata.h:34
Event request_data(int owner, ID::IDType id)
Definition nodeset.h:117
Definition inst_layout.h:97
Definition processor.h:37
Definition profiling.h:393
Definition profiling.h:363
virtual void print(std::ostream &os) const
virtual Event get_finish_event(void) const
bool need_alloc_result
Definition inst_impl.h:72
RegionInstanceImpl * inst
Definition inst_impl.h:70
virtual void event_triggered(bool poisoned, TimeLimit work_until)
void defer(RegionInstanceImpl *_inst, MemoryImpl *_mem, bool _need_alloc_result, Event wait_on)
MemoryImpl * mem
Definition inst_impl.h:71
virtual Event get_finish_event(void) const
void defer(RegionInstanceImpl *_inst, MemoryImpl *_mem, Event wait_on)
RegionInstanceImpl * inst
Definition inst_impl.h:84
MemoryImpl * mem
Definition inst_impl.h:85
virtual void print(std::ostream &os) const
virtual void event_triggered(bool poisoned, TimeLimit work_until)
Definition inst_impl.h:173
MemSpecificInfo * mem_specific
Definition inst_impl.h:197
void serialize_msg(T &s) const
Definition inst_impl.h:180
Metadata(ReplicatedHeap *repl_heap)
T * find_mem_specific()
Definition inst_impl.h:201
Event ready_event
Definition inst_impl.h:193
size_t inst_offset
Definition inst_impl.h:192
void * serialize(size_t &out_size) const
CompiledInstanceLayout lookup_program
Definition inst_impl.h:198
void add_mem_specific(MemSpecificInfo *info)
void deserialize(const void *in_data, size_t in_size)
const T * find_mem_specific() const
Definition inst_impl.h:214
bool need_alloc_result
Definition inst_impl.h:194
ExternalInstanceResource * ext_resource
Definition inst_impl.h:196
bool need_notify_dealloc
Definition inst_impl.h:194
InstanceLayoutGeneric * layout
Definition inst_impl.h:195
Definition inst_impl.h:54
Event prefetch_metadata(NodeID target)
static constexpr size_t INSTOFFSET_FAILED
Definition inst_impl.h:168
RegionInstanceImpl(const RuntimeImpl *_runtime_impl, RegionInstance _me, MemoryImpl *_memory)
static Event create_instance(RegionInstance &inst, MemoryImpl *memory, InstanceLayoutGeneric *ilg, const ExternalInstanceResource *res, const ProfilingRequestSet &prs, Event wait_on)
ProfilingRequestSet requests
Definition inst_impl.h:162
ProfilingMeasurements::InstanceTimeline timeline
Definition inst_impl.h:164
static constexpr size_t INSTOFFSET_MAXVALID
Definition inst_impl.h:172
std::vector< RegionInstanceImpl * > deferred_redistrict
Definition inst_impl.h:91
Event redistrict(RegionInstance *instances, const InstanceLayoutGeneric **layouts, size_t num_layouts, const ProfilingRequestSet *prs, Event wait_on=Event::NO_EVENT)
bool get_strided_parameters(void *&base, size_t &stride, off_t field_offset) const
Event request_metadata(void)
Definition inst_impl.h:121
static constexpr size_t INSTOFFSET_DELAYEDDESTROY
Definition inst_impl.h:170
Metadata metadata
Definition inst_impl.h:231
void * pointer_untyped(size_t offset, size_t datalen)
MemoryImpl * mem_impl
Definition inst_impl.h:160
const PieceLookup::Instruction * get_lookup_program(FieldID field_id, const Rect< N, T > &subrect, unsigned allowed_mask, size_t &field_offset)
std::map< NodeID, Event > prefetch_events
Definition inst_impl.h:233
void reduce_fold_untyped(size_t offset, ReductionOpID redop_id, const void *data, size_t datalen, bool exclusive)
Event fetch_metadata(Processor target)
void send_metadata(const NodeSet &early_reqs)
DeferredCreate deferred_create
Definition inst_impl.h:74
Mutex mutex
Definition inst_impl.h:230
void release(Event wait_on)
Release this instance and the resources it holds after wait_on has been triggered.
DeferredDestroy deferred_destroy
Definition inst_impl.h:87
static constexpr size_t INSTOFFSET_DELAYEDREDISTRICT
Definition inst_impl.h:171
ProfilingMeasurementCollection measurements
Definition inst_impl.h:163
ReservationImpl lock
Definition inst_impl.h:236
void reduce_apply_untyped(size_t offset, ReductionOpID redop_id, const void *data, size_t datalen, bool exclusive)
void notify_allocation(MemoryImpl::AllocationResult result, size_t offset, TimeLimit work_until)
void write_untyped(size_t offset, const void *data, size_t datalen)
static constexpr size_t INSTOFFSET_UNALLOCATED
Definition inst_impl.h:167
void read_untyped(size_t offset, void *data, size_t datalen) const
const PieceLookup::Instruction * get_lookup_program(FieldID field_id, unsigned allowed_mask, uintptr_t &field_offset)
RegionInstance me
Definition inst_impl.h:158
static constexpr size_t INSTOFFSET_DELAYEDALLOC
Definition inst_impl.h:169
Definition instance.h:66
id_t id
Definition instance.h:69
Definition repl_heap.h:30
Definition rsrv_impl.h:57
Definition runtime_impl.h:264
Definition timers.h:129
Definition mutex.h:223
Definition activemsg.h:38
realm_field_id_t FieldID
Definition instance.h:45
int NodeID
Definition nodeset.h:40
::realm_reduction_op_id_t ReductionOpID
Definition event.h:38
Definition inst_impl.h:244
Event valid_event
Definition inst_impl.h:246
RegionInstance inst
Definition inst_impl.h:245
static void handle_message(NodeID sender, const InstanceMetadataPrefetchRequest &msg, const void *data, size_t datalen, TimeLimit work_until)
Definition inst_layout.h:131
Definition point.h:143