ArmNN
 23.02
SubgraphView Class Referencefinal

The SubgraphView class represents a subgraph of a Graph. More...

#include <SubgraphView.hpp>

Inheritance diagram for SubgraphView:

Public Types

using SubgraphViewPtr = std::shared_ptr< SubgraphView >
 
using InputSlots = std::vector< InputSlot * >
 
using IInputSlots = std::vector< IInputSlot * >
 
using OutputSlots = std::vector< OutputSlot * >
 
using IOutputSlots = std::vector< IOutputSlot * >
 
using Layers = std::list< Layer * >
 
using IConnectableLayers = std::list< IConnectableLayer * >
 
using Iterator = Layers::iterator
 
using IConnectableLayerIterator = IConnectableLayers::iterator
 
using ConstIterator = Layers::const_iterator
 
using ConstIConnectableIterator = IConnectableLayers::const_iterator
 

Public Member Functions

template<typename Func >
void ForEachLayer (Func func) const
 
template<typename Func >
void ForEachIConnectableLayer (Func func) const
 
 SubgraphView (Graph &graph)
 Constructs a sub-graph from the entire given graph. More...
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use constructor with arguments: " "IConnectableLayers, IInputSlots and IOutputSlots", "23.08") SubgraphView(InputSlots &&inputs
 Constructs a sub-graph with the given arguments. More...
 
 SubgraphView (IConnectableLayers &&layers, IInputSlots &&inputs, IOutputSlots &&outputs)
 Constructs a sub-graph with the given arguments. More...
 
 SubgraphView (const SubgraphView &subgraph)
 Copy-constructor. More...
 
 SubgraphView (SubgraphView &&subgraph)
 Move-constructor. More...
 
 SubgraphView (IConnectableLayer *layer)
 Constructs a sub-graph with only the given layer. More...
 
SubgraphViewoperator= (SubgraphView &&other)
 Move-assignment operator. More...
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use GetIInputSlots() returning" " public IInputSlots", "23.08") const InputSlots &GetInputSlots() const
 
const IInputSlotsGetIInputSlots () const
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use GetIOutputSlots() returning" " public IOutputSlots", "23.08") const OutputSlots &GetOutputSlots() const
 
const IOutputSlotsGetIOutputSlots () const
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use GetIConnectableLayers() " "returning public IConnectableLayers", "23.08") const Layers &GetLayers() const
 
const IConnectableLayersGetIConnectableLayers () const
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use GetIInputSlot() returning public " "IInputSlot", "23.08") const InputSlot *GetInputSlot(unsigned int index) const
 
const IInputSlotGetIInputSlot (unsigned int index) const
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use GetIInputSlot() returning public " "IInputSlot", "23.08") InputSlot *GetInputSlot(unsigned int index)
 
IInputSlotGetIInputSlot (unsigned int index)
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use GetIOutputSlot() returning" " public IOutputSlot", "23.08") const OutputSlot *GetOutputSlot(unsigned int index) const
 
const IOutputSlotGetIOutputSlot (unsigned int index) const
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use GetIOutputSlot() returning" " public IOutputSlot", "23.08") OutputSlot *GetOutputSlot(unsigned int index)
 
IOutputSlotGetIOutputSlot (unsigned int index)
 
unsigned int GetNumInputSlots () const
 
unsigned int GetNumOutputSlots () const
 
 ARMNN_DEPRECATED_MSG_CHANGE_DATE ("This function is deprecated and will be changed to return an " "IConnectableLayerIterator, until that occurs in 23.08; please use " "beginIConnectable() returning public IConnectableLayerIterator", "23.08") Iterator begin()
 
IConnectableLayerIterator beginIConnectable ()
 
 ARMNN_DEPRECATED_MSG_CHANGE_DATE ("This function is deprecated and will be changed to return an " "IConnectableLayerIterator, until that occurs in 23.08; please use " "endIConnectable() returning public IConnectableLayerIterator", "23.08") Iterator end()
 
IConnectableLayerIterator endIConnectable ()
 
 ARMNN_DEPRECATED_MSG_CHANGE_DATE ("This function is deprecated and will be changed to return an " "ConstIConnectableIterator, until that occurs in 23.08; please use " "beginIConnectable() returning public ConstIConnectableIterator", "23.08") ConstIterator begin() const
 
ConstIConnectableIterator beginIConnectable () const
 
 ARMNN_DEPRECATED_MSG_CHANGE_DATE ("This function is deprecated and will be changed to return an " "ConstIConnectableIterator, until that occurs in 23.08; please use " "endIConnectable() returning public ConstIConnectableIterator", "23.08") ConstIterator end() const
 
ConstIConnectableIterator endIConnectable () const
 
 ARMNN_DEPRECATED_MSG_CHANGE_DATE ("This function is deprecated and will be changed to return an " "ConstIConnectableIterator, until that occurs in 23.08; please use " "cbeginIConnectable() returning public ConstIConnectableIterator", "23.08") ConstIterator cbegin() const
 
ConstIConnectableIterator cbeginIConnectable () const
 
 ARMNN_DEPRECATED_MSG_CHANGE_DATE ("This function is deprecated and will be changed to return an " "ConstIConnectableIterator, until that occurs in 23.08; please use " "cendIConnectable() returning public ConstIConnectableIterator", "23.08") ConstIterator cend() const
 
ConstIConnectableIterator cendIConnectable () const
 
void Clear ()
 
SubgraphView GetWorkingCopy () const
 This method returns a copy of the original SubgraphView provided by OptimizeSubgraphView with a separate underlying graph from the main ArmNN graph. More...
 
void SubstituteSubgraph (SubgraphView &, IConnectableLayer *)
 These methods should be called on a working copy subgraph created from GetWorkingCopy. More...
 
void SubstituteSubgraph (SubgraphView &, const SubgraphView &)
 
const IInputSlotsGetOriginalInputSlots () const
 These methods should be called on a working copy subgraph created from GetWorkingCopy. More...
 
const IOutputSlotsGetOriginalOutputSlots () const
 

Public Attributes

OutputSlots && outputs
 
OutputSlots Layers && layers
 

Detailed Description

The SubgraphView class represents a subgraph of a Graph.

The data it holds, points to data held by layers of the Graph, so the the contents of the SubgraphView become invalid when the Layers are destroyed or changed.

Definition at line 31 of file SubgraphView.hpp.

Member Typedef Documentation

◆ ConstIConnectableIterator

using ConstIConnectableIterator = IConnectableLayers::const_iterator

Definition at line 66 of file SubgraphView.hpp.

◆ ConstIterator

using ConstIterator = Layers::const_iterator

Definition at line 65 of file SubgraphView.hpp.

◆ IConnectableLayerIterator

using IConnectableLayerIterator = IConnectableLayers::iterator

Definition at line 64 of file SubgraphView.hpp.

◆ IConnectableLayers

Definition at line 62 of file SubgraphView.hpp.

◆ IInputSlots

using IInputSlots = std::vector<IInputSlot*>

Definition at line 58 of file SubgraphView.hpp.

◆ InputSlots

using InputSlots = std::vector<InputSlot*>

Definition at line 57 of file SubgraphView.hpp.

◆ IOutputSlots

using IOutputSlots = std::vector<IOutputSlot*>

Definition at line 60 of file SubgraphView.hpp.

◆ Iterator

using Iterator = Layers::iterator

Definition at line 63 of file SubgraphView.hpp.

◆ Layers

using Layers = std::list<Layer*>

Definition at line 61 of file SubgraphView.hpp.

◆ OutputSlots

using OutputSlots = std::vector<OutputSlot*>

Definition at line 59 of file SubgraphView.hpp.

◆ SubgraphViewPtr

using SubgraphViewPtr = std::shared_ptr<SubgraphView>

Definition at line 56 of file SubgraphView.hpp.

Constructor & Destructor Documentation

◆ SubgraphView() [1/5]

SubgraphView ( Graph graph)
explicit

Constructs a sub-graph from the entire given graph.

Definition at line 45 of file SubgraphView.cpp.

46  : enable_shared_from_this()
47  , m_InputSlots{}
48  , m_OutputSlots{}
49  , m_Layers(graph.begin(), graph.end())
50  , m_IConnectableLayers(graph.begin(), graph.end())
51 {
52  ArrangeBySortOrder();
53  CheckSubgraph();
54 }

◆ SubgraphView() [2/5]

Constructs a sub-graph with the given arguments.

IConnectable Duplication to maintain backwards compatibility.

Definition at line 71 of file SubgraphView.cpp.

74  : enable_shared_from_this()
75  , m_IInputSlots{inputs}
76  , m_IOutputSlots{outputs}
77  , m_IConnectableLayers(IConnectableLayers{layers.begin(), layers.end()})
78 {
79  // Cast from IConnectableLayer to Layer for backward compatibility
80  auto f = [](IConnectableLayer* value)
81  {
82  return PolymorphicDowncast<Layer*>(value);
83  };
84  std::transform(layers.begin(), layers.end(), std::back_inserter(m_Layers), f);
85 
86  m_InputSlots.resize(inputs.size());
87  m_IInputSlots.resize(inputs.size());
88  for (unsigned int i = 0; i < inputs.size(); i++)
89  {
90  m_InputSlots.at(i) = PolymorphicDowncast<InputSlot*>(inputs[i]);
91  m_IInputSlots.at(i) = inputs[i];
92  }
93 
94  m_OutputSlots.resize(outputs.size());
95  m_IOutputSlots.resize(outputs.size());
96  for (unsigned int i = 0; i < outputs.size(); i++)
97  {
98  m_OutputSlots.at(i) = PolymorphicDowncast<OutputSlot*>(outputs[i]);
99  m_IOutputSlots.at(i) = outputs[i];
100  }
101 
102  ArrangeBySortOrder();
103  CheckSubgraph();
104 }

◆ SubgraphView() [3/5]

SubgraphView ( const SubgraphView subgraph)

Copy-constructor.

Definition at line 144 of file SubgraphView.cpp.

145  : enable_shared_from_this()
146  , m_InputSlots(subgraph.m_InputSlots.begin(), subgraph.m_InputSlots.end())
147  , m_IInputSlots(subgraph.m_IInputSlots.begin(), subgraph.m_IInputSlots.end())
148  , m_OutputSlots(subgraph.m_OutputSlots.begin(), subgraph.m_OutputSlots.end())
149  , m_IOutputSlots(subgraph.m_IOutputSlots.begin(), subgraph.m_IOutputSlots.end())
150  , m_Layers(subgraph.m_Layers.begin(), subgraph.m_Layers.end())
151  , m_IConnectableLayers(IConnectableLayers{subgraph.m_IConnectableLayers.begin(),
152  subgraph.m_IConnectableLayers.end()})
153 {
154  ArrangeBySortOrder();
155  CheckSubgraph();
156 }

◆ SubgraphView() [4/5]

SubgraphView ( SubgraphView &&  subgraph)

Move-constructor.

Definition at line 158 of file SubgraphView.cpp.

159  : enable_shared_from_this()
160  , m_InputSlots(std::move(subgraph.m_InputSlots))
161  , m_IInputSlots(std::move(subgraph.m_IInputSlots))
162  , m_OutputSlots(std::move(subgraph.m_OutputSlots))
163  , m_IOutputSlots(std::move(subgraph.m_IOutputSlots))
164  , m_Layers(std::move(subgraph.m_Layers))
165  , m_IConnectableLayers(std::move(subgraph.m_IConnectableLayers))
166 {
167  ArrangeBySortOrder();
168  CheckSubgraph();
169 }

◆ SubgraphView() [5/5]

Constructs a sub-graph with only the given layer.

Definition at line 171 of file SubgraphView.cpp.

172  : enable_shared_from_this()
173  , m_Layers{PolymorphicDowncast<Layer*>(layer)}
174  , m_IConnectableLayers{layer}
175 {
176  unsigned int numInputSlots = layer->GetNumInputSlots();
177  m_InputSlots.resize(numInputSlots);
178  m_IInputSlots.resize(numInputSlots);
179  for (unsigned int i = 0; i < numInputSlots; i++)
180  {
181  m_InputSlots.at(i) = PolymorphicDowncast<InputSlot*>(&(layer->GetInputSlot(i)));
182  m_IInputSlots.at(i) = &(layer->GetInputSlot(i));
183  }
184 
185  unsigned int numOutputSlots = layer->GetNumOutputSlots();
186  m_OutputSlots.resize(numOutputSlots);
187  m_IOutputSlots.resize(numOutputSlots);
188  for (unsigned int i = 0; i < numOutputSlots; i++)
189  {
190  m_OutputSlots.at(i) = PolymorphicDowncast<OutputSlot*>(&(layer->GetOutputSlot(i)));
191  m_IOutputSlots.at(i) = &(layer->GetOutputSlot(i));
192  }
193 
194  CheckSubgraph();
195 }

Member Function Documentation

◆ ARMNN_DEPRECATED_MSG_CHANGE_DATE() [1/6]

ARMNN_DEPRECATED_MSG_CHANGE_DATE ( "This function is deprecated and will be changed to return an " "  ConstIConnectableIterator,
until that occurs in 23.08;please use " "beginIConnectable() returning public ConstIConnectableIterator ,
"23.08"   
) const

◆ ARMNN_DEPRECATED_MSG_CHANGE_DATE() [2/6]

ARMNN_DEPRECATED_MSG_CHANGE_DATE ( "This function is deprecated and will be changed to return an " "  ConstIConnectableIterator,
until that occurs in 23.08;please use " "cbeginIConnectable() returning public ConstIConnectableIterator ,
"23.08"   
) const

◆ ARMNN_DEPRECATED_MSG_CHANGE_DATE() [3/6]

ARMNN_DEPRECATED_MSG_CHANGE_DATE ( "This function is deprecated and will be changed to return an " "  ConstIConnectableIterator,
until that occurs in 23.08;please use " "cendIConnectable() returning public ConstIConnectableIterator ,
"23.08"   
) const

◆ ARMNN_DEPRECATED_MSG_CHANGE_DATE() [4/6]

ARMNN_DEPRECATED_MSG_CHANGE_DATE ( "This function is deprecated and will be changed to return an " "  ConstIConnectableIterator,
until that occurs in 23.08;please use " "endIConnectable() returning public ConstIConnectableIterator ,
"23.08"   
) const

◆ ARMNN_DEPRECATED_MSG_CHANGE_DATE() [5/6]

ARMNN_DEPRECATED_MSG_CHANGE_DATE ( "This function is deprecated and will be changed to return an " "  IConnectableLayerIterator,
until that occurs in 23.08;please use " "beginIConnectable() returning public IConnectableLayerIterator ,
"23.08"   
)

◆ ARMNN_DEPRECATED_MSG_CHANGE_DATE() [6/6]

ARMNN_DEPRECATED_MSG_CHANGE_DATE ( "This function is deprecated and will be changed to return an " "  IConnectableLayerIterator,
until that occurs in 23.08;please use " "endIConnectable() returning public IConnectableLayerIterator ,
"23.08"   
)

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [1/8]

ARMNN_DEPRECATED_MSG_REMOVAL_DATE ( "This function has been  deprecated,
please use constructor with arguments:" "  IConnectableLayers,
IInputSlots and IOutputSlots ,
"23.08"   
) &&

Constructs a sub-graph with the given arguments.

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [2/8]

ARMNN_DEPRECATED_MSG_REMOVAL_DATE ( "This function has been  deprecated,
please use GetIConnectableLayers() " "returning public IConnectableLayers ,
"23.08"   
) const &

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [3/8]

ARMNN_DEPRECATED_MSG_REMOVAL_DATE ( "This function has been  deprecated,
please use GetIInputSlot() returning public " "IInputSlot ,
"23.08"   
) const

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [4/8]

ARMNN_DEPRECATED_MSG_REMOVAL_DATE ( "This function has been  deprecated,
please use GetIInputSlot() returning public " "IInputSlot ,
"23.08"   
)

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [5/8]

ARMNN_DEPRECATED_MSG_REMOVAL_DATE ( "This function has been  deprecated,
please use GetIInputSlots() returning" " public IInputSlots ,
"23.08"   
) const &

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [6/8]

ARMNN_DEPRECATED_MSG_REMOVAL_DATE ( "This function has been  deprecated,
please use GetIOutputSlot() returning" " public IOutputSlot ,
"23.08"   
) const

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [7/8]

ARMNN_DEPRECATED_MSG_REMOVAL_DATE ( "This function has been  deprecated,
please use GetIOutputSlot() returning" " public IOutputSlot ,
"23.08"   
)

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [8/8]

ARMNN_DEPRECATED_MSG_REMOVAL_DATE ( "This function has been  deprecated,
please use GetIOutputSlots() returning" " public IOutputSlots ,
"23.08"   
) const &

◆ beginIConnectable() [1/2]

◆ beginIConnectable() [2/2]

ConstIConnectableIterator beginIConnectable ( ) const

◆ cbeginIConnectable()

SubgraphView::ConstIConnectableIterator cbeginIConnectable ( ) const

Definition at line 372 of file SubgraphView.cpp.

373 {
374  return beginIConnectable();
375 }

References SubgraphView::beginIConnectable().

◆ cendIConnectable()

SubgraphView::ConstIConnectableIterator cendIConnectable ( ) const

Definition at line 377 of file SubgraphView.cpp.

378 {
379  return endIConnectable();
380 }

References SubgraphView::endIConnectable().

◆ Clear()

void Clear ( )

Definition at line 382 of file SubgraphView.cpp.

383 {
384  m_InputSlots.clear();
385  m_OutputSlots.clear();
386  m_Layers.clear();
387 
388  m_IInputSlots.clear();
389  m_IOutputSlots.clear();
390  m_IConnectableLayers.clear();
391 }

◆ endIConnectable() [1/2]

◆ endIConnectable() [2/2]

ConstIConnectableIterator endIConnectable ( ) const

◆ ForEachIConnectableLayer()

void ForEachIConnectableLayer ( Func  func) const
inline

Definition at line 46 of file SubgraphView.hpp.

47  {
48  for (auto it = m_IConnectableLayers.begin(); it != m_IConnectableLayers.end(); )
49  {
50  auto next = std::next(it);
51  func(*it);
52  it = next;
53  }
54  }

Referenced by SubgraphView::SubstituteSubgraph(), and Graph::SubstituteSubgraph().

◆ ForEachLayer()

void ForEachLayer ( Func  func) const
inline

Definition at line 35 of file SubgraphView.hpp.

36  {
37  for (auto it = m_Layers.begin(); it != m_Layers.end(); )
38  {
39  auto next = std::next(it);
40  func(*it);
41  it = next;
42  }
43  }

◆ GetIConnectableLayers()

const SubgraphView::IConnectableLayers & GetIConnectableLayers ( ) const

Definition at line 308 of file SubgraphView.cpp.

309 {
310  return m_IConnectableLayers;
311 }

Referenced by armnn::ApplyBackendOptimizations(), SubgraphView::GetWorkingCopy(), SubgraphViewSelector::SelectSubgraphs(), and OptimizationViews::Validate().

◆ GetIInputSlot() [1/2]

IInputSlot * GetIInputSlot ( unsigned int  index)

Definition at line 268 of file SubgraphView.cpp.

269 {
270  return m_IInputSlots.at(index);
271 }

◆ GetIInputSlot() [2/2]

const IInputSlot * GetIInputSlot ( unsigned int  index) const

Definition at line 258 of file SubgraphView.cpp.

259 {
260  return m_IInputSlots.at(index);
261 }

◆ GetIInputSlots()

const SubgraphView::IInputSlots & GetIInputSlots ( ) const

◆ GetIOutputSlot() [1/2]

IOutputSlot * GetIOutputSlot ( unsigned int  index)

Definition at line 288 of file SubgraphView.cpp.

289 {
290  return m_IOutputSlots.at(index);
291 }

◆ GetIOutputSlot() [2/2]

const IOutputSlot * GetIOutputSlot ( unsigned int  index) const

Definition at line 278 of file SubgraphView.cpp.

279 {
280  return m_IOutputSlots.at(index);
281 }

Referenced by TosaRefBackend::OptimizeSubgraphView().

◆ GetIOutputSlots()

const SubgraphView::IOutputSlots & GetIOutputSlots ( ) const

Definition at line 248 of file SubgraphView.cpp.

249 {
250  return m_IOutputSlots;
251 }

Referenced by SubgraphView::GetWorkingCopy(), SubgraphView::SubstituteSubgraph(), and OptimizationViews::Validate().

◆ GetNumInputSlots()

unsigned int GetNumInputSlots ( ) const

Definition at line 293 of file SubgraphView.cpp.

294 {
295  return armnn::numeric_cast<unsigned int>(m_IInputSlots.size());
296 }

Referenced by TosaRefBackend::OptimizeSubgraphView().

◆ GetNumOutputSlots()

unsigned int GetNumOutputSlots ( ) const

Definition at line 298 of file SubgraphView.cpp.

299 {
300  return armnn::numeric_cast<unsigned int>(m_IOutputSlots.size());
301 }

Referenced by TosaRefBackend::OptimizeSubgraphView().

◆ GetOriginalInputSlots()

const SubgraphView::IInputSlots & GetOriginalInputSlots ( ) const

These methods should be called on a working copy subgraph created from GetWorkingCopy.

They return pointers to the input and output Slots belonging to the original SubgraphView that the working copy was created from. This may be used to find the original TensorInfo of connected boundary OutputSlots.

Definition at line 638 of file SubgraphView.cpp.

639 {
640  if (!p_WorkingCopyImpl)
641  {
642  throw NullPointerException("The SubgraphView calling GetOriginalInputSlots is not a working copy. "
643  "Call this function on SubgraphView returned from SubgraphView::GetWorkingCopy()");
644  }
645  if (!p_WorkingCopyImpl->m_OriginalSubgraphView)
646  {
647  throw NullPointerException("The working copy SubgraphView pointer to its original SubgraphView is null.");
648  }
649  return p_WorkingCopyImpl->m_OriginalSubgraphView->GetIInputSlots();
650 }

◆ GetOriginalOutputSlots()

const SubgraphView::IOutputSlots & GetOriginalOutputSlots ( ) const

Definition at line 651 of file SubgraphView.cpp.

652 {
653  if (!p_WorkingCopyImpl)
654  {
655  throw NullPointerException("The SubgraphView calling GetOriginalOutputSlots is not a working copy. "
656  "Call this function on SubgraphView returned from SubgraphView::GetWorkingCopy()");
657  }
658  if (!p_WorkingCopyImpl->m_OriginalSubgraphView)
659  {
660  throw NullPointerException("The working copy SubgraphView pointer to its original SubgraphView is null.");
661  }
662  return p_WorkingCopyImpl->m_OriginalSubgraphView->GetIOutputSlots();
663 }

◆ GetWorkingCopy()

SubgraphView GetWorkingCopy ( ) const

This method returns a copy of the original SubgraphView provided by OptimizeSubgraphView with a separate underlying graph from the main ArmNN graph.

Backend users should edit this working copy and then add it as a SubstitutionPair, along with original SubgraphView, to the OptimizationViews returned by OptimizeSubgraphView. ArmNN will then decide on whether or not to carry out Substitution of the two SubgraphViews.

Definition at line 429 of file SubgraphView.cpp.

430 {
431  if (p_WorkingCopyImpl)
432  {
433  throw Exception("The SubgraphView calling GetWorkingCopy() is already a working copy. This function "
434  "should be called on original SubgraphView obtained from OptimizeSubgraphView()");
435  }
436 
437  // Create a cut down SubgraphView with underlying graph containing only the relevant layers.
438  // It needs its own underlying layers so that they can be replaced safely.
439  auto ptr = std::make_shared<SubgraphViewWorkingCopy>(Graph(), shared_from_this());
440 
441  std::unordered_map<const IConnectableLayer*, IConnectableLayer*> originalToClonedLayerMap;
442  std::list<armnn::IConnectableLayer*> originalSubgraphLayers = GetIConnectableLayers();
443 
444  for (auto&& originalLayer : originalSubgraphLayers)
445  {
446  Layer* const layer = PolymorphicDowncast<const Layer*>(originalLayer)->Clone(ptr->m_Graph);
447  originalToClonedLayerMap.emplace(originalLayer, layer);
448  }
449 
450  SubgraphView::IInputSlots workingCopyInputs;
451  // Add IInputSlots to workingCopy
452  for (auto originalSubgraphInputSlot : GetIInputSlots())
453  {
454  const IConnectableLayer& originalSubgraphLayer =
455  PolymorphicDowncast<InputSlot*>(originalSubgraphInputSlot)->GetOwningLayer();
456 
457  auto* clonedLayer = originalToClonedLayerMap[&originalSubgraphLayer];
458 
459  workingCopyInputs.push_back(&clonedLayer->GetInputSlot(originalSubgraphInputSlot->GetSlotIndex()));
460  }
461 
462  for (auto originalSubgraphLayer : originalSubgraphLayers)
463  {
464  IConnectableLayer* const clonedLayer = originalToClonedLayerMap[originalSubgraphLayer];
465 
466  // OutputLayers have no OutputSlots to be connected
467  if (clonedLayer->GetType() != LayerType::Output)
468  {
469  // connect all cloned layers as per original subgraph
470  for (unsigned int i = 0; i < clonedLayer->GetNumOutputSlots(); i++)
471  {
472  auto& originalOutputSlot = originalSubgraphLayer->GetOutputSlot(i);
473  auto& clonedOutputSlot = clonedLayer->GetOutputSlot(i);
474  for (unsigned int j = 0; j < originalOutputSlot.GetNumConnections(); j++)
475  {
476  // nextLayer is the layer with IInputSlot connected to IOutputSlot we are working on
477  const IConnectableLayer& nextLayerOnOriginalSubgraph =
478  originalOutputSlot.GetConnection(j)->GetOwningIConnectableLayer();
479 
480  // Check the layer is in our map and so has a clonedLayer
481  if (originalToClonedLayerMap.find(&nextLayerOnOriginalSubgraph) != originalToClonedLayerMap.end())
482  {
483  auto* nextLayerOnClonedSubgraph = originalToClonedLayerMap[&nextLayerOnOriginalSubgraph];
484 
485  auto index = PolymorphicDowncast<OutputSlot*>(
486  &originalOutputSlot)->GetConnection(j)->GetSlotIndex();
487 
488  IInputSlot& inputSlot = nextLayerOnClonedSubgraph->GetInputSlot(index);
489 
490  // Then make the connection
491  clonedOutputSlot.Connect(inputSlot);
492  }
493  }
494  // Copy the tensorInfo to the clonedOutputSlot
495  clonedOutputSlot.SetTensorInfo(originalOutputSlot.GetTensorInfo());
496  }
497  }
498  }
499 
500  SubgraphView::IOutputSlots workingCopyOutputs;
501 
502  // Add IOutputSlots to workingCopy
503  for (auto outputSlot : GetIOutputSlots())
504  {
505  auto outputSlotIndex = outputSlot->CalculateIndexOnOwner();
506  const IConnectableLayer& originalSubgraphLayer = outputSlot->GetOwningIConnectableLayer();
507 
508  // OutputLayers have no OutputSlots to be connected
509  if (originalSubgraphLayer.GetType() != LayerType::Output)
510  {
511  IConnectableLayer* clonedLayer = originalToClonedLayerMap[&originalSubgraphLayer];
512 
513  // Add the OutputSlot of clonedLayer to WorkingCopy OutputSlots
514  workingCopyOutputs.push_back(&clonedLayer->GetOutputSlot(outputSlotIndex));
515  }
516  }
517 
518  SubgraphView::IConnectableLayers workingCopyLayers;
519  for (auto& pair : originalToClonedLayerMap)
520  {
521  workingCopyLayers.push_back(pair.second);
522  }
523 
524  return {std::move(workingCopyLayers),
525  std::move(workingCopyInputs),
526  std::move(workingCopyOutputs),
527  ptr};
528 }

References Layer::Clone(), SubgraphView::GetIConnectableLayers(), SubgraphView::GetIInputSlots(), SubgraphView::GetIOutputSlots(), IConnectableLayer::GetNumOutputSlots(), IConnectableLayer::GetOutputSlot(), IConnectableLayer::GetType(), and armnn::Output.

◆ operator=()

SubgraphView & operator= ( SubgraphView &&  other)

Move-assignment operator.

Definition at line 197 of file SubgraphView.cpp.

198 {
199  m_InputSlots = std::move(other.m_InputSlots);
200  m_IInputSlots = std::move(other.m_IInputSlots);
201  m_OutputSlots = std::move(other.m_OutputSlots);
202  m_IOutputSlots = std::move(other.m_IOutputSlots);
203  m_Layers = std::move(other.m_Layers);
204  m_IConnectableLayers = std::move(other.m_IConnectableLayers);
205 
206  CheckSubgraph();
207 
208  return *this;
209 }

◆ SubstituteSubgraph() [1/2]

void SubstituteSubgraph ( SubgraphView patternSubgraph,
const SubgraphView substituteSubgraph 
)

Definition at line 572 of file SubgraphView.cpp.

573 {
574  if (!p_WorkingCopyImpl)
575  {
576  throw NullPointerException("The SubgraphView calling SubstituteSubgraphView is not a working copy. "
577  "Call this function on SubgraphView returned from SubgraphView::GetWorkingCopy()");
578  }
579 
580  auto numPatternInputs = patternSubgraph.GetIInputSlots().size();
581  auto numSubInputs = substituteSubgraph.GetIInputSlots().size();
582  if (numPatternInputs != numSubInputs)
583  {
585  fmt::format("Number of InputSlots on substitute SubgraphView ({}) must equal the number of"
586  " InputSlots on pattern SubgraphView ({})",
587  numSubInputs,
588  numPatternInputs));
589  }
590 
591  auto numPatternOutputs = patternSubgraph.GetIOutputSlots().size();
592  auto numSubOutputs = substituteSubgraph.GetIOutputSlots().size();
593  if (numPatternOutputs != numSubOutputs)
594  {
596  fmt::format("Number of OutputSlots on substitute SubgraphView ({}) must equal the number of"
597  " OutputSlots on pattern SubgraphView ({})",
598  numSubOutputs,
599  numPatternOutputs));
600  }
601 
602  // Add substitute layer to the Main graph i.e. graph in p_WorkingCopyImpl
603  auto workingCopyGraph = &p_WorkingCopyImpl->m_Graph;
604  substituteSubgraph.ForEachIConnectableLayer([workingCopyGraph](IConnectableLayer* iConnectableLayer)
605  {
606  // Search WorkingCopy Graph for substituteLayer and add if missing
607  if (std::find(std::begin(workingCopyGraph->m_Layers),
608  std::end(workingCopyGraph->m_Layers),
609  iConnectableLayer) ==
610  std::end(workingCopyGraph->m_Layers))
611  {
612  auto layer = PolymorphicDowncast<Layer*>(iConnectableLayer);
613 
614  layer->Reparent(*workingCopyGraph,
615  (workingCopyGraph->m_Layers).end());
616 
617  workingCopyGraph->m_LayersInOrder = false;
618  }
619  });
620 
621  // Replace the old connections with connections to new layer
622  workingCopyGraph->ReplaceSubgraphConnections(patternSubgraph, substituteSubgraph);
623 
624  // Update input/outputSlot pointers
625  UpdateSubgraphViewSlotPointers(patternSubgraph, substituteSubgraph);
626 
627  // Delete the old layers.
628  workingCopyGraph->EraseSubgraphLayers(patternSubgraph);
629 
630  // Sort
631  workingCopyGraph->TopologicalSort();
632 
633  // Update SubgraphView layer pointers to match those of the internal WorkingCopy layer pointers
634  m_IConnectableLayers = IConnectableLayers{ workingCopyGraph->m_Layers.begin(),
635  workingCopyGraph->m_Layers.end() };
636 }

References SubgraphView::ForEachIConnectableLayer(), SubgraphView::GetIInputSlots(), and SubgraphView::GetIOutputSlots().

◆ SubstituteSubgraph() [2/2]

void SubstituteSubgraph ( SubgraphView subgraph,
IConnectableLayer substituteLayer 
)

These methods should be called on a working copy subgraph created from GetWorkingCopy.

They take a SubgraphView pattern to replace and the substitute layer or subgraphView to substitute in.

Definition at line 530 of file SubgraphView.cpp.

531 {
532  ARMNN_ASSERT(substituteLayer != nullptr);
533  SubgraphView substituteSubgraph(substituteLayer);
534 
535  SubstituteSubgraph(subgraph, substituteSubgraph);
536 }

References ARMNN_ASSERT.

Member Data Documentation

◆ layers

OutputSlots Layers&& layers

Definition at line 74 of file SubgraphView.hpp.

◆ outputs

OutputSlots&& outputs

Definition at line 74 of file SubgraphView.hpp.


The documentation for this class was generated from the following files:
armnn::SubgraphView::beginIConnectable
IConnectableLayerIterator beginIConnectable()
Definition: SubgraphView.cpp:324
armnn::SubgraphView::SubstituteSubgraph
void SubstituteSubgraph(SubgraphView &, IConnectableLayer *)
These methods should be called on a working copy subgraph created from GetWorkingCopy.
Definition: SubgraphView.cpp:530
armnn::SubgraphView::IConnectableLayers
std::list< IConnectableLayer * > IConnectableLayers
Definition: SubgraphView.hpp:62
armnn::SubgraphView::GetIConnectableLayers
const IConnectableLayers & GetIConnectableLayers() const
Definition: SubgraphView.cpp:308
armnn::SubgraphView::outputs
OutputSlots && outputs
Definition: SubgraphView.hpp:74
armnn::SubgraphView::IInputSlots
std::vector< IInputSlot * > IInputSlots
Definition: SubgraphView.hpp:58
armnn::SubgraphView::endIConnectable
IConnectableLayerIterator endIConnectable()
Definition: SubgraphView.cpp:329
armnn::SubgraphView::SubgraphView
SubgraphView(Graph &graph)
Constructs a sub-graph from the entire given graph.
Definition: SubgraphView.cpp:45
armnn::SubgraphView::IOutputSlots
std::vector< IOutputSlot * > IOutputSlots
Definition: SubgraphView.hpp:60
armnn::SubgraphView::layers
OutputSlots Layers && layers
Definition: SubgraphView.hpp:74
ARMNN_ASSERT
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
armnn::SubgraphView::GetIInputSlots
const IInputSlots & GetIInputSlots() const
Definition: SubgraphView.cpp:238
armnn::LayerType::Output
@ Output
armnn::SubgraphView::GetIOutputSlots
const IOutputSlots & GetIOutputSlots() const
Definition: SubgraphView.cpp:248
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80