From bc91297c865808ed2c321febc405179f63195ff8 Mon Sep 17 00:00:00 2001 From: SiCongLi Date: Tue, 25 May 2021 14:29:21 +0100 Subject: Fix node fusion mutator Node fusion mutator adds new nodes to the node list, invalidating the list iterator during iteration. The fix uses index instead. Resolves COMPMID-4543 Change-Id: Ibb38e2394c616ac6e458568e73f09fb5243e94fe Signed-off-by: SiCongLi Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5717 Reviewed-by: Michele Di Giorgio Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins --- src/graph/mutators/NodeFusionMutator.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/graph/mutators/NodeFusionMutator.cpp b/src/graph/mutators/NodeFusionMutator.cpp index 1d47668cf2..5a696f8386 100644 --- a/src/graph/mutators/NodeFusionMutator.cpp +++ b/src/graph/mutators/NodeFusionMutator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 Arm Limited. + * Copyright (c) 2018-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -268,9 +268,12 @@ void fuse_node_with_activation(Graph &g, const Edge *output_edge, const std::set template void fuse_layer(Graph &g, std::function const &prec, const F fuse_fcn, Args &&... optional_arguments) { - // Not interested in the order of nodes - for(auto &node : g.nodes()) + // Note that fused nodes may be added to the end of the node list. + // Instead of only looping over the original list of nodes, we loop over the current node list which could be growing. + // This is intentional as it probes the newly added fused nodes for further fusing opportunities. + for(unsigned int i = 0; i < g.nodes().size(); ++i) { + auto node = g.node(i); // Check if the node is of type N and not a branching node if(node && node->type() == N1::node_type && node->output_edges().size() == 1) { -- cgit v1.2.1