18 #include <flecsi-config.h> 20 #if !defined(__FLECSI_PRIVATE__) 21 #error Do not include this file directly! 24 #include "../backend.hh" 26 #if !defined(FLECSI_ENABLE_LEGION) 27 #error FLECSI_ENABLE_LEGION not defined! This file depends on Legion! 31 #include <legion/legion_mapping.h> 32 #include <mappers/default_mapper.h> 36 inline log::devel_tag legion_mapper_tag(
"legion_mapper");
60 Legion::Runtime * _runtime,
61 Legion::Processor local)
62 : Legion::Mapping::DefaultMapper(_runtime->get_mapper_runtime(),
67 using legion_machine = Legion::Machine;
68 using legion_proc = Legion::Processor;
70 legion_machine::ProcessorQuery pq =
71 legion_machine::ProcessorQuery(machine).same_address_space_as(local);
72 for(legion_machine::ProcessorQuery::iterator pqi = pq.begin();
76 if(p.kind() == legion_proc::LOC_PROC)
77 local_cpus.push_back(p);
78 else if(p.kind() == legion_proc::TOC_PROC)
79 local_gpus.push_back(p);
83 std::map<Realm::Memory::Kind, Realm::Memory> & mem_map = proc_mem_map[p];
85 legion_machine::MemoryQuery mq =
86 legion_machine::MemoryQuery(machine).has_affinity_to(p);
87 for(legion_machine::MemoryQuery::iterator mqi = mq.begin();
90 Realm::Memory m = *mqi;
91 mem_map[m.kind()] = m;
93 if(m.kind() == Realm::Memory::SYSTEM_MEM)
100 flog_devel(info) <<
"Mapper constructor" << std::endl
101 <<
"\tlocal: " << local << std::endl
102 <<
"\tcpus: " << local_cpus.size() << std::endl
103 <<
"\tgpus: " << local_gpus.size() << std::endl
104 <<
"\tsysmem: " << local_sysmem << std::endl;
113 Legion::LayoutConstraintID default_policy_select_layout_constraints(
114 Legion::Mapping::MapperContext ctx,
116 const Legion::RegionRequirement &,
117 Legion::Mapping::DefaultMapper::MappingKind,
119 bool & force_new_instances) {
123 force_new_instances =
false;
124 std::vector<Legion::DimensionKind> ordering;
125 ordering.push_back(Legion::DimensionKind::DIM_Y);
126 ordering.push_back(Legion::DimensionKind::DIM_X);
127 ordering.push_back(Legion::DimensionKind::DIM_F);
128 Legion::OrderingConstraint ordering_constraint(
130 Legion::LayoutConstraintSet layout_constraint;
131 layout_constraint.add_constraint(ordering_constraint);
134 Legion::LayoutConstraintID result =
135 runtime->register_layout(ctx, layout_constraint);
152 virtual void map_task(
const Legion::Mapping::MapperContext ctx,
153 const Legion::Task & task,
154 const Legion::Mapping::Mapper::MapTaskInput & input,
155 Legion::Mapping::Mapper::MapTaskOutput & output) {
156 DefaultMapper::map_task(ctx, task, input, output);
158 if((task.tag == FLECSI_MAPPER_COMPACTED_STORAGE) &&
159 (task.regions.size() > 0)) {
161 Legion::Memory target_mem =
162 DefaultMapper::default_policy_select_target_memory(
163 ctx, task.target_proc, task.regions[0]);
169 Legion::LayoutConstraintSet layout_constraints;
171 layout_constraints.add_constraint(Legion::SpecializedConstraint());
172 layout_constraints.add_constraint(Legion::OrderingConstraint());
174 layout_constraints.add_constraint(
175 Legion::MemoryConstraint(target_mem.kind()));
177 std::vector<Legion::FieldID> all_fields;
178 layout_constraints.add_constraint(Legion::FieldConstraint());
181 Legion::ColocationConstraint colocation_constraints;
183 for(
size_t indx = 0; indx < task.regions.size(); indx++) {
185 Legion::Mapping::PhysicalInstance result;
186 std::vector<Legion::LogicalRegion> regions;
189 if(task.regions[indx].tag == FLECSI_MAPPER_EXCLUSIVE_LR) {
192 "ERROR:: wrong number of regions passed to the task wirth \ 193 the tag = FLECSI_MAPPER_COMPACTED_STORAGE");
196 "ERROR:: pasing not existing REGION to the mapper");
197 regions.push_back(task.regions[indx].region);
198 regions.push_back(task.regions[indx + 1].region);
199 regions.push_back(task.regions[indx + 2].region);
201 flog_assert(runtime->find_or_create_physical_instance(ctx,
209 "FLeCSI mapper failed to allocate instance");
211 for(
size_t j = 0; j < 3; j++) {
212 output.chosen_instances[indx + j].push_back(result);
219 regions.push_back(task.regions[indx].region);
221 flog_assert(runtime->find_or_create_physical_instance(ctx,
229 "FLeCSI mapper failed to allocate instance");
231 output.chosen_instances[indx].push_back(result);
240 virtual void slice_task(
const Legion::Mapping::MapperContext ctx,
241 const Legion::Task & task,
242 const Legion::Mapping::Mapper::SliceTaskInput & input,
243 Legion::Mapping::Mapper::SliceTaskOutput & output) {
246 case FLECSI_MAPPER_SUBRANK_LAUNCH:
248 assert(input.domain.get_dim() == 1);
250 output.slices.resize(1);
251 output.slices[0].domain = input.domain;
252 output.slices[0].proc = task.target_proc;
255 case FLECSI_MAPPER_FORCE_RANK_MATCH: {
257 assert(input.domain.get_dim() == 1);
258 LegionRuntime::Arrays::Rect<1> r = input.domain.get_rect<1>();
262 std::map<int, Legion::Processor> targets;
264 Legion::Machine::ProcessorQuery pq =
265 Legion::Machine::ProcessorQuery(machine).only_kind(
266 Legion::Processor::LOC_PROC);
267 for(Legion::Machine::ProcessorQuery::iterator it = pq.begin();
270 Legion::Processor p = *it;
271 int a = p.address_space();
272 if(targets.count(a) == 0)
276 output.slices.resize(1);
277 for(
int a = r.lo[0]; a <= r.hi[0]; a++) {
278 assert(targets.count(a) > 0);
279 output.slices[0].domain =
280 Legion::Rect<1>(a, a);
281 output.slices[0].proc = targets[a];
287 DefaultMapper::slice_task(ctx, task, input, output);
292 std::map<Legion::Processor, std::map<Realm::Memory::Kind, Realm::Memory>>
294 Realm::Memory local_sysmem;
295 Realm::Machine machine;
307 Legion::HighLevelRuntime * rt,
308 const std::set<Legion::Processor> & local_procs) {
309 for(std::set<Legion::Processor>::const_iterator it = local_procs.begin();
310 it != local_procs.end();
313 rt->replace_default_mapper(mapper, *it);
virtual void map_task(const Legion::Mapping::MapperContext ctx, const Legion::Task &task, const Legion::Mapping::Mapper::MapTaskInput &input, Legion::Mapping::Mapper::MapTaskOutput &output)
Definition: mapper.hh:152
mpi_mapper_t(Legion::Machine machine, Legion::Runtime *_runtime, Legion::Processor local)
Definition: mapper.hh:59
#define flog_assert(test, message)
Definition: flog.hh:411
void mapper_registration(Legion::Machine machine, Legion::HighLevelRuntime *rt, const std::set< Legion::Processor > &local_procs)
Definition: mapper.hh:306
virtual ~mpi_mapper_t()
Definition: mapper.hh:111
Definition: control.hh:31