Skip to content

Commit

Permalink
legion, regent: Add interface for task local regions, do nothing for …
Browse files Browse the repository at this point in the history
…them yet
  • Loading branch information
magnatelee committed Apr 20, 2018
1 parent b6b28e9 commit 1370f68
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 51 deletions.
2 changes: 1 addition & 1 deletion language/examples/manual_capi.rg
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ terra top_level_task(task : c.legion_task_t,
var is = c.legion_index_space_create(runtime, ctx, 5)
var fs = c.legion_field_space_create(runtime, ctx)
var r = c.legion_logical_region_create(runtime, ctx, is, fs)
var r = c.legion_logical_region_create(runtime, ctx, is, fs, true)
var ptr1 : c.legion_ptr_t, ptr2 : c.legion_ptr_t
var f1 : c.legion_field_id_t, f2 : c.legion_field_id_t
Expand Down
2 changes: 1 addition & 1 deletion language/examples/manual_capi_1d.rg
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ terra top_level_task(task : c.legion_task_t,
})
var is = c.legion_index_space_create_domain(runtime, ctx, d)
var fs = c.legion_field_space_create(runtime, ctx)
var r = c.legion_logical_region_create(runtime, ctx, is, fs)
var r = c.legion_logical_region_create(runtime, ctx, is, fs, true)
do
var fsa = c.legion_field_allocator_create(runtime, ctx, fs)
Expand Down
2 changes: 1 addition & 1 deletion language/examples/manual_capi_fields_after_region.rg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ terra top_level_task(task : c.legion_task_t,
var is = c.legion_index_space_create(runtime, ctx, 5)
var fs = c.legion_field_space_create(runtime, ctx)
var r = c.legion_logical_region_create(runtime, ctx, is, fs)
var r = c.legion_logical_region_create(runtime, ctx, is, fs, true)
var ptr1 : c.legion_ptr_t, ptr2 : c.legion_ptr_t
var f1 : c.legion_field_id_t, f2 : c.legion_field_id_t
Expand Down
2 changes: 1 addition & 1 deletion language/examples/manual_capi_reduce.rg
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ terra top_level_task(task : c.legion_task_t,
var is = c.legion_index_space_create(runtime, ctx, 5)
var fs = c.legion_field_space_create(runtime, ctx)
var r = c.legion_logical_region_create(runtime, ctx, is, fs)
var r = c.legion_logical_region_create(runtime, ctx, is, fs, true)
var ptr1 : c.legion_ptr_t, ptr2 : c.legion_ptr_t
var f1 : c.legion_field_id_t, f2 : c.legion_field_id_t
Expand Down
4 changes: 2 additions & 2 deletions language/examples/manual_capi_single_task_multile_regions.rg
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ terra top_level_task(task : c.legion_task_t,
c.legion_field_allocator_destroy(allocator)
end
var lr1 =
c.legion_logical_region_create(runtime, ctx, is1, fs1)
c.legion_logical_region_create(runtime, ctx, is1, fs1, true)
var is2 = c.legion_index_space_create(runtime, ctx, 5)
var fs2 = c.legion_field_space_create(runtime, ctx)
Expand All @@ -66,7 +66,7 @@ terra top_level_task(task : c.legion_task_t,
c.legion_field_allocator_destroy(allocator)
end
var lr2 =
c.legion_logical_region_create(runtime, ctx, is2, fs2)
c.legion_logical_region_create(runtime, ctx, is2, fs2, true)
var arg_nil = c.legion_task_argument_t { args = nil, arglen = 0 }
Expand Down
4 changes: 2 additions & 2 deletions language/src/regent/codegen.t
Original file line number Diff line number Diff line change
Expand Up @@ -3543,7 +3543,7 @@ function codegen.expr_region(cx, node)
end)]
[fs_naming_actions];
c.legion_field_allocator_destroy(fsa)
var [lr] = c.legion_logical_region_create([cx.runtime], [cx.context], [is], [fs])
var [lr] = c.legion_logical_region_create([cx.runtime], [cx.context], [is], [fs], true)
var [r] = [region_type]{ impl = [lr] }
end
local tag = terralib.newsymbol(c.legion_mapping_tag_id_t, "tag")
Expand Down Expand Up @@ -4125,7 +4125,7 @@ function codegen.expr_list_duplicate_partition(cx, node)
var color = [indices_type:data(indices.value)][i]
var orig_r = [get_partition_subregion(cx, partition, color)]
var r = c.legion_logical_region_create(
[cx.runtime], [cx.context], orig_r.index_space, orig_r.field_space)
[cx.runtime], [cx.context], orig_r.index_space, orig_r.field_space, true)
var new_root = c.legion_logical_partition_get_logical_subregion_by_tree(
[cx.runtime], orig_r.index_space, orig_r.field_space, r.tree_id)

Expand Down
6 changes: 4 additions & 2 deletions runtime/legion.h
Original file line number Diff line number Diff line change
Expand Up @@ -4500,12 +4500,14 @@ namespace Legion {
* @return handle for the logical region created
*/
LogicalRegion create_logical_region(Context ctx, IndexSpace index,
FieldSpace fields);
FieldSpace fields,
bool task_local = false);
// Template version
template<int DIM, typename COORD_T>
LogicalRegionT<DIM,COORD_T> create_logical_region(Context ctx,
IndexSpaceT<DIM,COORD_T> index,
FieldSpace fields);
FieldSpace fields,
bool task_local = false);
/**
* Destroy a logical region and all of its logical sub-regions.
* @param ctx enclosing task context
Expand Down
4 changes: 2 additions & 2 deletions runtime/legion/legion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5330,10 +5330,10 @@ namespace Legion {

//--------------------------------------------------------------------------
LogicalRegion Runtime::create_logical_region(Context ctx,
IndexSpace index, FieldSpace fields)
IndexSpace index, FieldSpace fields, bool task_local)
//--------------------------------------------------------------------------
{
return runtime->create_logical_region(ctx, index, fields);
return runtime->create_logical_region(ctx, index, fields, task_local);
}

//--------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions runtime/legion/legion.inl
Original file line number Diff line number Diff line change
Expand Up @@ -7577,11 +7577,11 @@ namespace Legion {
//--------------------------------------------------------------------------
template<int DIM, typename T>
LogicalRegionT<DIM,T> Runtime::create_logical_region(Context ctx,
IndexSpaceT<DIM,T> index, FieldSpace fields)
IndexSpaceT<DIM,T> index, FieldSpace fields, bool task_local)
//--------------------------------------------------------------------------
{
return LogicalRegionT<DIM,T>(create_logical_region(ctx,
IndexSpace(index), fields));
IndexSpace(index), fields, task_local));
}

//--------------------------------------------------------------------------
Expand Down
6 changes: 4 additions & 2 deletions runtime/legion/legion_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1515,14 +1515,16 @@ legion_logical_region_t
legion_logical_region_create(legion_runtime_t runtime_,
legion_context_t ctx_,
legion_index_space_t index_,
legion_field_space_t fields_)
legion_field_space_t fields_,
bool task_local)
{
Runtime *runtime = CObjectWrapper::unwrap(runtime_);
Context ctx = CObjectWrapper::unwrap(ctx_)->context();
IndexSpace index = CObjectWrapper::unwrap(index_);
FieldSpace fields = CObjectWrapper::unwrap(fields_);

LogicalRegion r = runtime->create_logical_region(ctx, index, fields);
LogicalRegion r =
runtime->create_logical_region(ctx, index, fields, task_local);
return CObjectWrapper::wrap(r);
}

Expand Down
3 changes: 2 additions & 1 deletion runtime/legion/legion_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,8 @@ extern "C" {
legion_logical_region_create(legion_runtime_t runtime,
legion_context_t ctx,
legion_index_space_t index,
legion_field_space_t fields);
legion_field_space_t fields,
bool task_local);

/**
* @param handle Caller must have ownership of parameter `handle`.
Expand Down
35 changes: 21 additions & 14 deletions runtime/legion/legion_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ namespace Legion {
}

//--------------------------------------------------------------------------
void TaskContext::register_region_creation(LogicalRegion handle)
void TaskContext::register_region_creation(LogicalRegion handle,
bool task_local)
//--------------------------------------------------------------------------
{
// Create a new logical region
Expand All @@ -218,7 +219,7 @@ namespace Legion {
#ifdef DEBUG_LEGION
assert(created_regions.find(handle) == created_regions.end());
#endif
created_regions.insert(handle);
created_regions[handle] = task_local;
add_created_region(handle);
}

Expand All @@ -231,7 +232,8 @@ namespace Legion {
// be returning values from the utility processor
{
AutoLock priv_lock(privilege_lock);
std::set<LogicalRegion>::iterator finder = created_regions.find(handle);
std::map<LogicalRegion,bool>::iterator finder =
created_regions.find(handle);
// See if we created this region, if so remove it from the list
// of created regions, otherwise add it to the list of deleted
// regions to flow backwards
Expand Down Expand Up @@ -434,18 +436,18 @@ namespace Legion {

//--------------------------------------------------------------------------
void TaskContext::register_region_creations(
const std::set<LogicalRegion> &regs)
const std::map<LogicalRegion,bool> &regs)
//--------------------------------------------------------------------------
{
AutoLock priv_lock(privilege_lock);
for (std::set<LogicalRegion>::const_iterator it = regs.begin();
for (std::map<LogicalRegion,bool>::const_iterator it = regs.begin();
it != regs.end(); it++)
{
#ifdef DEBUG_LEGION
assert(created_regions.find(*it) == created_regions.end());
assert(created_regions.find(it->first) == created_regions.end());
#endif
created_regions.insert(*it);
add_created_region(*it);
created_regions[it->first] = it->second;
add_created_region(it->first);
}
}

Expand All @@ -460,7 +462,8 @@ namespace Legion {
for (std::set<LogicalRegion>::const_iterator it = regs.begin();
it != regs.end(); it++)
{
std::set<LogicalRegion>::iterator finder = created_regions.find(*it);
std::map<LogicalRegion,bool>::iterator finder =
created_regions.find(*it);
if (finder != created_regions.end())
{
created_regions.erase(finder);
Expand Down Expand Up @@ -3505,7 +3508,8 @@ namespace Legion {
//--------------------------------------------------------------------------
LogicalRegion InnerContext::create_logical_region(RegionTreeForest *forest,
IndexSpace index_space,
FieldSpace field_space)
FieldSpace field_space,
bool task_local)
//--------------------------------------------------------------------------
{
AutoRuntimeCall call(this);
Expand All @@ -3522,7 +3526,7 @@ namespace Legion {

forest->create_logical_region(region);
// Register the creation of a top-level region with the context
register_region_creation(region);
register_region_creation(region, task_local);
return region;
}

Expand Down Expand Up @@ -8135,7 +8139,8 @@ namespace Legion {
//--------------------------------------------------------------------------
LogicalRegion LeafContext::create_logical_region(RegionTreeForest *forest,
IndexSpace index_space,
FieldSpace field_space)
FieldSpace field_space,
bool task_local)
//--------------------------------------------------------------------------
{
REPORT_LEGION_ERROR(ERROR_ILLEGAL_REGION_CREATION,
Expand Down Expand Up @@ -9350,10 +9355,12 @@ namespace Legion {
//--------------------------------------------------------------------------
LogicalRegion InlineContext::create_logical_region(RegionTreeForest *forest,
IndexSpace index_space,
FieldSpace field_space)
FieldSpace field_space,
bool task_local)
//--------------------------------------------------------------------------
{
return enclosing->create_logical_region(forest, index_space, field_space);
return enclosing->create_logical_region(forest, index_space, field_space,
task_local);
}

//--------------------------------------------------------------------------
Expand Down
16 changes: 10 additions & 6 deletions runtime/legion/legion_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ namespace Legion {
const std::set<FieldID> &to_free) = 0;
virtual LogicalRegion create_logical_region(RegionTreeForest *forest,
IndexSpace index_space,
FieldSpace field_space) = 0;
FieldSpace field_space,
bool task_local) = 0;
virtual void destroy_logical_region(LogicalRegion handle) = 0;
virtual void destroy_logical_partition(LogicalPartition handle) = 0;
virtual FieldAllocator create_field_allocator(Legion::Runtime *external,
Expand Down Expand Up @@ -385,7 +386,7 @@ namespace Legion {
void log_created_requirements(void);
public: // Privilege tracker methods
virtual void register_region_creations(
const std::set<LogicalRegion> &regions);
const std::map<LogicalRegion,bool> &regions);
virtual void register_region_deletions(
const std::set<LogicalRegion> &regions);
public:
Expand All @@ -409,7 +410,7 @@ namespace Legion {
virtual void register_index_partition_deletions(
const std::set<IndexPartition> &parts);
public:
void register_region_creation(LogicalRegion handle);
void register_region_creation(LogicalRegion handle, bool task_local);
void register_region_deletion(LogicalRegion handle);
public:
void register_field_creation(FieldSpace space, FieldID fid, bool local);
Expand Down Expand Up @@ -848,7 +849,8 @@ namespace Legion {
const std::set<FieldID> &to_free);
virtual LogicalRegion create_logical_region(RegionTreeForest *forest,
IndexSpace index_space,
FieldSpace field_space);
FieldSpace field_space,
bool task_local);
virtual void destroy_logical_region(LogicalRegion handle);
virtual void destroy_logical_partition(LogicalPartition handle);
virtual FieldAllocator create_field_allocator(Legion::Runtime *external,
Expand Down Expand Up @@ -1448,7 +1450,8 @@ namespace Legion {
const std::set<FieldID> &to_free);
virtual LogicalRegion create_logical_region(RegionTreeForest *forest,
IndexSpace index_space,
FieldSpace field_space);
FieldSpace field_space,
bool task_local);
virtual void destroy_logical_region(LogicalRegion handle);
virtual void destroy_logical_partition(LogicalPartition handle);
virtual FieldAllocator create_field_allocator(Legion::Runtime *external,
Expand Down Expand Up @@ -1757,7 +1760,8 @@ namespace Legion {
const std::set<FieldID> &to_free);
virtual LogicalRegion create_logical_region(RegionTreeForest *forest,
IndexSpace index_space,
FieldSpace field_space);
FieldSpace field_space,
bool task_local);
virtual void destroy_logical_region(LogicalRegion handle);
virtual void destroy_logical_partition(LogicalPartition handle);
virtual FieldAllocator create_field_allocator(Legion::Runtime *external,
Expand Down
19 changes: 11 additions & 8 deletions runtime/legion/legion_tasks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,11 @@ namespace Legion {
rez.serialize<size_t>(created_regions.size());
if (!created_regions.empty())
{
for (std::set<LogicalRegion>::const_iterator it =
for (std::map<LogicalRegion,bool>::const_iterator it =
created_regions.begin(); it != created_regions.end(); it++)
{
rez.serialize(*it);
rez.serialize(it->first);
rez.serialize<bool>(it->second);
}
}
rez.serialize<size_t>(deleted_regions.size());
Expand Down Expand Up @@ -240,12 +241,14 @@ namespace Legion {
derez.deserialize(num_created_regions);
if (num_created_regions > 0)
{
std::set<LogicalRegion> created_regions;
std::map<LogicalRegion,bool> created_regions;
for (unsigned idx = 0; idx < num_created_regions; idx++)
{
LogicalRegion reg;
bool local;
derez.deserialize(reg);
created_regions.insert(reg);
derez.deserialize(local);
created_regions[reg] = local;
}
target->register_region_creations(created_regions);
}
Expand Down Expand Up @@ -8733,17 +8736,17 @@ namespace Legion {

//--------------------------------------------------------------------------
void SliceTask::register_region_creations(
const std::set<LogicalRegion> &regs)
const std::map<LogicalRegion,bool> &regs)
//--------------------------------------------------------------------------
{
AutoLock o_lock(op_lock);
for (std::set<LogicalRegion>::const_iterator it = regs.begin();
for (std::map<LogicalRegion,bool>::const_iterator it = regs.begin();
it != regs.end(); it++)
{
#ifdef DEBUG_LEGION
assert(created_regions.find(*it) == created_regions.end());
assert(created_regions.find(it->first) == created_regions.end());
#endif
created_regions.insert(*it);
created_regions[it->first] = it->second;
}
}

Expand Down
7 changes: 4 additions & 3 deletions runtime/legion/legion_tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Legion {
ResourceTracker& operator=(const ResourceTracker &rhs);
public:
virtual void register_region_creations(
const std::set<LogicalRegion> &regions) = 0;
const std::map<LogicalRegion,bool> &regions) = 0;
virtual void register_region_deletions(
const std::set<LogicalRegion> &regions) = 0;
public:
Expand Down Expand Up @@ -76,7 +76,8 @@ namespace Legion {
static void unpack_privilege_state(Deserializer &derez,
ResourceTracker *target);
protected:
std::set<LogicalRegion> created_regions;
std::map<LogicalRegion,
bool/*local*/> created_regions;
std::map<std::pair<FieldSpace,FieldID>,
bool/*local*/> created_fields;
std::set<FieldSpace> created_field_spaces;
Expand Down Expand Up @@ -1081,7 +1082,7 @@ namespace Legion {
static void handle_slice_return(Runtime *rt, Deserializer &derez);
public: // Privilege tracker methods
virtual void register_region_creations(
const std::set<LogicalRegion> &regions);
const std::map<LogicalRegion,bool> &regions);
virtual void register_region_deletions(
const std::set<LogicalRegion> &regions);
public:
Expand Down
Loading

0 comments on commit 1370f68

Please sign in to comment.