Compute Library
 22.11
NodeFusionMutator Class Referencefinal

Mutation pass to fuss nodes. More...

#include <NodeFusionMutator.h>

Collaboration diagram for NodeFusionMutator:
[legend]

Public Member Functions

virtual void mutate (Graph &g) override
 Walk the graph and perform a specific mutation. More...
 
MutationType type () const override
 Returns mutation type. More...
 
const char * name () override
 Returns mutator name. More...
 
- Public Member Functions inherited from IGraphMutator
virtual ~IGraphMutator ()=default
 Virtual Destructor. More...
 

Additional Inherited Members

- Public Types inherited from IGraphMutator
enum  MutationType { IR, Backend }
 Mutation type. More...
 

Detailed Description

Mutation pass to fuss nodes.

Definition at line 35 of file NodeFusionMutator.h.

Member Function Documentation

◆ mutate()

void mutate ( Graph g)
overridevirtual

Walk the graph and perform a specific mutation.

Parameters
[in,out]gGraph to walk and mutate

Implements IGraphMutator.

Definition at line 805 of file NodeFusionMutator.cpp.

References ActivationLayerInfo::ABS, ARM_COMPUTE_ERROR_ON, ActivationLayerInfo::BOUNDED_RELU, arm_compute::graph::CL, Graph::edge(), ActivationLayerInfo::ELU, arm_compute::graph::detail::fuse_convolution_batch_normalization_with_post_ops(), arm_compute::graph::detail::fuse_convolution_with_batch_normalization(), arm_compute::graph::detail::fuse_convolution_with_post_ops(), arm_compute::graph::detail::fuse_depthwise_convolution_with_batch_normalization(), ActivationLayerInfo::HARD_SWISH, ActivationLayerInfo::IDENTITY, ActivationLayerInfo::LEAKY_RELU, ActivationLayerInfo::LINEAR, ActivationLayerInfo::LOGISTIC, ActivationLayerInfo::LU_BOUNDED_RELU, arm_compute::test::validation::n, arm_compute::QASYMM8, ActivationLayerInfo::RELU, ActivationLayerInfo::SOFT_RELU, ActivationLayerInfo::SQRT, ActivationLayerInfo::SQUARE, and ActivationLayerInfo::TANH.

806 {
807  // Supported activations when fusing
808  const std::set<Activation> supported_fused_activations = { Activation::ABS, Activation::BOUNDED_RELU, Activation::ELU,
813  };
814 
815  // Preconditions
816  auto empty_prec = [](INode &)
817  {
818  return true;
819  };
820  auto cl_target_prec = [](INode & n)
821  {
822  return n.assigned_target() == Target::CL;
823  };
824  auto qs8_prec = [&g](INode & n)
825  {
826  ARM_COMPUTE_ERROR_ON(n.output(0) == nullptr);
827 
828  const auto output_edge_id = *n.output_edges().begin();
829  const auto output_edge = g.edge(output_edge_id);
830  // To perform fusion the two nodes must have same output quantization information
831  const bool same_qinfo = n.output(0)->desc().quant_info == output_edge->producer()->output(0)->desc().quant_info;
832  const bool output_qasymm8 = n.output(0)->desc().data_type == DataType::QASYMM8;
833 
834  return (output_qasymm8 && same_qinfo) || !output_qasymm8;
835  };
836 
837  // Fusion mutations
838 
839  detail::fuse_layer<PadLayerNode, ConvolutionLayerNode>(g, empty_prec, detail::fuse_pad_with_convolution<ConvolutionLayerNode>);
840  detail::fuse_layer<PadLayerNode, DepthwiseConvolutionLayerNode>(g, empty_prec, detail::fuse_pad_with_convolution<DepthwiseConvolutionLayerNode>);
841  // The fusion of PostOps to ConvolutionLayer:
842  // It must occur after the fusion of PadLayer into ConvolutionLayer
843  // It must occur before the fusion of normal ActivationLayer into ConvolutionLayer as it takes precedence
844  detail::fuse_layer<ConvolutionLayerNode>(g, cl_target_prec, detail::fuse_convolution_with_post_ops, supported_fused_activations);
845  detail::fuse_layer<BatchNormalizationLayerNode, ActivationLayerNode>(g, empty_prec, detail::fuse_node_with_activation<BatchNormalizationLayerNode>, supported_fused_activations);
846  detail::fuse_layer<ConvolutionLayerNode, ActivationLayerNode>(g, empty_prec, detail::fuse_node_with_activation<ConvolutionLayerNode>, supported_fused_activations);
847  detail::fuse_layer<DepthwiseConvolutionLayerNode, ActivationLayerNode>(g, qs8_prec, detail::fuse_node_with_activation<DepthwiseConvolutionLayerNode>, supported_fused_activations);
848  detail::fuse_layer<FullyConnectedLayerNode, ActivationLayerNode>(g, empty_prec, detail::fuse_node_with_activation<FullyConnectedLayerNode>, supported_fused_activations);
849  detail::fuse_layer<EltwiseLayerNode, ActivationLayerNode>(g, cl_target_prec, detail::fuse_node_with_activation<EltwiseLayerNode>, supported_fused_activations);
850  // The fusion of BatchNormalizationLayer must occur after the fusion of ActivationLayer. Because FusedConvolutionBatchNormalizationNode assumes the BatchNormalization is already fused with activation, if any
851  detail::fuse_layer<ConvolutionLayerNode, BatchNormalizationLayerNode>(g, empty_prec, detail::fuse_convolution_with_batch_normalization);
852  detail::fuse_layer<DepthwiseConvolutionLayerNode, BatchNormalizationLayerNode>(g, empty_prec, detail::fuse_depthwise_convolution_with_batch_normalization);
853  detail::fuse_layer<FusedConvolutionBatchNormalizationNode>(g, cl_target_prec, detail::fuse_convolution_batch_normalization_with_post_ops, supported_fused_activations);
854 }
void fuse_convolution_with_batch_normalization(Graph &g, const Edge *output_edge)
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
void fuse_depthwise_convolution_with_batch_normalization(Graph &g, const Edge *output_edge)
void fuse_convolution_batch_normalization_with_post_ops(Graph &g, const Edge *output_edge, unsigned int conv_node_id, const std::set< Activation > &supported_fused_activations)
void fuse_convolution_with_post_ops(Graph &g, const Edge *output_edge, unsigned int conv_node_id, const std::set< Activation > &supported_fused_activations)
Fuse below operators:
quantized, asymmetric fixed-point 8-bit number unsigned
OpenCL capable target device.

◆ name()

const char * name ( )
overridevirtual

Returns mutator name.

Returns
Mutator name

Implements IGraphMutator.

Definition at line 795 of file NodeFusionMutator.cpp.

796 {
797  return "NodeFusionMutator";
798 }

◆ type()

IGraphMutator::MutationType type ( ) const
overridevirtual

Returns mutation type.

Returns
Mutation type enumeration

Implements IGraphMutator.

Definition at line 800 of file NodeFusionMutator.cpp.

References IGraphMutator::Backend.


The documentation for this class was generated from the following files: