From 9b2eadcb4be21b938220125a5a753db245201aea Mon Sep 17 00:00:00 2001 From: Yakup Budanaz Date: Thu, 24 Oct 2024 18:11:08 +0200 Subject: [PATCH 1/5] Add CFG to generate_scope in tutorials --- tutorials/codegen.ipynb | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/tutorials/codegen.ipynb b/tutorials/codegen.ipynb index a6effd7996..d2e1994db0 100644 --- a/tutorials/codegen.ipynb +++ b/tutorials/codegen.ipynb @@ -480,48 +480,48 @@ " self.frame = frame_codegen\n", " # Can be used to dispatch other code generators for allocation/nodes\n", " self.dispatcher = frame_codegen.dispatcher\n", - " \n", + "\n", " ################################################################\n", - " # Register handlers/hooks through dispatcher: Can be used for \n", + " # Register handlers/hooks through dispatcher: Can be used for\n", " # nodes, memory copy/allocation, scopes, states, and more.\n", - " \n", + "\n", " # In this case, register scopes\n", " self.dispatcher.register_map_dispatcher(dace.ScheduleType.LoopyLoop, self)\n", - " \n", + "\n", " # You can similarly use register_{array,copy,node,state}_dispatcher\n", - " \n", - " # A scope dispatcher will trigger a method called generate_scope whenever \n", + "\n", + " # A scope dispatcher will trigger a method called generate_scope whenever\n", " # an SDFG has a scope with that schedule\n", - " def generate_scope(self, sdfg: dace.SDFG, scope: ScopeSubgraphView,\n", + " def generate_scope(self, sdfg: dace.SDFG, dfg, scope: ScopeSubgraphView,\n", " state_id: int, function_stream: CodeIOStream,\n", " callsite_stream: CodeIOStream):\n", " # The parameters here are:\n", " # sdfg: The SDFG we are currently generating.\n", " # scope: The subgraph of the state containing only the scope (map contents)\n", " # we want to generate the code for.\n", - " # state_id: The state in the SDFG the subgraph is taken from (i.e., \n", + " # state_id: The state in the SDFG the subgraph is taken from (i.e.,\n", " # `sdfg.node(state_id)` is the same as `scope.graph`)\n", " # function_stream: A cursor to the global code (which can be used to define\n", " # functions, hence the name).\n", " # callsite_stream: A cursor to the current location in the code, most of\n", " # the code is generated here.\n", - " \n", + "\n", " # We can get the map entry node from the scope graph\n", " entry_node = scope.source_nodes()[0]\n", - " \n", + "\n", " # First, generate an opening brace (for instrumentation and dynamic map ranges)\n", " callsite_stream.write('{', sdfg, state_id, entry_node)\n", - " \n", + "\n", " ################################################################\n", - " # Generate specific code: We will generate a reversed loop with a \n", + " # Generate specific code: We will generate a reversed loop with a\n", " # comment for each dimension of the map. For the sake of simplicity,\n", " # dynamic map ranges are not supported.\n", - " \n", + "\n", " for param, rng in zip(entry_node.map.params, entry_node.map.range):\n", " # We use the sym2cpp function from the cpp support functions\n", " # to convert symbolic expressions to proper C++\n", " begin, end, stride = (sym2cpp(r) for r in rng)\n", - " \n", + "\n", " # Every write is optionally (but recommended to be) tagged with\n", " # 1-3 extra arguments, serving as line information to match\n", " # SDFG, state, and graph nodes/edges to written code.\n", @@ -529,17 +529,17 @@ " for (auto {param} = {end}; {param} >= {begin}; {param} -= {stride}) {{''',\n", " sdfg, state_id, entry_node\n", " )\n", - " \n", + "\n", " # NOTE: CodeIOStream will automatically take care of indentation for us.\n", - " \n", - " \n", + "\n", + "\n", " # Now that the loops have been defined, use the dispatcher to invoke any\n", " # code generator (including this one) that is registered to deal with\n", " # the internal nodes in the subgraph. We skip the MapEntry node.\n", - " self.dispatcher.dispatch_subgraph(sdfg, scope, state_id,\n", + " self.dispatcher.dispatch_subgraph(sdfg, dfg, scope, state_id,\n", " function_stream, callsite_stream,\n", " skip_entry_node=True)\n", - " \n", + "\n", " # NOTE: Since skip_exit_node above is set to False, closing braces will\n", " # be automatically generated" ] From 0706df0e1bcc65e3f8758a20997dc66c882cc106 Mon Sep 17 00:00:00 2001 From: Yakup Budanaz Date: Fri, 25 Oct 2024 10:47:34 +0200 Subject: [PATCH 2/5] Add typehint, use correct name --- tutorials/codegen.ipynb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tutorials/codegen.ipynb b/tutorials/codegen.ipynb index d2e1994db0..2be83f35be 100644 --- a/tutorials/codegen.ipynb +++ b/tutorials/codegen.ipynb @@ -492,9 +492,9 @@ "\n", " # A scope dispatcher will trigger a method called generate_scope whenever\n", " # an SDFG has a scope with that schedule\n", - " def generate_scope(self, sdfg: dace.SDFG, dfg, scope: ScopeSubgraphView,\n", - " state_id: int, function_stream: CodeIOStream,\n", - " callsite_stream: CodeIOStream):\n", + " def generate_scope(self, sdfg: dace.SDFG, cfg: dace.ControlFlowRegion,\n", + " scope: ScopeSubgraphView, state_id: int,\n", + " function_stream: CodeIOStream, callsite_stream: CodeIOStream):\n", " # The parameters here are:\n", " # sdfg: The SDFG we are currently generating.\n", " # scope: The subgraph of the state containing only the scope (map contents)\n", @@ -536,7 +536,7 @@ " # Now that the loops have been defined, use the dispatcher to invoke any\n", " # code generator (including this one) that is registered to deal with\n", " # the internal nodes in the subgraph. We skip the MapEntry node.\n", - " self.dispatcher.dispatch_subgraph(sdfg, dfg, scope, state_id,\n", + " self.dispatcher.dispatch_subgraph(sdfg, cfg, scope, state_id,\n", " function_stream, callsite_stream,\n", " skip_entry_node=True)\n", "\n", @@ -798,7 +798,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": ".def", "language": "python", "name": "python3" }, @@ -812,7 +812,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.1" + "version": "3.12.3" } }, "nbformat": 4, From 4661a4d6309d5683a01a9dd3f916714bfb6aff3a Mon Sep 17 00:00:00 2001 From: Yakup Koray Budanaz Date: Fri, 25 Oct 2024 13:42:44 +0200 Subject: [PATCH 3/5] Update codegen.ipynb --- tutorials/codegen.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/codegen.ipynb b/tutorials/codegen.ipynb index 2be83f35be..207fca642d 100644 --- a/tutorials/codegen.ipynb +++ b/tutorials/codegen.ipynb @@ -798,7 +798,7 @@ ], "metadata": { "kernelspec": { - "display_name": ".def", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -812,7 +812,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.3" + "version": "3.12.1" } }, "nbformat": 4, From c5be6ea8ad28b5a2c65c3d0338f7ad76e116f14c Mon Sep 17 00:00:00 2001 From: Yakup Koray Budanaz Date: Mon, 28 Oct 2024 12:56:44 +0100 Subject: [PATCH 4/5] Add tutorial comments --- tutorials/codegen.ipynb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tutorials/codegen.ipynb b/tutorials/codegen.ipynb index 207fca642d..a20cfca03e 100644 --- a/tutorials/codegen.ipynb +++ b/tutorials/codegen.ipynb @@ -497,6 +497,8 @@ " function_stream: CodeIOStream, callsite_stream: CodeIOStream):\n", " # The parameters here are:\n", " # sdfg: The SDFG we are currently generating.\n", + " # cfg: The current control flow graph (CFG) we are currently generating. For example, + " it can be the SDFG a or a loop region. " # scope: The subgraph of the state containing only the scope (map contents)\n", " # we want to generate the code for.\n", " # state_id: The state in the SDFG the subgraph is taken from (i.e.,\n", From 9d40a48d0749630d3e8f476394333aed5ca7cc6e Mon Sep 17 00:00:00 2001 From: Yakup Koray Budanaz Date: Tue, 29 Oct 2024 10:24:05 +0100 Subject: [PATCH 5/5] Fix typo Co-authored-by: Philipp Schaad --- tutorials/codegen.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/codegen.ipynb b/tutorials/codegen.ipynb index a20cfca03e..2c79f1a2e0 100644 --- a/tutorials/codegen.ipynb +++ b/tutorials/codegen.ipynb @@ -498,7 +498,7 @@ " # The parameters here are:\n", " # sdfg: The SDFG we are currently generating.\n", " # cfg: The current control flow graph (CFG) we are currently generating. For example, - " it can be the SDFG a or a loop region. + " it can be the SDFG or a loop region. " # scope: The subgraph of the state containing only the scope (map contents)\n", " # we want to generate the code for.\n", " # state_id: The state in the SDFG the subgraph is taken from (i.e.,\n",