ArmNN
 21.02
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::Layers originalLayers = originalSubgraph.GetLayers();
21  originalLayers.sort();
22 
23  // Create a new list based on the sum of all the subgraphs and sort it
24  SubgraphView::Layers countedLayers;
25  for (auto& failed : m_FailedOptimizations)
26  {
27  countedLayers.insert(countedLayers.end(), failed.GetLayers().begin(), failed.GetLayers().end());
28  }
29  for (auto& untouched : m_UntouchedSubgraphs)
30  {
31  countedLayers.insert(countedLayers.end(), untouched.GetLayers().begin(), untouched.GetLayers().end());
32  }
33  for (auto& successful : m_SuccesfulOptimizations)
34  {
35  countedLayers.insert(countedLayers.end(),
36  successful.m_SubstitutableSubgraph.GetLayers().begin(),
37  successful.m_SubstitutableSubgraph.GetLayers().end());
38  }
39  countedLayers.sort();
40 
41  // Compare the two lists to make sure they match
42  valid &= originalLayers.size() == countedLayers.size();
43 
44  auto oIt = originalLayers.begin();
45  auto cIt = countedLayers.begin();
46  for (size_t i=0; i < originalLayers.size() && valid; ++i, ++oIt, ++cIt)
47  {
48  valid &= (*oIt == *cIt);
49  }
50 
51  // Compare the substitution subgraphs to ensure they are compatible
52  if (valid)
53  {
54  for (auto& substitution : m_SuccesfulOptimizations)
55  {
56  bool validSubstitution = true;
57  const SubgraphView& replacement = substitution.m_ReplacementSubgraph;
58  const SubgraphView& old = substitution.m_SubstitutableSubgraph;
59  validSubstitution &= replacement.GetInputSlots().size() == old.GetInputSlots().size();
60  validSubstitution &= replacement.GetOutputSlots().size() == old.GetOutputSlots().size();
61  valid &= validSubstitution;
62  }
63  }
64  return valid;
65 }
66 } //namespace armnn
Copyright (c) 2021 ARM Limited and Contributors.
The SubgraphView class represents a subgraph of a Graph.
bool Validate(const SubgraphView &originalSubgraph) const
const InputSlots & GetInputSlots() const
const OutputSlots & GetOutputSlots() const
const Layers & GetLayers() const
std::list< Layer * > Layers