ArmNN
 23.02
SquashEqualSiblingsImpl< Comparable > Class Template Reference

#include <SquashEqualSiblings.hpp>

Public Member Functions

void Run (Graph &graph, InputSlot &connection) const
 Run for every connection between a base Layer (any) and a child ComparableLayer. More...
 

Protected Member Functions

 SquashEqualSiblingsImpl ()=default
 
 ~SquashEqualSiblingsImpl ()=default
 

Detailed Description

template<typename Comparable>
class armnn::optimizations::SquashEqualSiblingsImpl< Comparable >

Definition at line 18 of file SquashEqualSiblings.hpp.

Constructor & Destructor Documentation

◆ SquashEqualSiblingsImpl()

SquashEqualSiblingsImpl ( )
protecteddefault

◆ ~SquashEqualSiblingsImpl()

~SquashEqualSiblingsImpl ( )
protecteddefault

Member Function Documentation

◆ Run()

void Run ( Graph graph,
InputSlot connection 
) const
inline

Run for every connection between a base Layer (any) and a child ComparableLayer.

For all siblings of the child layer that compare equal to it, bypasses and removes them. I.e., moves the connections in the outputs of the siblings to the outputs of the child layer, so the siblings are left unconnected (and later removed).

Definition at line 25 of file SquashEqualSiblings.hpp.

26  {
27  IgnoreUnused(graph);
28  auto& child = connection.GetOwningLayer();
29 
30  if (!child.IsOutputUnconnected())
31  {
32  OutputSlot& baseOutput = *connection.GetConnectedOutputSlot();
33 
34  if (baseOutput.GetNumConnections() > 1)
35  {
36  auto& comparableChild = *PolymorphicDowncast<Comparable*>(&child);
37 
38  Layer* lowestPriorityChild = &child;
39  for (auto&& it : baseOutput.GetConnections())
40  {
41  Layer* sibling = &it->GetOwningLayer();
42  if ((sibling != lowestPriorityChild) && comparableChild.IsEqual(*sibling))
43  {
44  if (sibling->GetPriority() < lowestPriorityChild->GetPriority())
45  {
46  std::swap(sibling, lowestPriorityChild);
47  }
48  // Bypasses sibling. It will be removed as it's left unconnected.
49  auto siblingOut = sibling->BeginOutputSlots();
50  for (auto lowestPriorityChildOut = lowestPriorityChild->BeginOutputSlots();
51  lowestPriorityChildOut != lowestPriorityChild->EndOutputSlots(); ++lowestPriorityChildOut)
52  {
53  siblingOut->MoveAllConnections(*lowestPriorityChildOut);
54  ++siblingOut;
55  }
56  }
57  }
58  }
59  }
60  }

References Layer::BeginOutputSlots(), Layer::EndOutputSlots(), InputSlot::GetConnectedOutputSlot(), OutputSlot::GetConnections(), OutputSlot::GetNumConnections(), InputSlot::GetOwningLayer(), Layer::GetPriority(), armnn::IgnoreUnused(), and armnn::swap().


The documentation for this class was generated from the following file:
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::swap
void swap(OriginsDescriptor &first, OriginsDescriptor &second)
Definition: Descriptors.cpp:350