From 08235192ea11fbf296caf0334cde4a3e15d2f77a Mon Sep 17 00:00:00 2001 From: Philipp Schaad Date: Thu, 23 Jan 2025 10:56:54 +0100 Subject: [PATCH] Codegen fixes --- dace/codegen/targets/cpu.py | 1 + dace/codegen/targets/framecode.py | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/dace/codegen/targets/cpu.py b/dace/codegen/targets/cpu.py index c7d05de5a3..5ac21553b9 100644 --- a/dace/codegen/targets/cpu.py +++ b/dace/codegen/targets/cpu.py @@ -1667,6 +1667,7 @@ def _generate_NestedSDFG( ): inline = Config.get_bool('compiler', 'inline_sdfgs') self._dispatcher.defined_vars.enter_scope(sdfg, can_access_parent=inline) + self._dispatcher.declared_arrays.enter_scope(sdfg, can_access_parent=inline) state_dfg = cfg.nodes()[state_id] fsyms = self._frame.free_symbols(node.sdfg) diff --git a/dace/codegen/targets/framecode.py b/dace/codegen/targets/framecode.py index 5abcc770aa..10d562c14b 100644 --- a/dace/codegen/targets/framecode.py +++ b/dace/codegen/targets/framecode.py @@ -21,7 +21,7 @@ from dace.sdfg import scope as sdscope from dace.sdfg import utils from dace.sdfg.analysis import cfg as cfg_analysis -from dace.sdfg.state import ConditionalBlock, ControlFlowBlock, ControlFlowRegion, LoopRegion +from dace.sdfg.state import AbstractControlFlowRegion, ControlFlowBlock, ControlFlowRegion, LoopRegion from dace.transformation.passes.analysis import StateReachability, loop_analysis @@ -578,18 +578,23 @@ def determine_allocation_lifetime(self, top_sdfg: SDFG): array_names = sdfg.arrays.keys( ) #set(k for k, v in sdfg.arrays.items() if v.lifetime == dtypes.AllocationLifetime.Scope) # Iterate topologically to get state-order - for state in cfg_analysis.blockorder_topological_sort(sdfg, ignore_nonstate_blocks=True): - for node in state.data_nodes(): - if node.data not in array_names: - continue - instances[node.data].append((state, node)) + for block in cfg_analysis.blockorder_topological_sort(sdfg, ignore_nonstate_blocks=False): + if isinstance(block, SDFGState): + for node in block.data_nodes(): + if node.data not in array_names: + continue + instances[node.data].append((block, node)) + elif isinstance(block, AbstractControlFlowRegion): + block_fsyms = block.used_symbols(all_symbols=True, with_contents=False) + for block_array in block_fsyms & array_names: + instances[block_array].append((block, nodes.AccessNode(block_array))) # Look in the surrounding edges for usage edge_fsyms: Set[str] = set() - for e in state.parent_graph.all_edges(state): + for e in block.parent_graph.all_edges(block): edge_fsyms |= e.data.free_symbols for edge_array in edge_fsyms & array_names: - instances[edge_array].append((state, nodes.AccessNode(edge_array))) + instances[edge_array].append((block, nodes.AccessNode(edge_array))) ############################################# access_instances[sdfg.cfg_id] = instances