Skip to content

Commit

Permalink
framecode: Fix missing SingleState argument (#1630)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iBug authored Aug 30, 2024
1 parent d3a1c57 commit 8521f40
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion dace/codegen/targets/framecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8521f40

Please sign in to comment.