ArmNN
 24.02
OptimizationViews Class Reference

#include <OptimizationViews.hpp>

Classes

struct  SubstitutionPair
 

Public Types

using Subgraphs = std::vector< SubgraphView >
 
using Substitutions = std::vector< SubstitutionPair >
 

Public Member Functions

 OptimizationViews (const NetworkOptions &networkOptions={})
 
 OptimizationViews (const OptimizationViews &)=delete
 
OptimizationViewsoperator= (const OptimizationViews &)=delete
 
 OptimizationViews (OptimizationViews &&)=default
 
OptimizationViewsoperator= (OptimizationViews &&)=default
 
void AddSubstitution (SubstitutionPair &&substitution)
 
void AddFailedSubgraph (SubgraphView &&subgraph)
 
void AddUntouchedSubgraph (SubgraphView &&subgraph)
 
void AddDeletedSubgraph (SubgraphView &&subgraph)
 
const SubstitutionsGetSubstitutions () const
 
const SubgraphsGetFailedSubgraphs () const
 
const SubgraphsGetUntouchedSubgraphs () const
 
const SubgraphsGetDeletedSubgraphs () const
 
SubstitutionsGetSubstitutions ()
 
SubgraphsGetFailedSubgraphs ()
 
SubgraphsGetUntouchedSubgraphs ()
 
bool Validate (const SubgraphView &originalSubgraph) const
 
INetworkGetINetwork ()
 
INetworkGetINetworkRef ()
 

Detailed Description

Definition at line 17 of file OptimizationViews.hpp.

Member Typedef Documentation

◆ Subgraphs

using Subgraphs = std::vector<SubgraphView>

Definition at line 35 of file OptimizationViews.hpp.

◆ Substitutions

using Substitutions = std::vector<SubstitutionPair>

Definition at line 36 of file OptimizationViews.hpp.

Constructor & Destructor Documentation

◆ OptimizationViews() [1/3]

OptimizationViews ( const NetworkOptions networkOptions = {})
inline

Definition at line 20 of file OptimizationViews.hpp.

20 {}) : m_INetwork(INetwork::Create(networkOptions)) {}

◆ OptimizationViews() [2/3]

OptimizationViews ( const OptimizationViews )
delete

◆ OptimizationViews() [3/3]

Member Function Documentation

◆ AddDeletedSubgraph()

void AddDeletedSubgraph ( SubgraphView &&  subgraph)
inline

Definition at line 53 of file OptimizationViews.hpp.

54  {
55  m_DeletedSubgraphs.emplace_back(subgraph);
56  }

Referenced by armnn::RemoveReshapeLayer().

◆ AddFailedSubgraph()

void AddFailedSubgraph ( SubgraphView &&  subgraph)
inline

Definition at line 43 of file OptimizationViews.hpp.

44  {
45  m_FailedOptimizations.emplace_back(subgraph);
46  }

◆ AddSubstitution()

void AddSubstitution ( SubstitutionPair &&  substitution)
inline

Definition at line 38 of file OptimizationViews.hpp.

39  {
40  m_SuccesfulOptimizations.emplace_back(substitution);
41  }

Referenced by armnn::FoldPadLayer(), armnn::FuseLayer(), TosaRefBackend::OptimizeSubgraphView(), GpuFsaBackend::OptimizeSubgraphView(), armnn::ReplaceLayers(), and armnn::ReplaceMultipleLayers().

◆ AddUntouchedSubgraph()

void AddUntouchedSubgraph ( SubgraphView &&  subgraph)
inline

◆ GetDeletedSubgraphs()

const Subgraphs& GetDeletedSubgraphs ( ) const
inline

◆ GetFailedSubgraphs() [1/2]

Subgraphs& GetFailedSubgraphs ( )
inline

Definition at line 64 of file OptimizationViews.hpp.

64 { return m_FailedOptimizations; }

◆ GetFailedSubgraphs() [2/2]

const Subgraphs& GetFailedSubgraphs ( ) const
inline

Definition at line 59 of file OptimizationViews.hpp.

59 { return m_FailedOptimizations; }

Referenced by armnn::ApplyBackendOptimizations().

◆ GetINetwork()

◆ GetINetworkRef()

INetwork& GetINetworkRef ( )
inline

Definition at line 70 of file OptimizationViews.hpp.

70 { return *m_INetwork; }

◆ GetSubstitutions() [1/2]

Substitutions& GetSubstitutions ( )
inline

Definition at line 63 of file OptimizationViews.hpp.

63 { return m_SuccesfulOptimizations; }

◆ GetSubstitutions() [2/2]

const Substitutions& GetSubstitutions ( ) const
inline

◆ GetUntouchedSubgraphs() [1/2]

Subgraphs& GetUntouchedSubgraphs ( )
inline

Definition at line 65 of file OptimizationViews.hpp.

65 { return m_UntouchedSubgraphs; }

◆ GetUntouchedSubgraphs() [2/2]

const Subgraphs& GetUntouchedSubgraphs ( ) const
inline

Definition at line 60 of file OptimizationViews.hpp.

60 { return m_UntouchedSubgraphs; }

◆ operator=() [1/2]

OptimizationViews& operator= ( const OptimizationViews )
delete

◆ operator=() [2/2]

OptimizationViews& operator= ( OptimizationViews &&  )
default

◆ Validate()

bool Validate ( const SubgraphView originalSubgraph) const

Definition at line 11 of file OptimizationViews.cpp.

12 {
13  //This needs to verify that:
14  // 1) the sum of m_SuccesfulOptimizations & m_FailedOptimizations & m_UntouchedSubgraphs contains subgraphviews
15  // which cover the entire space of the originalSubgraph.
16  // 2) Each SubstitutionPair contains matching inputs and outputs
17  bool valid = true;
18 
19  // Create a copy of the layer list from the original subgraph and sort it
20  SubgraphView::IConnectableLayers originalLayers = originalSubgraph.GetIConnectableLayers();
21  originalLayers.sort();
22 
23  // Create a new list based on the sum of all the subgraphs and sort it
25  for (auto& failed : m_FailedOptimizations)
26  {
27  countedLayers.insert(countedLayers.end(),
28  failed.GetIConnectableLayers().begin(),
29  failed.GetIConnectableLayers().end());
30  }
31  for (auto& untouched : m_UntouchedSubgraphs)
32  {
33  countedLayers.insert(countedLayers.end(),
34  untouched.GetIConnectableLayers().begin(),
35  untouched.GetIConnectableLayers().end());
36  }
37  for (auto& successful : m_SuccesfulOptimizations)
38  {
39  countedLayers.insert(countedLayers.end(),
40  successful.m_SubstitutableSubgraph.GetIConnectableLayers().begin(),
41  successful.m_SubstitutableSubgraph.GetIConnectableLayers().end());
42  }
43  for (auto& successful : m_DeletedSubgraphs)
44  {
45  countedLayers.insert(countedLayers.end(),
46  successful.GetIConnectableLayers().begin(),
47  successful.GetIConnectableLayers().end());
48  }
49  countedLayers.sort();
50 
51  // Compare the two lists to make sure they match
52  valid &= originalLayers.size() == countedLayers.size();
53 
54  auto oIt = originalLayers.begin();
55  auto cIt = countedLayers.begin();
56  for (size_t i=0; i < originalLayers.size() && valid; ++i, ++oIt, ++cIt)
57  {
58  valid &= (*oIt == *cIt);
59  }
60 
61  // Compare the substitution subgraphs to ensure they are compatible
62  if (valid)
63  {
64  for (auto& substitution : m_SuccesfulOptimizations)
65  {
66  bool validSubstitution = true;
67  const SubgraphView& replacement = substitution.m_ReplacementSubgraph;
68  const SubgraphView& old = substitution.m_SubstitutableSubgraph;
69  validSubstitution &= replacement.GetIInputSlots().size() == old.GetIInputSlots().size();
70  validSubstitution &= replacement.GetIOutputSlots().size() == old.GetIOutputSlots().size();
71  valid &= validSubstitution;
72  }
73  }
74  return valid;
75 }

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

Referenced by armnn::ApplyBackendOptimizations().


The documentation for this class was generated from the following files:
armnn::SubgraphView::IConnectableLayers
std::list< IConnectableLayer * > IConnectableLayers
Definition: SubgraphView.hpp:62
armnn::INetwork::Create
static INetworkPtr Create(const NetworkOptions &networkOptions={})
Definition: Network.cpp:676