From 6f109bdaed41bf9f37f201189f11ba30c60170fb Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Mon, 16 Jul 2018 12:57:42 +0100 Subject: COMPMID-1409: Disable BN + Act fusion in the graph if activation is not supported Change-Id: Ifba641d498638ac48bbc9624338a2168a56fe5c6 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/140075 Tested-by: Jenkins Reviewed-by: Anthony Barbier --- src/graph/mutators/NodeFusionMutator.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/graph') diff --git a/src/graph/mutators/NodeFusionMutator.cpp b/src/graph/mutators/NodeFusionMutator.cpp index 39209d2f49..6677330cec 100644 --- a/src/graph/mutators/NodeFusionMutator.cpp +++ b/src/graph/mutators/NodeFusionMutator.cpp @@ -29,6 +29,8 @@ #include "arm_compute/core/utils/misc/Cast.h" +#include + namespace arm_compute { namespace graph @@ -37,6 +39,9 @@ namespace detail { void fuse_batch_norm_with_activation(Graph &g) { + // Supported activations when fusing + const std::set supported_fused_activations = { Activation::RELU, Activation::BOUNDED_RELU, Activation::LU_BOUNDED_RELU }; + // Not interested in the order of nodes for(auto &node : g.nodes()) { @@ -48,14 +53,20 @@ void fuse_batch_norm_with_activation(Graph &g) // Check if following node is an activation layer node if((output_edge != nullptr) && (output_edge->consumer() != nullptr) && (output_edge->consumer()->type() == NodeType::ActivationLayer)) { - ARM_COMPUTE_LOG_GRAPH_VERBOSE("Fusing Batch Normalization node with ID : " << output_edge->producer_id() - << " with Activation Layer node with ID : " << output_edge->consumer_id() << std::endl); - auto *bn_node = arm_compute::utils::cast::polymorphic_downcast(output_edge->producer()); auto *act_node = arm_compute::utils::cast::polymorphic_downcast(output_edge->consumer()); ARM_COMPUTE_ERROR_ON(act_node->output(0) == nullptr || bn_node->output(0) == nullptr); + // Check if activation is supported for fusion + if(supported_fused_activations.count(act_node->activation_info().activation()) == 0) + { + continue; + } + + ARM_COMPUTE_LOG_GRAPH_VERBOSE("Fusing Batch Normalization node with ID : " << output_edge->producer_id() + << " with Activation Layer node with ID : " << output_edge->consumer_id() << std::endl); + // Prevent fusion if batch normalization node has an output accessor if(bn_node->output(0)->accessor() == nullptr) { -- cgit v1.2.1