Skip to content

Commit

Permalink
Revert "Revert "regent: Allow r.volume on regions.""
Browse files Browse the repository at this point in the history
This reverts commit e237d08.
  • Loading branch information
magnatelee committed Nov 30, 2018
1 parent c260b40 commit 73fc0dc
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 20 deletions.
3 changes: 2 additions & 1 deletion language/src/regent/ast_util.t
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function ast_util.mk_expr_bounds_access(value)
local expr_type = std.as_read(value.expr_type)
local index_type
if std.is_region(expr_type) then
index_type = expr_type:ispace().index_type
return ast_util.mk_expr_bounds_access(
ast_util.mk_expr_field_access(value, "ispace", expr_type:ispace()))
elseif std.is_ispace(expr_type) then
index_type = expr_type.index_type
else
Expand Down
10 changes: 2 additions & 8 deletions language/src/regent/codegen.t
Original file line number Diff line number Diff line change
Expand Up @@ -2047,17 +2047,11 @@ function codegen.expr_field_access(cx, node)
`([expr_type] { impl = [value.value].impl.index_space }),
expr_type),
expr_type)
elseif (std.is_ispace(value_type) or std.is_region(value_type)) and
field_name == "bounds" then
elseif std.is_ispace(value_type) and field_name == "bounds" then
local value = codegen.expr(cx, node.value):read(cx)
local expr_type = std.as_read(node.expr_type)
assert(expr_type.is_rect_type)
local bounds
if std.is_ispace(value_type) then
bounds = cx:ispace(value_type).bounds
else
bounds = cx:ispace(value_type:ispace()).bounds
end
local bounds = cx:ispace(value_type).bounds

local actions = quote
[value.actions]
Expand Down
8 changes: 5 additions & 3 deletions language/src/regent/parallelize_tasks.t
Original file line number Diff line number Diff line change
Expand Up @@ -2301,10 +2301,12 @@ local function rewrite_metadata_access(task_cx)
return function(node, continuation)
if node:is(ast.typed.expr.FieldAccess) and
node.field_name == "bounds" and
std.is_region(std.as_read(node.value.expr_type)) then
assert(node.value:is(ast.typed.expr.ID))
node.value:is(ast.typed.expr.FieldAccess) and
node.value.field_name == "ispace" and
std.is_region(std.as_read(node.value.value.expr_type)) then
assert(node.value.value:is(ast.typed.expr.ID))
local metadata_params =
task_cx:find_metadata_parameters(node.value.value)
task_cx:find_metadata_parameters(node.value.value.value)
if metadata_params then
return ast_util.mk_expr_id(metadata_params.bounds)
else
Expand Down
19 changes: 12 additions & 7 deletions language/src/regent/type_check.t
Original file line number Diff line number Diff line change
Expand Up @@ -547,13 +547,18 @@ function type_check.expr_field_access(cx, node)
elseif std.is_ispace(std.as_read(unpack_type)) and node.field_name == "volume" then
-- Volume can be retrieved on any ispace.
field_type = int64
elseif std.is_region(std.as_read(unpack_type)) and node.field_name == "bounds" then
local index_type = std.as_read(unpack_type):ispace().index_type
if index_type:is_opaque() then
report.error(node, "no field '" .. node.field_name .. "' in type " ..
tostring(std.as_read(unpack_type)))
end
field_type = std.rect_type(index_type)
elseif std.is_region(std.as_read(unpack_type)) and (node.field_name == "bounds" or node.field_name == "volume") then
-- Index space fields can also be retrieved through a region.
return type_check.expr(
cx,
node {
value = ast.specialized.expr.FieldAccess {
value = node.value,
field_name = "ispace",
span = node.value.span,
annotations = node.value.annotations,
}
})
elseif std.is_partition(std.as_read(unpack_type)) and node.field_name == "colors" then
field_type = std.as_read(unpack_type):colors()
elseif std.type_is_opaque_to_field_accesses(std.as_read(unpack_type)) then
Expand Down
2 changes: 1 addition & 1 deletion language/tests/regent/compile_fail/invalid_bounds2.rg
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
-- limitations under the License.

-- fails-with:
-- invalid_bounds2.rg:27: no field 'bounds' in type region(int32)
-- invalid_bounds2.rg:27: no field 'bounds' in type ispace(ptr)
-- var bounds = r.bounds
-- ^

Expand Down
33 changes: 33 additions & 0 deletions language/tests/regent/run_pass/region_volume.rg
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-- Copyright 2018 Stanford University
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

import "regent"

local c = regentlib.c

task main()
var is = ispace(int2d, {4, 8})
var r = region(is, int)
var p = partition(equal, r, ispace(int2d, {2, 2}))
var r00 = p[{0, 0}]
var r11 = p[{1, 1}]
var r_volume = r.volume
var r00_volume = r00.volume
var r11_volume = r11.volume

regentlib.assert(r_volume == 32, "test failed")
regentlib.assert(r00_volume == 8, "test failed")
regentlib.assert(r11_volume == 8, "test failed")
end
regentlib.start(main)

0 comments on commit 73fc0dc

Please sign in to comment.