ArmNN
 22.11
OptimizationViews.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. 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  countedLayers.sort();
44 
45  // Compare the two lists to make sure they match
46  valid &= originalLayers.size() == countedLayers.size();
47 
48  auto oIt = originalLayers.begin();
49  auto cIt = countedLayers.begin();
50  for (size_t i=0; i < originalLayers.size() && valid; ++i, ++oIt, ++cIt)
51  {
52  valid &= (*oIt == *cIt);
53  }
54 
55  // Compare the substitution subgraphs to ensure they are compatible
56  if (valid)
57  {
58  for (auto& substitution : m_SuccesfulOptimizations)
59  {
60  bool validSubstitution = true;
61  const SubgraphView& replacement = substitution.m_ReplacementSubgraph;
62  const SubgraphView& old = substitution.m_SubstitutableSubgraph;
63  validSubstitution &= replacement.GetIInputSlots().size() == old.GetIInputSlots().size();
64  validSubstitution &= replacement.GetIOutputSlots().size() == old.GetIOutputSlots().size();
65  valid &= validSubstitution;
66  }
67  }
68  return valid;
69 }
70 } //namespace armnn
const IOutputSlots & GetIOutputSlots() const
const IConnectableLayers & GetIConnectableLayers() const
const IInputSlots & GetIInputSlots() const
Copyright (c) 2021 ARM Limited and Contributors.
The SubgraphView class represents a subgraph of a Graph.
std::list< IConnectableLayer * > IConnectableLayers
bool Validate(const SubgraphView &originalSubgraph) const