Compute Library
 21.08
InPlaceOperationMutator Class Referencefinal

Mutation pass to optimize operations that can be performed in-place. More...

#include <InPlaceOperationMutator.h>

Collaboration diagram for InPlaceOperationMutator:
[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 optimize operations that can be performed in-place.

Definition at line 34 of file InPlaceOperationMutator.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 214 of file InPlaceOperationMutator.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_LOG_GRAPH_VERBOSE, arm_compute::mlgo::parser::end(), Graph::nodes(), and Edge::tensor().

215 {
216  std::set<NodeType> in_place_nodes =
217  {
225  };
226 
227  // Not interested in the order of nodes
228  for(auto &node : g.nodes())
229  {
230  if(node && in_place_nodes.find(node->type()) != std::end(in_place_nodes))
231  {
232  // Get input edge
233  Edge *input_edge = node->input_edge(0);
234 
235  // Check if parent has a single output if yes then force in place calculation else not
236  if((input_edge != nullptr) && output_edges_are_separate_tensors(g, input_edge))
237  {
238  if(node->type() == NodeType::EltwiseLayer)
239  {
240  try_in_place_elementwise(node);
241  }
243  {
244  try_in_place_depthwiseconv(node);
245  }
246  else
247  {
248  // Get current and new output tensors
249  auto current_output_tensor = node->output(0);
250  auto new_output_tensor = input_edge->tensor();
251 
252  ARM_COMPUTE_ERROR_ON(current_output_tensor == nullptr || new_output_tensor == nullptr);
253 
254  // Prevent in-place operation if there is an accessor bound to the in-place tensor or quantization info are different
255  if(new_output_tensor->accessor() != nullptr || current_output_tensor->desc().quant_info != new_output_tensor->desc().quant_info)
256  {
257  ARM_COMPUTE_LOG_GRAPH_VERBOSE("Prevented in-place operation as there is an accessor bound to the input tensor or the quantization info are different.\n");
258  }
259  else
260  {
261  set_new_output_and_inherit_accessor(node, current_output_tensor, new_output_tensor);
262  }
263  }
264  }
265  }
266  }
267 }
#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 end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
#define ARM_COMPUTE_LOG_GRAPH_VERBOSE(x)
Definition: Logger.h:50

◆ name()

const char * name ( )
overridevirtual

Returns mutator name.

Returns
Mutator name

Implements IGraphMutator.

Definition at line 204 of file InPlaceOperationMutator.cpp.

205 {
206  return "InPlaceOperationMutator";
207 }

◆ type()

IGraphMutator::MutationType type ( ) const
overridevirtual

Returns mutation type.

Returns
Mutation type enumeration

Implements IGraphMutator.

Definition at line 209 of file InPlaceOperationMutator.cpp.


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