ArmNN
 22.08
SubgraphView Class Referencefinal

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

#include <SubgraphView.hpp>

Public Types

using SubgraphViewPtr = std::unique_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.02; please use " "beginIConnectable() returning public IConnectableLayerIterator", "23.02") 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.02; please use " "endIConnectable() returning public IConnectableLayerIterator", "23.02") 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.02; please use " "beginIConnectable() returning public ConstIConnectableIterator", "23.02") 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.02; please use " "endIConnectable() returning public ConstIConnectableIterator", "23.02") 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.02; please use " "cbeginIConnectable() returning public ConstIConnectableIterator", "23.02") 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.02; please use " "cendIConnectable() returning public ConstIConnectableIterator", "23.02") 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 &)
 

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 23 of file SubgraphView.hpp.

Member Typedef Documentation

◆ ConstIConnectableIterator

using ConstIConnectableIterator = IConnectableLayers::const_iterator

Definition at line 58 of file SubgraphView.hpp.

◆ ConstIterator

using ConstIterator = Layers::const_iterator

Definition at line 57 of file SubgraphView.hpp.

◆ IConnectableLayerIterator

using IConnectableLayerIterator = IConnectableLayers::iterator

Definition at line 56 of file SubgraphView.hpp.

◆ IConnectableLayers

Definition at line 54 of file SubgraphView.hpp.

◆ IInputSlots

using IInputSlots = std::vector<IInputSlot*>

Definition at line 50 of file SubgraphView.hpp.

◆ InputSlots

using InputSlots = std::vector<InputSlot*>

Definition at line 49 of file SubgraphView.hpp.

◆ IOutputSlots

using IOutputSlots = std::vector<IOutputSlot*>

Definition at line 52 of file SubgraphView.hpp.

◆ Iterator

using Iterator = Layers::iterator

Definition at line 55 of file SubgraphView.hpp.

◆ Layers

using Layers = std::list<Layer*>

Definition at line 53 of file SubgraphView.hpp.

◆ OutputSlots

using OutputSlots = std::vector<OutputSlot*>

Definition at line 51 of file SubgraphView.hpp.

◆ SubgraphViewPtr

using SubgraphViewPtr = std::unique_ptr<SubgraphView>

Definition at line 48 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 44 of file SubgraphView.cpp.

References SubgraphView::layers, and SubgraphView::outputs.

Referenced by SubgraphView::SubgraphView().

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

◆ SubgraphView() [2/5]

Constructs a sub-graph with the given arguments.

IConnectable Duplication to maintain backwards compatibility.

Definition at line 68 of file SubgraphView.cpp.

References SubgraphView::layers, SubgraphView::outputs, and SubgraphView::SubgraphView().

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

◆ SubgraphView() [3/5]

SubgraphView ( const SubgraphView subgraph)

Copy-constructor.

Definition at line 139 of file SubgraphView.cpp.

140  : m_InputSlots(subgraph.m_InputSlots.begin(), subgraph.m_InputSlots.end())
141  , m_IInputSlots(subgraph.m_IInputSlots.begin(), subgraph.m_IInputSlots.end())
142  , m_OutputSlots(subgraph.m_OutputSlots.begin(), subgraph.m_OutputSlots.end())
143  , m_IOutputSlots(subgraph.m_IOutputSlots.begin(), subgraph.m_IOutputSlots.end())
144  , m_Layers(subgraph.m_Layers.begin(), subgraph.m_Layers.end())
145  , m_IConnectableLayers(IConnectableLayers{subgraph.m_IConnectableLayers.begin(),
146  subgraph.m_IConnectableLayers.end()})
147 {
148  ArrangeBySortOrder();
149  CheckSubgraph();
150 }
std::list< IConnectableLayer * > IConnectableLayers

◆ SubgraphView() [4/5]

SubgraphView ( SubgraphView &&  subgraph)

Move-constructor.

Definition at line 152 of file SubgraphView.cpp.

153  : m_InputSlots(std::move(subgraph.m_InputSlots))
154  , m_IInputSlots(std::move(subgraph.m_IInputSlots))
155  , m_OutputSlots(std::move(subgraph.m_OutputSlots))
156  , m_IOutputSlots(std::move(subgraph.m_IOutputSlots))
157  , m_Layers(std::move(subgraph.m_Layers))
158  , m_IConnectableLayers(std::move(subgraph.m_IConnectableLayers))
159 {
160  ArrangeBySortOrder();
161  CheckSubgraph();
162 }

◆ SubgraphView() [5/5]

Constructs a sub-graph with only the given layer.

Definition at line 164 of file SubgraphView.cpp.

165  : m_Layers{PolymorphicDowncast<Layer*>(layer)}
166  , m_IConnectableLayers{layer}
167 {
168  unsigned int numInputSlots = layer->GetNumInputSlots();
169  m_InputSlots.resize(numInputSlots);
170  m_IInputSlots.resize(numInputSlots);
171  for (unsigned int i = 0; i < numInputSlots; i++)
172  {
173  m_InputSlots.at(i) = PolymorphicDowncast<InputSlot*>(&(layer->GetInputSlot(i)));
174  m_IInputSlots.at(i) = &(layer->GetInputSlot(i));
175  }
176 
177  unsigned int numOutputSlots = layer->GetNumOutputSlots();
178  m_OutputSlots.resize(numOutputSlots);
179  m_IOutputSlots.resize(numOutputSlots);
180  for (unsigned int i = 0; i < numOutputSlots; i++)
181  {
182  m_OutputSlots.at(i) = PolymorphicDowncast<OutputSlot*>(&(layer->GetOutputSlot(i)));
183  m_IOutputSlots.at(i) = &(layer->GetOutputSlot(i));
184  }
185 
186  CheckSubgraph();
187 }

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 " "  IConnectableLayerIterator,
until that occurs in 23.02;please use " "beginIConnectable() returning public IConnectableLayerIterator ,
"23.02"   
)

◆ ARMNN_DEPRECATED_MSG_CHANGE_DATE() [2/6]

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

◆ 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.02;please use " "beginIConnectable() returning public ConstIConnectableIterator ,
"23.02"   
) 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.02;please use " "endIConnectable() returning public ConstIConnectableIterator ,
"23.02"   
) const

◆ ARMNN_DEPRECATED_MSG_CHANGE_DATE() [5/6]

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

◆ ARMNN_DEPRECATED_MSG_CHANGE_DATE() [6/6]

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

◆ 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 GetIInputSlots() returning" " public IInputSlots ,
"23.08"   
) const &

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [3/8]

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

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [4/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() [5/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() [6/8]

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

◆ 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"   
) const

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [8/8]

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

◆ beginIConnectable() [1/2]

◆ beginIConnectable() [2/2]

SubgraphView::ConstIConnectableIterator beginIConnectable ( ) const

Definition at line 337 of file SubgraphView.cpp.

338 {
339  return m_IConnectableLayers.begin();
340 }

◆ cbeginIConnectable()

SubgraphView::ConstIConnectableIterator cbeginIConnectable ( ) const

Definition at line 364 of file SubgraphView.cpp.

References SubgraphView::beginIConnectable().

365 {
366  return beginIConnectable();
367 }
IConnectableLayerIterator beginIConnectable()

◆ cendIConnectable()

SubgraphView::ConstIConnectableIterator cendIConnectable ( ) const

Definition at line 369 of file SubgraphView.cpp.

References SubgraphView::endIConnectable().

370 {
371  return endIConnectable();
372 }
IConnectableLayerIterator endIConnectable()

◆ Clear()

void Clear ( )

Definition at line 374 of file SubgraphView.cpp.

Referenced by Graph::SubstituteSubgraph().

375 {
376  m_InputSlots.clear();
377  m_OutputSlots.clear();
378  m_Layers.clear();
379 
380  m_IInputSlots.clear();
381  m_IOutputSlots.clear();
382  m_IConnectableLayers.clear();
383 }

◆ endIConnectable() [1/2]

◆ endIConnectable() [2/2]

SubgraphView::ConstIConnectableIterator endIConnectable ( ) const

Definition at line 342 of file SubgraphView.cpp.

References ARMNN_NO_DEPRECATE_WARN_BEGIN, and ARMNN_NO_DEPRECATE_WARN_END.

343 {
344  return m_IConnectableLayers.end();
345 }

◆ ForEachIConnectableLayer()

void ForEachIConnectableLayer ( Func  func) const
inline

Definition at line 38 of file SubgraphView.hpp.

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

39  {
40  for (auto it = m_IConnectableLayers.begin(); it != m_IConnectableLayers.end(); )
41  {
42  auto next = std::next(it);
43  func(*it);
44  it = next;
45  }
46  }

◆ ForEachLayer()

void ForEachLayer ( Func  func) const
inline

Definition at line 27 of file SubgraphView.hpp.

Referenced by TEST_SUITE().

28  {
29  for (auto it = m_Layers.begin(); it != m_Layers.end(); )
30  {
31  auto next = std::next(it);
32  func(*it);
33  it = next;
34  }
35  }

◆ GetIConnectableLayers()

◆ GetIInputSlot() [1/2]

const IInputSlot * GetIInputSlot ( unsigned int  index) const

Definition at line 250 of file SubgraphView.cpp.

251 {
252  return m_IInputSlots.at(index);
253 }

◆ GetIInputSlot() [2/2]

IInputSlot * GetIInputSlot ( unsigned int  index)

Definition at line 260 of file SubgraphView.cpp.

261 {
262  return m_IInputSlots.at(index);
263 }

◆ GetIInputSlots()

const SubgraphView::IInputSlots & GetIInputSlots ( ) const

◆ GetIOutputSlot() [1/2]

const IOutputSlot * GetIOutputSlot ( unsigned int  index) const

Definition at line 270 of file SubgraphView.cpp.

271 {
272  return m_IOutputSlots.at(index);
273 }

◆ GetIOutputSlot() [2/2]

IOutputSlot * GetIOutputSlot ( unsigned int  index)

Definition at line 280 of file SubgraphView.cpp.

281 {
282  return m_IOutputSlots.at(index);
283 }

◆ GetIOutputSlots()

const SubgraphView::IOutputSlots & GetIOutputSlots ( ) const

Definition at line 240 of file SubgraphView.cpp.

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

241 {
242  return m_IOutputSlots;
243 }

◆ GetNumInputSlots()

unsigned int GetNumInputSlots ( ) const

Definition at line 285 of file SubgraphView.cpp.

References armnn::numeric_cast().

286 {
287  return armnn::numeric_cast<unsigned int>(m_IInputSlots.size());
288 }
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35

◆ GetNumOutputSlots()

unsigned int GetNumOutputSlots ( ) const

Definition at line 290 of file SubgraphView.cpp.

References armnn::numeric_cast().

291 {
292  return armnn::numeric_cast<unsigned int>(m_IOutputSlots.size());
293 }
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35

◆ 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 419 of file SubgraphView.cpp.

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

Referenced by TEST_SUITE().

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

◆ operator=()

SubgraphView & operator= ( SubgraphView &&  other)

Move-assignment operator.

Definition at line 189 of file SubgraphView.cpp.

190 {
191  m_InputSlots = std::move(other.m_InputSlots);
192  m_IInputSlots = std::move(other.m_IInputSlots);
193  m_OutputSlots = std::move(other.m_OutputSlots);
194  m_IOutputSlots = std::move(other.m_IOutputSlots);
195  m_Layers = std::move(other.m_Layers);
196  m_IConnectableLayers = std::move(other.m_IConnectableLayers);
197 
198  CheckSubgraph();
199 
200  return *this;
201 }

◆ SubstituteSubgraph() [1/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 520 of file SubgraphView.cpp.

References ARMNN_ASSERT.

Referenced by TEST_SUITE().

521 {
522  ARMNN_ASSERT(substituteLayer != nullptr);
523  SubgraphView substituteSubgraph(substituteLayer);
524 
525  SubstituteSubgraph(subgraph, substituteSubgraph);
526 }
void SubstituteSubgraph(SubgraphView &, IConnectableLayer *)
These methods should be called on a working copy subgraph created from GetWorkingCopy.
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
SubgraphView(Graph &graph)
Constructs a sub-graph from the entire given graph.

◆ SubstituteSubgraph() [2/2]

void SubstituteSubgraph ( SubgraphView patternSubgraph,
const SubgraphView substituteSubgraph 
)

Definition at line 528 of file SubgraphView.cpp.

References SubgraphView::ForEachIConnectableLayer().

529 {
530  if (!p_WorkingCopyImpl)
531  {
532  throw NullPointerException("The SubgraphView calling SubstituteSubgraphView is not a working copy. "
533  "Call this function on SubgraphView returned from SubgraphView::GetWorkingCopy()");
534  }
535 
536  // Add substitute layer to the Main graph i.e. graph in p_WorkingCopyImpl
537  auto workingCopyGraph = &p_WorkingCopyImpl->m_Graph;
538  substituteSubgraph.ForEachIConnectableLayer([workingCopyGraph](IConnectableLayer* iConnectableLayer)
539  {
540  // Search WorkingCopy Graph for substituteLayer and add if missing
541  if (std::find(std::begin(workingCopyGraph->m_Layers),
542  std::end(workingCopyGraph->m_Layers),
543  iConnectableLayer) ==
544  std::end(workingCopyGraph->m_Layers))
545  {
546  auto layer = PolymorphicDowncast<Layer*>(iConnectableLayer);
547 
548  layer->Reparent(*workingCopyGraph,
549  (workingCopyGraph->m_Layers).end());
550 
551  workingCopyGraph->m_LayersInOrder = false;
552  }
553  });
554 
555  // Replace the old connections with connections to new layer
556  workingCopyGraph->ReplaceSubgraphConnections(patternSubgraph, substituteSubgraph);
557 
558  // Update input/outputSlot pointers
559  m_IInputSlots = std::move(substituteSubgraph.m_IInputSlots);
560  m_IOutputSlots = std::move(substituteSubgraph.m_IOutputSlots);
561 
562  // Delete the old layers.
563  workingCopyGraph->EraseSubgraphLayers(patternSubgraph);
564 
565  // Sort
566  workingCopyGraph->TopologicalSort();
567 
568  // Update SubgraphView layer pointers to match those of the internal WorkingCopy layer pointers
569  m_IConnectableLayers = IConnectableLayers{ workingCopyGraph->m_Layers.begin(),
570  workingCopyGraph->m_Layers.end() };
571 }
std::list< IConnectableLayer * > IConnectableLayers

Member Data Documentation

◆ layers

OutputSlots Layers&& layers

Definition at line 66 of file SubgraphView.hpp.

Referenced by SubgraphView::SubgraphView().

◆ outputs

OutputSlots&& outputs

Definition at line 66 of file SubgraphView.hpp.

Referenced by SubgraphView::SubgraphView().


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