@@ -269,6 +269,7 @@ def connect(
269269 map_exit : Optional [dace_nodes .MapExit ],
270270 dest : dace_nodes .AccessNode ,
271271 dest_subset : dace_subsets .Range ,
272+ allow_removal_of_last_node : bool ,
272273 ) -> bool :
273274 """Create a connection to the `dest` node, writing the given `dest_subset`.
274275
@@ -277,35 +278,34 @@ def connect(
277278 outside data container is removed, the caller is responsible to propagate
278279 the strides of the destination array to the array inside the nested SDFG.
279280 """
280- # We don't allow removing the last node of the dataflow inside a map scope,
281- # because the same reults could be written to multiple destiation nodes ouside
282- # the map scope, in case of field operators returning tuples.
283- allow_removal_of_last_node : Final [bool ] = False
284281 dest_desc = self .result .dc_node .desc (self .state )
285282 write_edge = self .state .in_edges (self .result .dc_node )[0 ]
286283
287- if self .state .out_degree (self .result .dc_node ) != 0 :
288- remove_last_node = False
289- elif isinstance (write_edge .src , dace_nodes .Tasklet ):
290- # The temporary data written by a tasklet can be safely deleted.
291- remove_last_node = True
292- elif isinstance (write_edge .src , dace_nodes .NestedSDFG ):
293- if isinstance (dest_desc , dace .data .Scalar ):
294- # We keep scalar temporary storage, as a general rule, since it
295- # does not affect performance of the generated code. This scalar
296- # is only required in some cases, e.g. for nested SDFGs implementing
297- # reduction, which use a WCR memlet for the reduction operation.
284+ if allow_removal_of_last_node :
285+ if self .state .out_degree (self .result .dc_node ) != 0 :
298286 remove_last_node = False
299- else :
300- # We remove the transient array on the output connection of a nested
301- # SDFG and write directly to the destination node.
302- # The caller is responsible to propagate the strides of the destination
303- # array to the array inside the nested SDFG.
287+ elif isinstance (write_edge .src , dace_nodes .Tasklet ):
288+ # The temporary data written by a tasklet can be safely deleted.
304289 remove_last_node = True
290+ elif isinstance (write_edge .src , dace_nodes .NestedSDFG ):
291+ if isinstance (dest_desc , dace .data .Scalar ):
292+ # We keep scalar temporary storage, as a general rule, since it
293+ # does not affect performance of the generated code. This scalar
294+ # is only required in some cases, e.g. for nested SDFGs implementing
295+ # reduction, which use a WCR memlet for the reduction operation.
296+ remove_last_node = False
297+ else :
298+ # We remove the transient array on the output connection of a nested
299+ # SDFG and write directly to the destination node.
300+ # The caller is responsible to propagate the strides of the destination
301+ # array to the array inside the nested SDFG.
302+ remove_last_node = True
303+ else :
304+ remove_last_node = False
305305 else :
306306 remove_last_node = False
307307
308- if allow_removal_of_last_node and remove_last_node :
308+ if remove_last_node :
309309 src_node = write_edge .src
310310 src_node_connector = write_edge .src_conn
311311 src_subset = write_edge .data .src_subset
0 commit comments