Legion Runtime
Loading...
Searching...
No Matches
replay_mapper.h
Go to the documentation of this file.
1/* Copyright 2026 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 __REPLAY_MAPPER_H__
17#define __REPLAY_MAPPER_H__
18
24#include "legion.h"
25
26#include <stdlib.h>
27#include <assert.h>
28#include <algorithm>
29
30namespace Legion {
31 namespace Mapping {
32
41 class ReplayMapper : public Mapper {
42 public:
43 struct InstanceInfo {
44 public:
45 InstanceInfo(void) : original_id(0),
46 creating_instance(false), instance_valid(false) { }
47 public:
48 PhysicalInstance get_instance(MapperRuntime *runtime,
49 MapperContext ctx, LogicalRegion handle);
50 void create_instance(MapperRuntime *runtime, MapperContext ctx,
51 LogicalRegion handle);
52 void record_created_instance(MapperRuntime *runtime, MapperContext ctx,
53 PhysicalInstance result);
54 void decrement_use_count(MapperRuntime *runtime,
55 MapperContext ctx, bool first);
56 public:
57 unsigned long original_id;
58 unsigned num_uses;
59 Processor creator;
60 bool is_owner;
61 public:
62 Memory target_memory;
63 LayoutConstraintSet layout_constraints;
64 std::vector<std::vector<DomainPoint> > region_paths;
65 public:
66 PhysicalInstance instance;
67 bool creating_instance;
68 bool instance_valid;
69 MapperEvent request_event;
70 };
72 public:
73 void map_requirement(MapperRuntime *runtime, MapperContext ctx,
74 LogicalRegion handle, std::vector<PhysicalInstance> &targets);
75 public:
76 std::vector<InstanceInfo*> instances;
77 };
79 public:
80 void set_tunable(void *&value, size_t &size);
81 public:
82 unsigned tunable_size;
83 void *tunable_value;
84 };
86 public:
87 TaskMappingInfo(void) : next_tunable(0) { }
88 public:
89 UniqueID original_unique_id;
90 Processor target_proc;
91 VariantID variant;
92 TaskPriority priority;
93 unsigned next_tunable;
94 public:
95 std::vector<RequirementMapping*> mappings;
96 std::map<unsigned,RequirementMapping*> postmappings;
97 std::vector<TunableMapping*> tunables;
98 std::vector<UniqueID/*original*/> operation_ids;
99 std::vector<UniqueID/*original*/> close_ids;
100 };
102 public:
103 RequirementMapping *mapping;
104 };
106 public:
107 std::vector<RequirementMapping*> src_mappings;
108 std::vector<RequirementMapping*> dst_mappings;
109 };
111 public:
112 RequirementMapping *mapping;
113 };
115 public:
116 };
117 public:
118 enum ReplayMessageKind {
119 ID_MAPPING_MESSAGE,
120 INSTANCE_MAPPING_MESSAGE,
121 CREATE_INSTANCE_MESSAGE,
122 INSTANCE_CREATION_MESSAGE,
123 DECREMENT_USE_MESSAGE,
124 };
125 public:
126 ReplayMapper(MapperRuntime *rt, Machine machine, Processor local,
127 const char *replay_file, const char *mapper_name = NULL);
128 ReplayMapper(const ReplayMapper &rhs);
129 virtual ~ReplayMapper(void);
130 public:
131 ReplayMapper& operator=(const ReplayMapper &rhs);
132 public:
133 static const char* create_replay_name(Processor p);
134 public:
135 const char* get_mapper_name(void) const override;
136 MapperSyncModel get_mapper_sync_model(void) const override;
137 public: // Task mapping calls
138 void select_task_options(const MapperContext ctx,
139 const Task& task,
140 TaskOptions& output) override;
141 void premap_task(const MapperContext ctx,
142 const Task& task,
143 const PremapTaskInput& input,
144 PremapTaskOutput& output) override;
145 void slice_task(const MapperContext ctx,
146 const Task& task,
147 const SliceTaskInput& input,
148 SliceTaskOutput& output) override;
149 void map_task(const MapperContext ctx,
150 const Task& task,
151 const MapTaskInput& input,
152 MapTaskOutput& output) override;
153 void replicate_task(MapperContext ctx,
154 const Task& task,
155 const ReplicateTaskInput& input,
156 ReplicateTaskOutput& output) override;
157 void select_task_variant(const MapperContext ctx,
158 const Task& task,
159 const SelectVariantInput& input,
160 SelectVariantOutput& output) override;
161 void postmap_task(const MapperContext ctx,
162 const Task& task,
163 const PostMapInput& input,
164 PostMapOutput& output) override;
165 void select_task_sources(const MapperContext ctx,
166 const Task& task,
167 const SelectTaskSrcInput& input,
168 SelectTaskSrcOutput& output) override;
169 void report_profiling(const MapperContext ctx,
170 const Task& task,
171 const TaskProfilingInfo& input) override;
172 void select_sharding_functor(
173 const MapperContext ctx,
174 const Task& task,
175 const SelectShardingFunctorInput& input,
176 SelectShardingFunctorOutput& output) override;
177 public: // Inline mapping calls
178 void map_inline(const MapperContext ctx,
179 const InlineMapping& inline_op,
180 const MapInlineInput& input,
181 MapInlineOutput& output) override;
182 void select_inline_sources(const MapperContext ctx,
183 const InlineMapping& inline_op,
184 const SelectInlineSrcInput& input,
185 SelectInlineSrcOutput& output) override;
186 void report_profiling(const MapperContext ctx,
187 const InlineMapping& inline_op,
188 const InlineProfilingInfo& input) override;
189 public: // Copy mapping calls
190 void map_copy(const MapperContext ctx,
191 const Copy& copy,
192 const MapCopyInput& input,
193 MapCopyOutput& output) override;
194 void select_copy_sources(const MapperContext ctx,
195 const Copy& copy,
196 const SelectCopySrcInput& input,
197 SelectCopySrcOutput& output) override;
198 void report_profiling(const MapperContext ctx,
199 const Copy& copy,
200 const CopyProfilingInfo& input) override;
202 const MapperContext ctx,
203 const Copy& copy,
204 const SelectShardingFunctorInput& input,
205 SelectShardingFunctorOutput& output) override;
206 public: // Close mapping calls
207 void select_close_sources(const MapperContext ctx,
208 const Close& close,
209 const SelectCloseSrcInput& input,
210 SelectCloseSrcOutput& output) override;
211 void report_profiling(const MapperContext ctx,
212 const Close& close,
213 const CloseProfilingInfo& input) override;
215 const MapperContext ctx,
216 const Close& close,
217 const SelectShardingFunctorInput& input,
218 SelectShardingFunctorOutput& output) override;
219 public: // Acquire mapping calls
220 void map_acquire(const MapperContext ctx,
221 const Acquire& acquire,
222 const MapAcquireInput& input,
223 MapAcquireOutput& output) override;
224 void report_profiling(const MapperContext ctx,
225 const Acquire& acquire,
226 const AcquireProfilingInfo& input) override;
228 const MapperContext ctx,
229 const Acquire& acquire,
230 const SelectShardingFunctorInput& input,
231 SelectShardingFunctorOutput& output) override;
232 public: // Release mapping calls
233 void map_release(const MapperContext ctx,
234 const Release& release,
235 const MapReleaseInput& input,
236 MapReleaseOutput& output) override;
237 void select_release_sources(const MapperContext ctx,
238 const Release& release,
239 const SelectReleaseSrcInput& input,
240 SelectReleaseSrcOutput& output) override;
241 void report_profiling(const MapperContext ctx,
242 const Release& release,
243 const ReleaseProfilingInfo& input) override;
245 const MapperContext ctx,
246 const Release& release,
247 const SelectShardingFunctorInput& input,
248 SelectShardingFunctorOutput& output) override;
249 public: // Partition mapping calls
250 void select_partition_projection(const MapperContext ctx,
251 const Partition& partition,
253 SelectPartitionProjectionOutput& output) override;
254 void map_partition(const MapperContext ctx,
255 const Partition& partition,
256 const MapPartitionInput& input,
257 MapPartitionOutput& output) override;
258 void select_partition_sources(
259 const MapperContext ctx,
260 const Partition& partition,
261 const SelectPartitionSrcInput& input,
262 SelectPartitionSrcOutput& output) override;
263 void report_profiling(const MapperContext ctx,
264 const Partition& partition,
265 const PartitionProfilingInfo& input) override;
267 const MapperContext ctx,
268 const Partition& partition,
269 const SelectShardingFunctorInput& input,
270 SelectShardingFunctorOutput& output) override;
271 public: // Fill mapper calls
273 const MapperContext ctx,
274 const Fill& fill,
275 const SelectShardingFunctorInput& input,
276 SelectShardingFunctorOutput& output) override;
277 public: // Task execution mapping calls
278 void configure_context(const MapperContext ctx,
279 const Task& task,
280 ContextConfigOutput& output) override;
281 void select_tunable_value(const MapperContext ctx,
282 const Task& task,
283 const SelectTunableInput& input,
284 SelectTunableOutput& output) override;
285 public: // Must epoch mapping
286 void select_sharding_functor(
287 const MapperContext ctx,
288 const MustEpoch& epoch,
289 const SelectShardingFunctorInput& input,
290 MustEpochShardingFunctorOutput& output) override;
291 void map_must_epoch(const MapperContext ctx,
292 const MapMustEpochInput& input,
293 MapMustEpochOutput& output) override;
294 public: // Dataflow graph mapping
295 void map_dataflow_graph(const MapperContext ctx,
296 const MapDataflowGraphInput& input,
297 MapDataflowGraphOutput& output) override;
298 public: // Memoization control
299 void memoize_operation(const MapperContext ctx,
300 const Mappable& mappable,
301 const MemoizeInput& input,
302 MemoizeOutput& output) override;
303 public: // Mapping control and stealing
304 void select_tasks_to_map(const MapperContext ctx,
305 const SelectMappingInput& input,
306 SelectMappingOutput& output) override;
307 void select_steal_targets(const MapperContext ctx,
308 const SelectStealingInput& input,
309 SelectStealingOutput& output) override;
310 void permit_steal_request(const MapperContext ctx,
311 const StealRequestInput& intput,
312 StealRequestOutput& output) override;
313 public: // handling
314 void handle_message(const MapperContext ctx,
315 const MapperMessage& message) override;
316 void handle_task_result(const MapperContext ctx,
317 const MapperTaskResult& result) override;
318 protected:
319 unsigned long find_original_instance_id(MapperContext ctx,
320 unsigned long current_id);
321 void update_original_instance_id(MapperContext ctx,
322 unsigned long current_id, unsigned long original_id);
323 protected:
324 InstanceInfo* unpack_instance(FILE *f) const;
325 TaskMappingInfo* unpack_task_mapping(FILE *f) const;
326 InlineMappingInfo* unpack_inline_mapping(FILE *f) const;
327 CopyMappingInfo* unpack_copy_mapping(FILE *f) const;
328 CloseMappingInfo* unpack_close_mapping(FILE *f) const;
329 ReleaseMappingInfo* unpack_release_mapping(FILE *f) const;
330 RequirementMapping* unpack_requirement(FILE *f) const;
331 TunableMapping* unpack_tunable(FILE *f) const;
332 protected:
333 TaskMappingInfo* find_task_mapping(MapperContext ctx, const Task &task,
334 const DomainPoint &p, bool parent = false);
335 InlineMappingInfo* find_inline_mapping(MapperContext ctx,
336 const InlineMapping &inline_op);
337 CopyMappingInfo* find_copy_mapping(MapperContext ctx, const Copy &copy);
338 CloseMappingInfo* find_close_mapping(MapperContext ctx,
339 const Close &close);
340 ReleaseMappingInfo* find_release_mapping(MapperContext ctx,
341 const Release &release);
342 protected:
343 template<typename T>
344 static inline void ignore_result(T arg) { }
345 protected:
346 const Machine machine;
347 const Processor local_proc;
348 const char *const mapper_name;
349 protected:
350 std::map<unsigned long,InstanceInfo*> instance_infos;
351 std::map<std::pair<UniqueID/*original*/,DomainPoint>,TaskMappingInfo*>
352 task_mappings;
353 std::map<UniqueID/*original*/,InlineMappingInfo*> inline_mappings;
354 std::map<UniqueID/*original*/,CopyMappingInfo*> copy_mappings;
355 std::map<UniqueID/*original*/,CloseMappingInfo*> close_mappings;
356 std::map<UniqueID/*original*/,ReleaseMappingInfo*> release_mappings;
357 protected:
358 UniqueID top_level_id;
359 std::map<UniqueID/*current*/,UniqueID/*original*/> original_mappings;
360 std::map<UniqueID/*current*/,MapperEvent> pending_task_ids;
361 protected:
362 std::map<unsigned long/*current*/,unsigned long/*original*/>
363 original_instances;
364 std::map<unsigned long/*current*/,MapperEvent> pending_instance_ids;
365 };
366
367 }; // namespace Mapping
368}; // namespace Legion
369
370#endif // _REPLAY_MAPPER_H___
371
Definition mapping.h:240
Definition mapping.h:292
Definition mapping.h:185
Definition geometry.h:34
Definition mapping.h:312
Definition mapping.h:216
Definition constraints.h:881
Definition data.h:189
Definition mapping.h:42
Definition mapping.h:526
Definition mapping.h:642
MapperSyncModel
Definition mapping.h:678
Definition mapping.h:2458
Definition mapping.h:414
Definition replay_mapper.h:41
void select_sharding_functor(const MapperContext ctx, const Release &release, const SelectShardingFunctorInput &input, SelectShardingFunctorOutput &output) override
void select_sharding_functor(const MapperContext ctx, const Acquire &acquire, const SelectShardingFunctorInput &input, SelectShardingFunctorOutput &output) override
void select_sharding_functor(const MapperContext ctx, const Close &close, const SelectShardingFunctorInput &input, SelectShardingFunctorOutput &output) override
void select_sharding_functor(const MapperContext ctx, const Fill &fill, const SelectShardingFunctorInput &input, SelectShardingFunctorOutput &output) override
void select_sharding_functor(const MapperContext ctx, const Copy &copy, const SelectShardingFunctorInput &input, SelectShardingFunctorOutput &output) override
void select_sharding_functor(const MapperContext ctx, const Partition &partition, const SelectShardingFunctorInput &input, SelectShardingFunctorOutput &output) override
const char * get_mapper_name(void) const override
Definition mapping.h:377
Definition mapping.h:342
Definition mapping.h:264
Definition mapping.h:112
Definition accessors.h:29
Definition mapping.h:1403
Definition mapping.h:2283
Definition mapping.h:1131
Definition mapping.h:1136
Definition mapping.h:783
Definition replay_mapper.h:43