Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[f2dace/dev, fortran] Instead of using parfor everywhere, give every transforms their unique short names. #1887

Draft
wants to merge 1 commit into
base: f2dace/dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions dace/frontend/fortran/ast_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2239,7 +2239,7 @@ def par_Decl_Range_Finder(node: ast_internal_classes.Array_Subscript_Node,
newbody.append(
ast_internal_classes.Decl_Stmt_Node(vardecl=[
ast_internal_classes.Symbol_Decl_Node(
name="tmp_parfor_" + str(count + len(rangepos) - 1), type="INTEGER", sizes=None, init=None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parDeclRangeFinder is called from many different transformations. Do you think this can still cause name collisions? if yes, then we can change it by passing a custom prefix from each transform

name="tmp_pdrf_" + str(count + len(rangepos) - 1), type="INTEGER", sizes=None, init=None,
parent=node.parent, line_number=node.line_number)
]))

Expand All @@ -2248,8 +2248,8 @@ def par_Decl_Range_Finder(node: ast_internal_classes.Array_Subscript_Node,
we need to adapt array accesses.
The main loop iterator is already initialized with the lower boundary of the dominating array.

Thus, if the offset is the same, the index is just "tmp_parfor".
Otherwise, it is "tmp_parfor - tmp_parfor_lower_boundary + our_lower_boundary"
Thus, if the offset is the same, the index is just "tmp_pdrf".
Otherwise, it is "tmp_pdrf - tmp_pdrf_lower_boundary + our_lower_boundary"
"""

if declaration:
Expand All @@ -2258,7 +2258,7 @@ def par_Decl_Range_Finder(node: ast_internal_classes.Array_Subscript_Node,
"""

indices.append(
ast_internal_classes.Name_Node(name="tmp_parfor_" + str(count + len(rangepos) - 1))
ast_internal_classes.Name_Node(name="tmp_pdrf_" + str(count + len(rangepos) - 1))
)
else:

Expand All @@ -2272,7 +2272,7 @@ def par_Decl_Range_Finder(node: ast_internal_classes.Array_Subscript_Node,

indices.append(
ast_internal_classes.BinOp_Node(
lval=ast_internal_classes.Name_Node(name="tmp_parfor_" + str(count + len(rangepos) - 1)),
lval=ast_internal_classes.Name_Node(name="tmp_pdrf_" + str(count + len(rangepos) - 1)),
op="+",
rval=ast_internal_classes.BinOp_Node(
lval=lower_boundary,
Expand Down Expand Up @@ -3742,20 +3742,20 @@ def visit_Execution_Part_Node(self, node: ast_internal_classes.Execution_Part_No
initrange = i[0]
finalrange = i[1]
init = ast_internal_classes.BinOp_Node(
lval=ast_internal_classes.Name_Node(name="tmp_parfor_" + str(self.count + range_index)),
lval=ast_internal_classes.Name_Node(name="tmp_ale_" + str(self.count + range_index)),
op="=",
rval=initrange,
line_number=child.line_number,parent=child.parent)
cond = ast_internal_classes.BinOp_Node(
lval=ast_internal_classes.Name_Node(name="tmp_parfor_" + str(self.count + range_index)),
lval=ast_internal_classes.Name_Node(name="tmp_ale_" + str(self.count + range_index)),
op="<=",
rval=finalrange,
line_number=child.line_number,parent=child.parent)
iter = ast_internal_classes.BinOp_Node(
lval=ast_internal_classes.Name_Node(name="tmp_parfor_" + str(self.count + range_index)),
lval=ast_internal_classes.Name_Node(name="tmp_ale_" + str(self.count + range_index)),
op="=",
rval=ast_internal_classes.BinOp_Node(
lval=ast_internal_classes.Name_Node(name="tmp_parfor_" + str(self.count + range_index)),
lval=ast_internal_classes.Name_Node(name="tmp_ale_" + str(self.count + range_index)),
op="+",
rval=ast_internal_classes.Int_Literal_Node(value="1"),parent=child.parent),
line_number=child.line_number,parent=child.parent)
Expand Down Expand Up @@ -3990,7 +3990,7 @@ def visit_Execution_Part_Node(self, node: ast_internal_classes.Execution_Part_No

dest_indices = copy.deepcopy(tmp_array.indices)
for idx, _, _ in tmp_array.noncontig_dims:
iter_var = ast_internal_classes.Name_Node(name=f"tmp_parfor_{tmp_array.counter}_{idx}")
iter_var = ast_internal_classes.Name_Node(name=f"tmp_pdncae_{tmp_array.counter}_{idx}")
dest_indices[idx] = iter_var

dest = ast_internal_classes.Array_Subscript_Node(
Expand All @@ -4003,7 +4003,7 @@ def visit_Execution_Part_Node(self, node: ast_internal_classes.Execution_Part_No
source_indices = copy.deepcopy(tmp_array.indices)
for idx, main_var, var in tmp_array.noncontig_dims:

iter_var = ast_internal_classes.Name_Node(name=f"tmp_parfor_{tmp_array.counter}_{idx}")
iter_var = ast_internal_classes.Name_Node(name=f"tmp_pdncae_{tmp_array.counter}_{idx}")

var.indices = [iter_var]
source_indices[idx] = main_var
Expand All @@ -4024,7 +4024,7 @@ def visit_Execution_Part_Node(self, node: ast_internal_classes.Execution_Part_No
initrange = ast_internal_classes.Int_Literal_Node(value="1")
finalrange = tmp_array.sizes[idx]

iter_var = ast_internal_classes.Name_Node(name=f"tmp_parfor_{tmp_array.counter}_{idx}")
iter_var = ast_internal_classes.Name_Node(name=f"tmp_pdncae_{tmp_array.counter}_{idx}")

node.parent.specification_part.specifications.append(
ast_internal_classes.Decl_Stmt_Node(vardecl=[
Expand Down
8 changes: 4 additions & 4 deletions dace/frontend/fortran/intrinsics.py
Original file line number Diff line number Diff line change
Expand Up @@ -714,20 +714,20 @@ def visit_Execution_Part_Node(self, node: ast_internal_classes.Execution_Part_No
initrange = i[0]
finalrange = i[1]
init = ast_internal_classes.BinOp_Node(
lval=ast_internal_classes.Name_Node(name="tmp_parfor_" + str(self.count + range_index)),
lval=ast_internal_classes.Name_Node(name="tmp_lbrt_" + str(self.count + range_index)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - this is a base used by many intrinsics. Two different intrinsic replacements can emit the same tmp_lbrt_0, for example.

If this is a problem for name collision, then I will change the implementation to pass a custom prefix from each intrinsic.

op="=",
rval=initrange,
line_number=child.line_number)
cond = ast_internal_classes.BinOp_Node(
lval=ast_internal_classes.Name_Node(name="tmp_parfor_" + str(self.count + range_index)),
lval=ast_internal_classes.Name_Node(name="tmp_lbrt_" + str(self.count + range_index)),
op="<=",
rval=finalrange,
line_number=child.line_number)
iter = ast_internal_classes.BinOp_Node(
lval=ast_internal_classes.Name_Node(name="tmp_parfor_" + str(self.count + range_index)),
lval=ast_internal_classes.Name_Node(name="tmp_lbrt_" + str(self.count + range_index)),
op="=",
rval=ast_internal_classes.BinOp_Node(
lval=ast_internal_classes.Name_Node(name="tmp_parfor_" + str(self.count + range_index)),
lval=ast_internal_classes.Name_Node(name="tmp_lbrt_" + str(self.count + range_index)),
op="+",
rval=ast_internal_classes.Int_Literal_Node(value="1")),
line_number=child.line_number)
Expand Down