From 8521f40d1086c4ab275298d88d89f9e5308c125d Mon Sep 17 00:00:00 2001 From: iBug Date: Fri, 30 Aug 2024 13:32:01 +0800 Subject: [PATCH] framecode: Fix missing SingleState argument (#1630) Updated for v0.16: The (renamed) `BasicCFBlock` class still requires 4 arguments in a different order and with none being optional. The new `__init__` method as provided by `@dataclass` looks like this: ```python def __init__(self, dispatch_state: Callable[[SDFGState], str], # from ControlFlow parent: Optional['ControlFlow'], # from ControlFlow last_block: bool, # from ControlFlow state: SDFGState, ) ``` The current code still supplies 3 arguments and in a wrong order. This PR fixes that. Original PR description (when I was still running on DaCe v0.15.1) follows. --- With `optimizer.detect_control_flow == False`, this part of code causes an error later on: ```text File "/home/ibug/examples/dace/dace/codegen/control_flow.py", line 221, in as_cpp expr += elem.as_cpp(codegen, symbols) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/ibug/examples/dace/dace/codegen/control_flow.py", line 128, in as_cpp sdfg = self.state.parent ^^^^^^^^^^^^^^^^^ AttributeError: 'bool' object has no attribute 'parent' ``` I identified this as `cflow.SingleState` requiring 4 arguments to its `__init__` method with the last one being optional, i.e.: ```python def __init__(self, dispatch_state: Callable[[SDFGState], str], # from ControlFlow parent: Optional['ControlFlow'], # from ControlFlow state: SDFGState, last_state: bool = False, ) ``` The current code incorrectly feeds 3 and did not trigger a `TypeError` due to the last one having a default value. This PR adds back the missing `parent` argument, although I'm not sure if the `sdfg` object is correct. Local testing shows that `None` suffices, though. --- dace/codegen/targets/framecode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dace/codegen/targets/framecode.py b/dace/codegen/targets/framecode.py index 5b756b413c..f86c0de3b4 100644 --- a/dace/codegen/targets/framecode.py +++ b/dace/codegen/targets/framecode.py @@ -492,7 +492,7 @@ def dispatch_state(state: SDFGState) -> str: states_topological = list(sdfg.bfs_nodes(sdfg.start_state)) last = states_topological[-1] cft = cflow.GeneralBlock(dispatch_state, None, - [cflow.BasicCFBlock(dispatch_state, s, s is last) for s in states_topological], + [cflow.BasicCFBlock(dispatch_state, None, s is last, s) for s in states_topological], [], [], [], [], False) callsite_stream.write(cft.as_cpp(self, sdfg.symbols), sdfg)