diff --git a/dace/transformation/dataflow/map_fusion_vertical.py b/dace/transformation/dataflow/map_fusion_vertical.py index c9c1e418c4..546bff3d6a 100644 --- a/dace/transformation/dataflow/map_fusion_vertical.py +++ b/dace/transformation/dataflow/map_fusion_vertical.py @@ -1541,11 +1541,15 @@ def _is_data_accessed_downstream( def next_nodes(node: nodes.Node) -> Iterable[nodes.Node]: return (edge.dst for edge in graph.out_edges(node)) - # Dataflow graph is acyclic, so we do not need to keep a list of - # what we have visited. + # Track visited nodes to avoid exponential blowup from visiting + # the same node multiple times via different paths in the DAG. to_visit: List[nodes.Node] = list(next_nodes(begin)) + visited: Set[nodes.Node] = set() while len(to_visit) > 0: node = to_visit.pop() + if node in visited: + continue + visited.add(node) if isinstance(node, nodes.AccessNode) and node.data == data: return True to_visit.extend(next_nodes(node))