-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1221 from spcl/fix-nested-sdfg-deepcopy
Fix-nested-sdfg-deepcopy
- Loading branch information
Showing
8 changed files
with
236 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,153 @@ | ||
# Copyright 2019-2023 ETH Zurich and the DaCe authors. All rights reserved. | ||
""" Tests deepcopying (nested) SDFGs. """ | ||
import copy | ||
import dace | ||
import numpy as np | ||
|
||
|
||
def test_deepcopy_same_state(): | ||
|
||
sdfg = dace.SDFG('deepcopy_nested_sdfg') | ||
state = sdfg.add_state('state') | ||
|
||
nsdfg = dace.SDFG('nested') | ||
nsdfg_node = state.add_nested_sdfg(nsdfg, None, {}, {}) | ||
|
||
copy_nsdfg = copy.deepcopy(nsdfg_node) | ||
assert copy_nsdfg.sdfg.parent_nsdfg_node is copy_nsdfg | ||
assert copy_nsdfg.sdfg.parent is None | ||
assert copy_nsdfg.sdfg.parent_sdfg is None | ||
|
||
state.add_node(copy_nsdfg) | ||
assert copy_nsdfg.sdfg.parent is state | ||
assert copy_nsdfg.sdfg.parent_sdfg is sdfg | ||
|
||
|
||
def test_deepcopy_same_state_edge(): | ||
|
||
sdfg = dace.SDFG('deepcopy_nested_sdfg') | ||
state = sdfg.add_state('state') | ||
|
||
nsdfg = dace.SDFG('nested') | ||
nsdfg_node = state.add_nested_sdfg(nsdfg, None, {}, {}) | ||
|
||
copy_nsdfg = copy.deepcopy(nsdfg_node) | ||
assert copy_nsdfg.sdfg.parent_nsdfg_node is copy_nsdfg | ||
assert copy_nsdfg.sdfg.parent is None | ||
assert copy_nsdfg.sdfg.parent_sdfg is None | ||
|
||
state.add_edge(nsdfg_node, None, copy_nsdfg, None, dace.Memlet()) | ||
assert copy_nsdfg.sdfg.parent is state | ||
assert copy_nsdfg.sdfg.parent_sdfg is sdfg | ||
|
||
|
||
def test_deepcopy_diff_state(): | ||
|
||
sdfg = dace.SDFG('deepcopy_nested_sdfg') | ||
state_0 = sdfg.add_state('state_0') | ||
state_1 = sdfg.add_state('state_1') | ||
|
||
nsdfg = dace.SDFG('nested') | ||
nsdfg_node = state_0.add_nested_sdfg(nsdfg, None, {}, {}) | ||
|
||
copy_nsdfg = copy.deepcopy(nsdfg_node) | ||
assert copy_nsdfg.sdfg.parent_nsdfg_node is copy_nsdfg | ||
assert copy_nsdfg.sdfg.parent is None | ||
assert copy_nsdfg.sdfg.parent_sdfg is None | ||
|
||
state_1.add_node(copy_nsdfg) | ||
assert copy_nsdfg.sdfg.parent is state_1 | ||
assert copy_nsdfg.sdfg.parent_sdfg is sdfg | ||
|
||
|
||
def test_deepcopy_diff_state_edge(): | ||
|
||
sdfg = dace.SDFG('deepcopy_nested_sdfg') | ||
sdfg.add_array('A', [1], dace.int32) | ||
state_0 = sdfg.add_state('state_0') | ||
state_1 = sdfg.add_state('state_1') | ||
|
||
nsdfg = dace.SDFG('nested') | ||
nsdfg_node = state_0.add_nested_sdfg(nsdfg, None, {}, {}) | ||
|
||
copy_nsdfg = copy.deepcopy(nsdfg_node) | ||
assert copy_nsdfg.sdfg.parent_nsdfg_node is copy_nsdfg | ||
assert copy_nsdfg.sdfg.parent is None | ||
assert copy_nsdfg.sdfg.parent_sdfg is None | ||
|
||
a = state_1.add_access('A') | ||
state_1.add_edge(a, None, copy_nsdfg, None, dace.Memlet()) | ||
assert copy_nsdfg.sdfg.parent is state_1 | ||
assert copy_nsdfg.sdfg.parent_sdfg is sdfg | ||
|
||
|
||
def test_deepcopy_diff_sdfg(): | ||
|
||
sdfg_0 = dace.SDFG('deepcopy_nested_sdfg_0') | ||
state_0 = sdfg_0.add_state('state_0') | ||
|
||
nsdfg = dace.SDFG('nested') | ||
nsdfg_node = state_0.add_nested_sdfg(nsdfg, None, {}, {}) | ||
|
||
copy_nsdfg = copy.deepcopy(nsdfg_node) | ||
assert copy_nsdfg.sdfg.parent_nsdfg_node is copy_nsdfg | ||
assert copy_nsdfg.sdfg.parent is None | ||
assert copy_nsdfg.sdfg.parent_sdfg is None | ||
|
||
sdfg_1 = dace.SDFG('deepcopy_nested_sdfg_1') | ||
state_1 = sdfg_1.add_state('state_1') | ||
|
||
state_1.add_node(copy_nsdfg) | ||
assert copy_nsdfg.sdfg.parent is state_1 | ||
assert copy_nsdfg.sdfg.parent_sdfg is sdfg_1 | ||
|
||
|
||
def test_deepcopy_diff_sdfg_edge(): | ||
|
||
sdfg_0 = dace.SDFG('deepcopy_nested_sdfg_0') | ||
state_0 = sdfg_0.add_state('state_0') | ||
|
||
nsdfg = dace.SDFG('nested') | ||
nsdfg_node = state_0.add_nested_sdfg(nsdfg, None, {}, {}) | ||
|
||
copy_nsdfg = copy.deepcopy(nsdfg_node) | ||
assert copy_nsdfg.sdfg.parent_nsdfg_node is copy_nsdfg | ||
assert copy_nsdfg.sdfg.parent is None | ||
assert copy_nsdfg.sdfg.parent_sdfg is None | ||
|
||
sdfg_1 = dace.SDFG('deepcopy_nested_sdfg_1') | ||
sdfg_1.add_array('A', [1], dace.int32) | ||
state_1 = sdfg_1.add_state('state_1') | ||
|
||
a = state_1.add_access('A') | ||
state_1.add_edge(a, None, copy_nsdfg, None, dace.Memlet()) | ||
assert copy_nsdfg.sdfg.parent is state_1 | ||
assert copy_nsdfg.sdfg.parent_sdfg is sdfg_1 | ||
|
||
|
||
def test_deepcopy_top_level(): | ||
|
||
sdfg = dace.SDFG('deepcopy_nested_sdfg') | ||
state = sdfg.add_state('state') | ||
|
||
nsdfg = dace.SDFG('nested') | ||
nsdfg_node = state.add_nested_sdfg(nsdfg, None, {}, {}) | ||
|
||
copy_sdfg = copy.deepcopy(sdfg) | ||
copy_state = copy_sdfg.states()[0] | ||
copy_nsdfg_node = copy_state.nodes()[0] | ||
for sd in copy_sdfg.all_sdfgs_recursive(): | ||
if sd is copy_sdfg: | ||
continue | ||
assert sd.parent_nsdfg_node is copy_nsdfg_node | ||
assert sd.parent is copy_state | ||
assert sd.parent_sdfg is copy_sdfg | ||
|
||
|
||
if __name__ == '__main__': | ||
test_deepcopy_same_state() | ||
test_deepcopy_same_state_edge() | ||
test_deepcopy_diff_state() | ||
test_deepcopy_diff_state_edge() | ||
test_deepcopy_diff_sdfg() | ||
test_deepcopy_top_level() |