ArmNN
 22.05.01
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", "22.11") 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", "22.11") const InputSlots &GetInputSlots() const
 
const IInputSlotsGetIInputSlots () const
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use GetIOutputSlots() returning" " public IOutputSlots", "22.11") const OutputSlots &GetOutputSlots() const
 
const IOutputSlotsGetIOutputSlots () const
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use GetIConnectableLayers() " "returning public IConnectableLayers", "22.11") const Layers &GetLayers() const
 
const IConnectableLayersGetIConnectableLayers () const
 
 ARMNN_DEPRECATED_MSG_REMOVAL_DATE ("This function has been deprecated, please use GetIInputSlot() returning public " "IInputSlot", "22.11") 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", "22.11") 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", "22.11") 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", "22.11") 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 ()
 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 ,
"22.11"   
) &&

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 ,
"22.11"   
) const &

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [3/8]

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

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [4/8]

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

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [5/8]

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

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [6/8]

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

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [7/8]

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

◆ ARMNN_DEPRECATED_MSG_REMOVAL_DATE() [8/8]

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

◆ beginIConnectable() [1/2]

Definition at line 316 of file SubgraphView.cpp.

Referenced by armnn::AssignBackends(), SubgraphView::cbeginIConnectable(), NeonBackend::OptimizeSubgraphView(), and ClBackend::OptimizeSubgraphView().

317 {
318  return m_IConnectableLayers.begin();
319 }

◆ 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]

Definition at line 321 of file SubgraphView.cpp.

Referenced by armnn::AssignBackends(), SubgraphView::cendIConnectable(), NeonBackend::OptimizeSubgraphView(), and ClBackend::OptimizeSubgraphView().

322 {
323  return m_IConnectableLayers.end();
324 }

◆ 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 ( )

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(), IConnectableLayer::GetInputSlot(), SubgraphView::GetIOutputSlots(), IConnectableLayer::GetNumInputSlots(), 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  Graph newGraph = Graph();
430  std::unordered_map<const IConnectableLayer*, IConnectableLayer*> originalToClonedLayerMap;
431  std::list<armnn::IConnectableLayer*> originalSubgraphLayers = GetIConnectableLayers();
432 
433  auto ptr = std::make_shared<SubgraphViewWorkingCopy>(std::move(newGraph));
434  SubgraphView::IInputSlots workingCopyInputs;
435 
436  for (auto&& originalLayer : originalSubgraphLayers)
437  {
438  Layer* const layer = PolymorphicDowncast<const Layer*>(originalLayer)->Clone(ptr->m_Graph);
439  originalToClonedLayerMap.emplace(originalLayer, layer);
440  }
441 
442  // Add IInputSlots to workingCopy
443  std::vector<const IConnectableLayer*> processed;
444  for (auto originalSubgraphInputSlot : GetIInputSlots())
445  {
446  const IConnectableLayer& originalSubgraphLayer =
447  PolymorphicDowncast<InputSlot*>(originalSubgraphInputSlot)->GetOwningLayer();
448 
449  // Only need process Slots of layer once
450  if (std::find(processed.begin(), processed.end(), &originalSubgraphLayer) == processed.end())
451  {
452  IConnectableLayer* clonedLayer = originalToClonedLayerMap[&originalSubgraphLayer];
453 
454  // Add the InputSlot to WorkingCopy InputSlots
455  for (unsigned int i = 0; i < clonedLayer->GetNumInputSlots(); i++)
456  {
457  workingCopyInputs.push_back(&clonedLayer->GetInputSlot(i));
458  }
459  processed.push_back(&originalSubgraphLayer);
460  }
461  }
462  // Empty processed
463  processed.clear();
464 
465  for (auto originalSubgraphLayer : originalSubgraphLayers)
466  {
467  IConnectableLayer* const clonedLayer = originalToClonedLayerMap[originalSubgraphLayer];
468 
469  // connect all cloned layers as per original subgraph
470  for (unsigned int i = 0; i < clonedLayer->GetNumOutputSlots(); i++)
471  {
472  // OutputLayers have no OutputSlots to be connected
473  if (clonedLayer->GetType() != LayerType::Output)
474  {
475  auto& outputSlot = clonedLayer->GetOutputSlot(i);
476  for (unsigned int k = 0; k < originalSubgraphLayer->GetNumOutputSlots(); k++)
477  {
478  auto& originalOutputSlot = originalSubgraphLayer->GetOutputSlot(k);
479  for (unsigned int j = 0; j < originalOutputSlot.GetNumConnections(); j++)
480  {
481  // nextLayer is the layer with IInputSlot connected to IOutputSlot we are working on
482  const IConnectableLayer& nextLayer =
483  originalOutputSlot.GetConnection(j)->GetOwningIConnectableLayer();
484 
485  // Check the layer is in our map and so has a clonedLayer
486  if (originalToClonedLayerMap.find(&nextLayer) != originalToClonedLayerMap.end())
487  {
488  IConnectableLayer* newGraphTargetLayer = originalToClonedLayerMap[&nextLayer];
489 
490  IInputSlot& inputSlot =
491  newGraphTargetLayer->GetInputSlot(
492  PolymorphicDowncast<OutputSlot*>(
493  &originalOutputSlot)->GetConnection(j)->GetSlotIndex());
494 
495  // Then make the connection
496  outputSlot.Connect(inputSlot);
497  }
498  }
499  // Copy the tensorInfo to the clonedOutputSlot
500  outputSlot.SetTensorInfo(originalOutputSlot.GetTensorInfo());
501  }
502  }
503  }
504  }
505 
506  SubgraphView::IOutputSlots workingCopyOutputs;
507 
508  // Add IOutputSlots to workingCopy
509  for (auto outputSlot : GetIOutputSlots())
510  {
511 
512  const IConnectableLayer& originalSubgraphLayer = outputSlot->GetOwningIConnectableLayer();
513 
514  // OutputLayers have no OutputSlots to be connected
515  // Only need process Slots of layer once
516  if (originalSubgraphLayer.GetType() != LayerType::Output &&
517  std::find(processed.begin(), processed.end(), &originalSubgraphLayer) == processed.end())
518  {
519  IConnectableLayer* clonedLayer = originalToClonedLayerMap[&originalSubgraphLayer];
520 
521  // Add the OutputSlot to WorkingCopy InputSlots
522  for (unsigned int i = 0; i < clonedLayer->GetNumOutputSlots(); i++)
523  {
524  workingCopyOutputs.push_back(&clonedLayer->GetOutputSlot(i));
525  }
526  processed.push_back(&originalSubgraphLayer);
527  }
528  }
529  processed.clear();
530 
531  SubgraphView::IConnectableLayers workingCopyLayers;
532  for (auto& pair : originalToClonedLayerMap)
533  {
534  workingCopyLayers.push_back(pair.second);
535  }
536 
537  return {std::move(workingCopyLayers),
538  std::move(workingCopyInputs),
539  std::move(workingCopyOutputs),
540  ptr};
541 }
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 543 of file SubgraphView.cpp.

References ARMNN_ASSERT.

Referenced by TEST_SUITE().

544 {
545  ARMNN_ASSERT(substituteLayer != nullptr);
546  SubgraphView substituteSubgraph(substituteLayer);
547 
548  SubstituteSubgraph(subgraph, substituteSubgraph);
549 }
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 551 of file SubgraphView.cpp.

References SubgraphView::ForEachIConnectableLayer().

552 {
553  if (!p_WorkingCopyImpl)
554  {
555  throw NullPointerException("The SubgraphView calling SubstituteSubgraphView is not a working copy. "
556  "Call this function on SubgraphView returned from SubgraphView::GetWorkingCopy()");
557  }
558 
559  // Add substitute layer to the Main graph i.e. graph in p_WorkingCopyImpl
560  auto workingCopyGraph = &p_WorkingCopyImpl->m_Graph;
561  substituteSubgraph.ForEachIConnectableLayer([workingCopyGraph](IConnectableLayer* iConnectableLayer)
562  {
563  // Search WorkingCopy Graph for substituteLayer and add if missing
564  if (std::find(std::begin(workingCopyGraph->m_Layers),
565  std::end(workingCopyGraph->m_Layers),
566  iConnectableLayer) ==
567  std::end(workingCopyGraph->m_Layers))
568  {
569  auto layer = PolymorphicDowncast<Layer*>(iConnectableLayer);
570 
571  layer->Reparent(*workingCopyGraph,
572  (workingCopyGraph->m_Layers).end());
573 
574  workingCopyGraph->m_LayersInOrder = false;
575  }
576  });
577 
578  // Replace the old connections with connections to new layer
579  workingCopyGraph->ReplaceSubgraphConnections(patternSubgraph, substituteSubgraph);
580 
581  // Update input/outputSlot pointers
582  m_IInputSlots = std::move(substituteSubgraph.m_IInputSlots);
583  m_IOutputSlots = std::move(substituteSubgraph.m_IOutputSlots);
584 
585  // Delete the old layers.
586  workingCopyGraph->EraseSubgraphLayers(patternSubgraph);
587 
588  // Sort
589  workingCopyGraph->TopologicalSort();
590 
591  // Update SubgraphView layer pointers to match those of the internal WorkingCopy layer pointers
592  m_IConnectableLayers = IConnectableLayers{ workingCopyGraph->m_Layers.begin(),
593  workingCopyGraph->m_Layers.end() };
594 }
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: