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

Add loop regions to the frontend's capabilities #1475

Merged
merged 77 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
b6e9000
Add loop regions to the frontend's capabilities
phschaad Dec 11, 2023
ced035b
Merge branch 'master' into loop_architecture_pt_3
phschaad Dec 11, 2023
0bb6223
Merge branch 'master' into loop_architecture_pt_3
phschaad Dec 12, 2023
d26c507
Bugfixes
phschaad Dec 12, 2023
b83d05d
Fix data dependent while loop generation
phschaad Dec 13, 2023
55acc41
Merge remote-tracking branch 'origin/master' into loop_architecture_pt_3
phschaad Dec 13, 2023
35e4272
Make state propagation test more robust to SDFG changes
phschaad Dec 13, 2023
6b4d1be
Fixes
phschaad Dec 13, 2023
83cf2d0
newast fixes
phschaad Dec 13, 2023
1393b19
Change property type and add better type hinting
phschaad Dec 14, 2023
864c607
Merge branch 'master' into loop_architecture_pt_3
phschaad Dec 20, 2023
b317a12
Allow orelse and break continue
phschaad Dec 20, 2023
240ff79
Fix free symbols for loops
phschaad Dec 20, 2023
016b21c
Merge branch 'master' into loop_architecture_pt_3
phschaad Jan 17, 2024
28177c7
Merge remote-tracking branch 'origin/master' into loop_architecture_pt_3
phschaad Jan 24, 2024
69eaf92
Provide pass compatibility check for passes and transformations
phschaad Jan 24, 2024
975d79e
Update passes and transformations
phschaad Jan 25, 2024
80e96bb
Make sure auto opt "works"
phschaad Jan 26, 2024
9b7f840
Refactor SDFG List to CFG List
phschaad Jan 29, 2024
bc8679f
Make sure no old style `sdfg_list` calls remain
phschaad Jan 29, 2024
68a6b62
Fix deserializataion for control flow regions
phschaad Jan 29, 2024
40cd861
Fix deserialization
phschaad Jan 29, 2024
482c30f
Remove legacy calls to sdfg_list
phschaad Jan 29, 2024
ae2e068
Merge branch 'refactor_sdfg_list_to_cfg_list' into loop_architecture_…
phschaad Jan 29, 2024
e596496
Fix transformation architecture
phschaad Jan 29, 2024
27a350e
Address review comments, update docs
phschaad Jan 29, 2024
5aeec96
Fix blunder
phschaad Jan 29, 2024
7e2aa45
Merge remote-tracking branch 'origin/refactor_sdfg_list_to_cfg_list' …
phschaad Jan 29, 2024
81b6972
Fix incorrect arg passing
phschaad Jan 29, 2024
4ca1fea
Fix control flow inlining
phschaad Jan 29, 2024
303c605
Fix control flow region traversal
phschaad Jan 29, 2024
c1ec438
Bugfixes
phschaad Jan 29, 2024
a966044
Fix test
phschaad Jan 30, 2024
01b3593
Fix missing reset of cfg list for inlining
phschaad Jan 30, 2024
8af34d5
Fix test
phschaad Jan 30, 2024
03e976c
Added loops to fortran frontend
phschaad Jan 30, 2024
2d3d77e
Ensure compatibility checks
phschaad Jan 30, 2024
a89c64d
Cleanup
phschaad Jan 30, 2024
9c06e06
Cleanup
phschaad Jan 30, 2024
a608779
Cleanup
phschaad Jan 30, 2024
926ad49
Fix codegen bug (for loops)
phschaad Jan 31, 2024
03f0d75
Fix SDFG references for complex loop condition tests
phschaad Jan 31, 2024
aad6c28
Make dreport file sorting based on version instead of state id
phschaad Jan 31, 2024
a04bf0b
Fix dinstr test
phschaad Jan 31, 2024
22b7456
Fix duplicate control flow block naming for while condition checks
phschaad Jan 31, 2024
abcd09e
Workflow debugging
phschaad Feb 2, 2024
3e779fd
pytest debugging
phschaad Feb 2, 2024
1c7a569
Fixes
phschaad Feb 5, 2024
24a3d8a
Revert two changes
phschaad Feb 6, 2024
ed3f36d
Merge branch 'master' into loop_architecture_pt_3
phschaad May 16, 2024
bb6159e
Merge addendum
phschaad May 16, 2024
7455eb2
More robustness to blocksafe wrapper
phschaad May 16, 2024
63df04b
Multistate inline fix
phschaad May 16, 2024
5869236
Cleanup
phschaad May 16, 2024
4bc7c69
Merge branch 'master' into loop_architecture_pt_3
phschaad May 29, 2024
6e77fd0
Temporarily disable tests that cause problems with CF detection
phschaad Jun 11, 2024
012e70a
Merge branch 'master' into loop_architecture_pt_3
phschaad Jun 11, 2024
be4ac47
Add tests and fixes
phschaad Jun 12, 2024
e783717
Update doc
phschaad Jun 12, 2024
8da2a33
Merge branch 'master' into loop_architecture_pt_3
phschaad Jun 14, 2024
2e9c16e
Update copyright year in newast.py
phschaad Jun 18, 2024
0238393
Address comments
phschaad Jun 18, 2024
31818f8
Address more comments
phschaad Jun 18, 2024
f81c156
Fix numpy version to < 2.0
phschaad Jun 18, 2024
12651b2
Merge branch 'numpy_version_fix' into loop_architecture_pt_3
phschaad Jun 18, 2024
67de006
Fix misplaced exception
phschaad Jun 18, 2024
4a24c9c
Address comments
phschaad Jun 19, 2024
be6fe26
Refactor
phschaad Jun 21, 2024
1b8c76d
Fix incompatible types with 3.7, again
phschaad Jun 21, 2024
75f4d64
Fixes
phschaad Jun 21, 2024
d45fd72
Added additional level of backwards compatibility safety for passes
phschaad Jun 24, 2024
f518019
Made map to for loop (legacy version) safer (renaming)
phschaad Jun 24, 2024
3c1a27c
Fix instanceof check
phschaad Jun 24, 2024
d4f79bb
Fix missing import
phschaad Jun 24, 2024
9053acd
More fixes
phschaad Jun 24, 2024
c7517b8
Remove erroneous import
phschaad Jun 24, 2024
cdd3bd8
Address minor comments:
phschaad Jun 26, 2024
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
31 changes: 19 additions & 12 deletions dace/frontend/python/newast.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019-2023 ETH Zurich and the DaCe authors. All rights reserved.
# Copyright 2019-2024 ETH Zurich and the DaCe authors. All rights reserved.
import ast
from collections import OrderedDict
import copy
Expand Down Expand Up @@ -32,7 +32,7 @@
from dace.memlet import Memlet
from dace.properties import LambdaProperty, CodeBlock
from dace.sdfg import SDFG, SDFGState
from dace.sdfg.state import ControlFlowBlock, LoopRegion, ControlFlowRegion
from dace.sdfg.state import BreakBlock, ContinueBlock, ControlFlowBlock, LoopRegion, ControlFlowRegion
from dace.sdfg.replace import replace_datadesc_names
from dace.symbolic import pystr_to_symbolic, inequal_symbols

Expand Down Expand Up @@ -2456,11 +2456,16 @@ def visit_While(self, node: ast.While):
if test_region is not None:
iter_end_blocks = set()
for n in loop_region.nodes():
if isinstance(n, LoopRegion.ContinueState):
iter_end_blocks.add(n)
# If it needs to be connected back to the test region, it does no longer need
# to be handled specially and thus is no longer a special continue state.
n.__class__ = SDFGState
if isinstance(n, ContinueBlock):
# If it needs to be connected back to the test region, it does no longer need to be handled
# specially and thus is no longer a special continue state. Add an empty state and redirect the
# edges leading into the continue into it.
replacer_state = loop_region.add_state()
iter_end_blocks.add(replacer_state)
for ie in loop_region.in_edges(n):
loop_region.add_edge(ie.src, replacer_state, ie.data)
loop_region.remove_edge(ie)
loop_region.remove_node(n)
for inner_node in loop_region.nodes():
if loop_region.out_degree(inner_node) == 0:
iter_end_blocks.add(inner_node)
Expand Down Expand Up @@ -2509,7 +2514,7 @@ def _generate_orelse(self, loop_region: LoopRegion, postloop_block: ControlFlowB
did_break_symbol = 'did_break_' + loop_region.label
self.sdfg.add_symbol(did_break_symbol, dace.int32)
for n in loop_region.nodes():
if isinstance(n, LoopRegion.BreakState):
if isinstance(n, BreakBlock):
for iedge in loop_region.in_edges(n):
iedge.data.assignments[did_break_symbol] = '1'
for iedge in self.cfg_target.in_edges(loop_region):
Expand All @@ -2528,8 +2533,7 @@ def _generate_orelse(self, loop_region: LoopRegion, postloop_block: ControlFlowB

def visit_Break(self, node: ast.Break):
if isinstance(self.cfg_target, LoopRegion):
break_state = self.cfg_target.add_state('break_%s' % node.lineno, is_break=True)
self._on_block_added(break_state)
self._on_block_added(self.cfg_target.add_break(f'break_{self.cfg_target.label}_{node.lineno}'))
else:
error_msg = "'break' is only supported inside loops "
if self.nested:
Expand All @@ -2539,8 +2543,7 @@ def visit_Break(self, node: ast.Break):

def visit_Continue(self, node: ast.Continue):
if isinstance(self.cfg_target, LoopRegion):
continue_state = self.cfg_target.add_state('continue_%s' % node.lineno, is_continue=True)
self._on_block_added(continue_state)
self._on_block_added(self.cfg_target.add_continue(f'continue_{self.cfg_target.label}_{node.lineno}'))
else:
error_msg = ("'continue' is only supported inside loops ")
if self.nested:
Expand Down Expand Up @@ -4685,6 +4688,10 @@ def visit_Return(self, node: ast.Return):
ast_name = ast.copy_location(ast.Name(id='__return'), node)
self._visit_assign(new_node, ast_name, None, is_return=True)

if not isinstance(self.cfg_target, SDFG):
# In a nested control flow region, a return needs to be explicitly marked with a return block.
self._on_block_added(self.cfg_target.add_return(f'return_{self.cfg_target.label}_{node.lineno}'))

def visit_With(self, node, is_async=False):
# "with dace.tasklet" syntax
if len(node.items) == 1:
Expand Down
3 changes: 3 additions & 0 deletions dace/frontend/python/preprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,9 @@ def _add_exits(self, until_loop_end: bool, only_one: bool = False) -> List[ast.A
for stmt in reversed(self.with_statements):
if until_loop_end and not isinstance(stmt, (ast.With, ast.AsyncWith)):
break
elif not until_loop_end and isinstance(stmt, (ast.For, ast.While)):
break

for mgrname, mgr in reversed(self.context_managers[stmt]):
# Call __exit__ (without exception management all three arguments are set to None)
exit_call = ast.copy_location(ast.parse(f'{mgrname}.__exit__(None, None, None)').body[0], stmt)
Expand Down
16 changes: 14 additions & 2 deletions dace/sdfg/sdfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from dace.frontend.python import astutils, wrappers
from dace.sdfg import nodes as nd
from dace.sdfg.graph import OrderedDiGraph, Edge, SubgraphView
from dace.sdfg.state import SDFGState, ControlFlowRegion
from dace.sdfg.state import ControlFlowBlock, SDFGState, ControlFlowRegion
from dace.sdfg.propagation import propagate_memlets_sdfg
from dace.distr_types import ProcessGrid, SubArray, RedistrArray
from dace.dtypes import validate_name
Expand Down Expand Up @@ -183,7 +183,7 @@ class InterstateEdge(object):
desc="Assignments to perform upon transition (e.g., 'x=x+1; y = 0')")
condition = CodeProperty(desc="Transition condition", default=CodeBlock("1"))

def __init__(self, condition: CodeBlock = None, assignments=None):
def __init__(self, condition: Optional[Union[CodeBlock, str, ast.AST, list]] = None, assignments=None):
if condition is None:
condition = CodeBlock("1")

Expand Down Expand Up @@ -2686,3 +2686,15 @@ def make_array_memlet(self, array: str):
:return: a Memlet that fully transfers array
"""
return dace.Memlet.from_array(array, self.data(array))

def recheck_using_experimental_blocks(self) -> bool:
found_experimental_block = False
for node, graph in self.root_sdfg.all_nodes_recursive():
if isinstance(graph, ControlFlowRegion) and not isinstance(graph, SDFG):
found_experimental_block = True
break
if isinstance(node, ControlFlowBlock) and not isinstance(node, SDFGState):
found_experimental_block = True
break
self.root_sdfg.using_experimental_blocks = found_experimental_block
return found_experimental_block
Loading
Loading