-
Notifications
You must be signed in to change notification settings - Fork 157
Fixed remove_edge_and_dangling_path()
#2307
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
Open
philip-paul-mueller
wants to merge
10
commits into
spcl:main
Choose a base branch
from
philip-paul-mueller:fixed_remove_edge_path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+210
−44
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
daf8d08
Corrected the `remove_{in, out}_connector()` functions.
philip-paul-mueller b80ef26
Made a new version of `remove_edge_and_dangling_path()` that can also…
philip-paul-mueller ebc4fbd
Fixed a bug
philip-paul-mueller 2f7c88d
Added a new test.
philip-paul-mueller c97d11c
Fxied some issues.
philip-paul-mueller 3c1b6f3
Less restrictive.
philip-paul-mueller 085b101
Seems to be picker.
philip-paul-mueller 668bd6e
Merge branch 'main' into fixed_remove_edge_path
philip-paul-mueller 34760d1
Applied Tal's comments.
philip-paul-mueller aad715e
Merge remote-tracking branch 'spcl/main' into fixed_remove_edge_path
philip-paul-mueller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| # Copyright 2019-2026 ETH Zurich and the DaCe authors. All rights reserved. | ||
| import dace | ||
|
|
||
|
|
||
| def test_remove_edge_global_scope(): | ||
| sdfg = dace.SDFG("simple_edge_remover_test") | ||
| state = sdfg.add_state() | ||
|
|
||
| sdfg.add_array("a", shape=(1, ), dtype=dace.float64, transient=False) | ||
| sdfg.add_array("b", shape=(1, ), dtype=dace.float64, transient=False) | ||
|
|
||
| tlet = state.add_tasklet( | ||
| "comp", | ||
| inputs={"__in"}, | ||
| outputs={"__out"}, | ||
| code="__out = __in + 1.0", | ||
| ) | ||
| a = state.add_access("a") | ||
| b = state.add_access("b") | ||
|
|
||
| up_edge = state.add_edge(a, None, tlet, "__in", dace.Memlet("a[0]")) | ||
| down_edge = state.add_edge(tlet, "__out", b, None, dace.Memlet("b[0]")) | ||
| sdfg.validate() | ||
|
|
||
| # Now remove the edge using the function. Note that this makes the SDFG invalid, | ||
| # because the tasklet wants an input. We ignore that for now. | ||
| nb_removed_edges = dace.sdfg.utils.remove_edge_and_dangling_path(state, up_edge) | ||
| assert nb_removed_edges == 1 | ||
| assert a not in state.nodes() | ||
| assert tlet in state.nodes() | ||
| assert b in state.nodes() | ||
| assert sdfg.arrays.keys() == {"a", "b"} | ||
| assert len(tlet.in_connectors) == 0 | ||
| assert state.in_degree(tlet) == 0 | ||
| assert tlet.out_connectors.keys() == {"__out"} | ||
| assert state.out_degree(tlet) == 1 | ||
|
|
||
| # If we now also delete the `down_edge` then the state will become empty. | ||
| nb_removed_edges = dace.sdfg.utils.remove_edge_and_dangling_path(state, down_edge) | ||
| assert nb_removed_edges == 1 | ||
| assert state.number_of_nodes() == 0 | ||
|
|
||
|
|
||
| def test_remove_edge_nested_scope(): | ||
| sdfg = dace.SDFG("nested_edge_remover_test") | ||
| state = sdfg.add_state() | ||
|
|
||
| sdfg.add_array("a", shape=(10, 10), dtype=dace.float64, transient=False) | ||
| sdfg.add_array("b", shape=(10, 10, 2), dtype=dace.float64, transient=False) | ||
|
|
||
| tlet = state.add_tasklet( | ||
| "comp", | ||
| inputs={"__in1", "__in2"}, | ||
| outputs={"__out1", "__out2"}, | ||
| code="__out1 = __in1 + 1.0\n__out2 = __in2 - 1.0", | ||
| ) | ||
| a, b = (state.add_access(name) for name in "ab") | ||
| me, mx = state.add_map("outer_map", ndrange={"__i": "0:10"}) | ||
| nme, nmx = state.add_map("nested_map", ndrange={"__j": "0:10"}) | ||
|
|
||
| state.add_edge(a, None, me, "IN_a", dace.Memlet("a[0:10, 0:10]")) | ||
| me.add_scope_connectors("a") | ||
| state.add_edge(me, "OUT_a", nme, "IN_a1", dace.Memlet("a[__i, 0:10]")) | ||
| state.add_edge(me, "OUT_a", nme, "IN_a2", dace.Memlet("a[0:10, __i]")) | ||
| nme.add_scope_connectors("a1") | ||
| nme.add_scope_connectors("a2") | ||
|
|
||
| up_edge1 = state.add_edge(nme, "OUT_a1", tlet, "__in1", dace.Memlet("a[__i, __j]")) | ||
| up_edge2 = state.add_edge(nme, "OUT_a2", tlet, "__in2", dace.Memlet("a[__j, __i]")) | ||
|
|
||
| down_edge1 = state.add_edge(tlet, "__out1", nmx, "IN_b", dace.Memlet("b[__i, __j, 0]")) | ||
| down_edge2 = state.add_edge(tlet, "__out2", nmx, "IN_b", dace.Memlet("b[__j, __i, 1]")) | ||
| nmx.add_scope_connectors("b") | ||
|
|
||
| state.add_edge(nmx, "OUT_b", mx, "IN_b", dace.Memlet("b[0:10, 0:10, 0:2]")) | ||
| mx.add_scope_connectors("b") | ||
| state.add_edge(mx, "OUT_b", b, None, dace.Memlet("b[0:10, 0:10, 0:2]")) | ||
| sdfg.validate() | ||
|
|
||
| assert state.number_of_nodes() == 7 | ||
|
|
||
| # Because of the fan out, the deletion will stop. | ||
| nb_rm_up_edge1 = dace.sdfg.utils.remove_edge_and_dangling_path(state, up_edge1) | ||
| assert nb_rm_up_edge1 == 2 | ||
| assert state.number_of_nodes() == 7 | ||
| assert set(tlet.in_connectors.keys()) == {"__in2"} | ||
| assert state.in_degree(tlet) == 1 | ||
| assert set(tlet.out_connectors.keys()) == {"__out1", "__out2"} | ||
| assert state.out_degree(tlet) == 2 | ||
| assert set(nme.out_connectors.keys()) == {"OUT_a2"} | ||
| assert set(nme.in_connectors.keys()) == {"IN_a2"} | ||
| assert state.out_degree(nme) == 1 | ||
| assert state.in_degree(nme) == 1 | ||
| assert state.out_degree(me) == 1 | ||
| assert state.in_degree(me) == 1 | ||
| assert set(me.out_connectors.keys()) == {"OUT_a"} | ||
| assert set(me.in_connectors.keys()) == {"IN_a"} | ||
| assert state.degree(a) == 1 | ||
|
|
||
| # Now the deletion will go up and remove the map entries; which leads to a | ||
| # technical and functional invalid SDFG. | ||
| nb_rm_up_edge2 = dace.sdfg.utils.remove_edge_and_dangling_path(state, up_edge2) | ||
| assert nb_rm_up_edge2 == 3 | ||
| assert state.number_of_nodes() == 4 | ||
| assert state.number_of_edges() == 4 | ||
| assert {tlet, nmx, mx, b} == set(state.nodes()) | ||
| assert len(tlet.in_connectors) == 0 | ||
| assert set(tlet.out_connectors.keys()) == {"__out1", "__out2"} | ||
|
|
||
| # The first down edge, will only delete one edge, due to the location of the fan | ||
| # in, which is a bit different compared to the location of the upper fan out. | ||
| nb_rm_down_edge1 = dace.sdfg.utils.remove_edge_and_dangling_path(state, down_edge1) | ||
| assert nb_rm_down_edge1 == 1 | ||
| assert state.number_of_nodes() == 4 | ||
| assert state.number_of_edges() == 3 | ||
| assert {tlet, nmx, mx, b} == set(state.nodes()) | ||
| assert len(tlet.in_connectors) == 0 | ||
| assert set(tlet.out_connectors.keys()) == {"__out2"} | ||
| assert len(nmx.in_connectors) == 1 | ||
| assert len(nmx.out_connectors) == 1 | ||
| assert len(mx.in_connectors) == 1 | ||
| assert len(mx.out_connectors) == 1 | ||
|
|
||
| # This will remove all nodes. | ||
| nb_rm_down_edge2 = dace.sdfg.utils.remove_edge_and_dangling_path(state, down_edge2) | ||
| assert nb_rm_up_edge2 == 3 | ||
| assert state.number_of_nodes() == 0 | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| test_remove_edge_global_scope() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what case is this? I think it is generally disallowed in SDFG syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually wish that it would be disallowed but it is permitted and as far as I can tell parts of the toolchain (I suspect
ConsolidateEdge) actually create such cases.The case essentially represents the following:
So
MapExitwill have two incoming edges.However, they do not have to go to the distinct (in-)connectors of the
MapExitnode.In case they go to distinct connectors then there are also two outgoing edges one with subset
[0:N, 0]and the other with[0:N, 39].However, it is also allowed that they go to the same (in-)connector of
MapExit.In that case
MapExitwill only have one outgoing edge, and it will have a subset of[0:N, 0:40], which grossly overestimate the range that is written.This is actually currently happening in GT4Py and it also blocks some optimization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, there is an exception for passthrough (
IN_*/OUT_*) connectors. I was only thinking about tasklets/library nodes/nested SDFGs. Thank you for the clarification