ArmNN
 24.08
OptimizationViews.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017,2022 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 namespace armnn
9 {
10 
11 bool OptimizationViews::Validate(const armnn::SubgraphView& originalSubgraph) const
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 }
76 } //namespace armnn
OptimizationViews.hpp
armnn::SubgraphView::IConnectableLayers
std::list< IConnectableLayer * > IConnectableLayers
Definition: SubgraphView.hpp:62
armnn::SubgraphView::GetIConnectableLayers
const IConnectableLayers & GetIConnectableLayers() const
Definition: SubgraphView.cpp:281
armnn::SubgraphView
The SubgraphView class represents a subgraph of a Graph.
Definition: SubgraphView.hpp:31
armnn::OptimizationViews::Validate
bool Validate(const SubgraphView &originalSubgraph) const
Definition: OptimizationViews.cpp:11
armnn::SubgraphView::GetIInputSlots
const IInputSlots & GetIInputSlots() const
Definition: SubgraphView.cpp:236
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::SubgraphView::GetIOutputSlots
const IOutputSlots & GetIOutputSlots() const
Definition: SubgraphView.cpp:241