@@ -28,6 +28,7 @@ using namespace Legion::Mapping;
2828
2929enum TaskIDs {
3030 TID_TOP,
31+ TID_INIT,
3132 TID_LEAF,
3233 TID_DUMMY,
3334};
@@ -97,6 +98,20 @@ void get_base_and_size(Runtime *runtime,
9798 bytes = rect.volume ();
9899}
99100
101+ void init (const Task *task,
102+ const std::vector<PhysicalRegion> ®ions,
103+ Context ctx, Runtime *runtime)
104+ {
105+ log_taskbench.info (" Init at point %lld" , task->index_point [0 ]);
106+
107+ char *scratch_ptr = NULL ;
108+ size_t scratch_bytes = 0 ;
109+ Rect<1 > scratch_rect = runtime->get_index_space_domain (
110+ regions[0 ].get_logical_region ().get_index_space ());
111+ get_base_and_size (runtime, regions[0 ], task->regions [0 ], scratch_rect, scratch_ptr, scratch_bytes);
112+ TaskGraph::prepare_scratch (scratch_ptr, scratch_bytes);
113+ }
114+
100115void leaf (const Task *task,
101116 const std::vector<PhysicalRegion> ®ions,
102117 Context ctx, Runtime *runtime)
@@ -160,6 +175,8 @@ struct LegionApp : public App {
160175
161176 void execute_timestep (size_t i, long t);
162177
178+ void init (size_t i);
179+
163180 void issue_execution_fence_and_block ();
164181
165182private:
@@ -269,6 +286,10 @@ void LegionApp::run()
269286 display ();
270287 }
271288
289+ for (size_t idx = 0 ; idx < graphs.size (); ++idx) {
290+ init (idx);
291+ }
292+
272293 execute_main_loop (); // warm-up
273294
274295 issue_execution_fence_and_block ();
@@ -329,6 +350,29 @@ void LegionApp::execute_main_loop()
329350 }
330351}
331352
353+ void LegionApp::init (size_t idx)
354+ {
355+ const TaskGraph &g = graphs[idx];
356+
357+ Rect<1 > bounds (0 , g.max_width -1 );
358+
359+ if (g.scratch_bytes_per_task != 0 ) {
360+ for (long i = 0 ; i < num_fields; ++i) {
361+ FieldID fout (FID_FIRST + i);
362+ IndexLauncher launcher (TID_INIT, bounds, TaskArgument (), ArgumentMap ());
363+ MappingTagID tag = exact_instance ? Legion::Mapping::DefaultMapper::EXACT_REGION : 0 ;
364+ const LogicalRegionT<1 > &sratch_region = scratch_regions[idx];
365+ const LogicalPartitionT<1 > &scratch = scratch_partitions[idx];
366+ launcher.add_region_requirement (
367+ RegionRequirement (scratch, 0 /* default projection */ ,
368+ READ_WRITE, EXCLUSIVE, sratch_region, tag)
369+ .add_field (fout));
370+
371+ runtime->execute_index_space (ctx, launcher);
372+ }
373+ }
374+ }
375+
332376void LegionApp::execute_timestep (size_t idx, long t)
333377{
334378 const TaskGraph &g = graphs[idx];
@@ -372,7 +416,7 @@ void LegionApp::execute_timestep(size_t idx, long t)
372416 const LogicalPartitionT<1 > &scratch = scratch_partitions[idx];
373417 launcher.add_region_requirement (
374418 RegionRequirement (scratch, 0 /* default projection */ ,
375- WRITE_DISCARD , EXCLUSIVE, sratch_region, tag)
419+ READ_WRITE , EXCLUSIVE, sratch_region, tag)
376420 .add_field (fout));
377421 }
378422
@@ -419,6 +463,13 @@ int main(int argc, char **argv)
419463 Runtime::preregister_task_variant<top>(registrar, " top" );
420464 }
421465
466+ {
467+ TaskVariantRegistrar registrar (TID_INIT, " init" );
468+ registrar.add_constraint (ProcessorConstraint (Processor::LOC_PROC));
469+ registrar.set_leaf ();
470+ Runtime::preregister_task_variant<init>(registrar, " init" );
471+ }
472+
422473 {
423474 TaskVariantRegistrar registrar (TID_LEAF, " leaf" );
424475 registrar.add_constraint (ProcessorConstraint (Processor::LOC_PROC));
0 commit comments