diff --git a/aidge_core/aidge_export_aidge/export.py b/aidge_core/aidge_export_aidge/export.py index b561b835f629e8ac9003d624456d904e30fd94bf..b0e859b71e77bb03b95acb6ca75dcf09a8af0722 100644 --- a/aidge_core/aidge_export_aidge/export.py +++ b/aidge_core/aidge_export_aidge/export.py @@ -11,7 +11,7 @@ from aidge_core import ExportNode, generate_file def export(export_folder: str, - scheduler: aidge_core.Scheduler, + graph_view: aidge_core.GraphView, enable_python_binding: bool = True, ): export_folder_path = Path(export_folder) @@ -52,12 +52,35 @@ def export(export_folder: str, # TODO: Add a main.py file ? ### Generating an export for each nodes and dnn file ### - ordered_nodes = scheduler.get_static_scheduling() - list_configs = [] # List of headers to include in dnn.cpp to access attribute and parameters list_actions = [] # List of string to construct graph set_operator = set() - for node in ordered_nodes: + # Queue of Aidge nodes to explore, guarantee a topological exploration of the graph + open_nodes = list(graph_view.get_input_nodes()) + # List of Aidge nodes already explored + closed_nodes = [] + + while open_nodes: + node = open_nodes.pop(0) + if node in closed_nodes: + continue # Node already converted, moving on ... + parents_not_converted = False + # Check all parents have been converted + for parent in node.get_parents(): + if parent is not None and \ + parent not in closed_nodes: + # If parents have not been converted, push back current node + if not parents_not_converted: + open_nodes.insert(0, node) + parents_not_converted = True + # Add to the stack the not converted parent as next node to convert + open_nodes.insert(0, parent) + if parents_not_converted: + + continue + # Next nodes to treat are children of current node + open_nodes += list(node.get_children()) + if node.type() in supported_operators(): set_operator.add(node.type()) op = OPERATORS_REGISTRY[node.type()](node) @@ -70,7 +93,7 @@ def export(export_folder: str, list_actions = op.forward(list_actions) else: raise RuntimeError(f"Operator: {node.type()} is not supported") - + closed_nodes.append(node) # Generate full dnn.cpp aidge_core.generate_file( export_folder_path / "src/dnn.cpp",