ArmNN
 24.08
OptimizationViews.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017, 2019, 2021-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
9 #include <armnn/Deprecated.hpp>
10 #include <armnn/INetwork.hpp>
12 #include <vector>
13 
14 namespace armnn
15 {
16 
18 {
19 public:
20  OptimizationViews(const NetworkOptions& networkOptions = {}) : m_INetwork(INetwork::Create(networkOptions)) {}
21  OptimizationViews(const OptimizationViews&) = delete;
25 
27  {
28  /// Subgraph of Layers from the original graph which should be replaced
30 
31  /// A subgraph of new layers which will replace layers in m_SubstitutableSubgraph
33  };
34 
35  using Subgraphs = std::vector<SubgraphView>;
36  using Substitutions = std::vector<SubstitutionPair>;
37 
38  void AddSubstitution(SubstitutionPair&& substitution)
39  {
40  m_SuccesfulOptimizations.emplace_back(substitution);
41  }
42 
44  {
45  m_FailedOptimizations.emplace_back(subgraph);
46  }
47 
49  {
50  m_UntouchedSubgraphs.emplace_back(subgraph);
51  }
52 
54  {
55  m_DeletedSubgraphs.emplace_back(subgraph);
56  }
57 
58  const Substitutions& GetSubstitutions() const { return m_SuccesfulOptimizations; }
59  const Subgraphs& GetFailedSubgraphs() const { return m_FailedOptimizations; }
60  const Subgraphs& GetUntouchedSubgraphs() const { return m_UntouchedSubgraphs; }
61  const Subgraphs& GetDeletedSubgraphs() const { return m_DeletedSubgraphs; }
62 
63  Substitutions& GetSubstitutions() { return m_SuccesfulOptimizations; }
64  Subgraphs& GetFailedSubgraphs() { return m_FailedOptimizations; }
65  Subgraphs& GetUntouchedSubgraphs() { return m_UntouchedSubgraphs; }
66 
67  bool Validate(const SubgraphView& originalSubgraph) const;
68 
69  INetwork* GetINetwork() { return m_INetwork.get(); }
70  INetwork& GetINetworkRef() { return *m_INetwork; }
71 
72 private:
73  Substitutions m_SuccesfulOptimizations; ///< Proposed substitutions from successful optimizations
74  Subgraphs m_FailedOptimizations; ///< Subgraphs from the original subgraph which cannot be supported
75  Subgraphs m_UntouchedSubgraphs; ///< Subgraphs from the original subgraph which remain unmodified
76  Subgraphs m_DeletedSubgraphs; ///< Subgraphs from the original subgraph which have been deleted
77 
78  /// INetworkPtr object used only as a container for any layer generated by the optimization process
79  /// Also, can use to AddPrecompiledLayer to the SubstitutionPair
80  INetworkPtr m_INetwork = INetwork::Create();
81 };
82 
83 } //namespace armnn
armnn::INetworkPtr
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:339
armnn::OptimizationViews::operator=
OptimizationViews & operator=(const OptimizationViews &)=delete
armnn::OptimizationViews::AddUntouchedSubgraph
void AddUntouchedSubgraph(SubgraphView &&subgraph)
Definition: OptimizationViews.hpp:48
armnn::OptimizationViews::GetUntouchedSubgraphs
const Subgraphs & GetUntouchedSubgraphs() const
Definition: OptimizationViews.hpp:60
armnn::OptimizationViews::GetFailedSubgraphs
const Subgraphs & GetFailedSubgraphs() const
Definition: OptimizationViews.hpp:59
armnn::OptimizationViews::Subgraphs
std::vector< SubgraphView > Subgraphs
Definition: OptimizationViews.hpp:35
Deprecated.hpp
armnn::OptimizationViews::SubstitutionPair::m_SubstitutableSubgraph
SubgraphView m_SubstitutableSubgraph
Subgraph of Layers from the original graph which should be replaced.
Definition: OptimizationViews.hpp:29
armnn::OptimizationViews::OptimizationViews
OptimizationViews(const NetworkOptions &networkOptions={})
Definition: OptimizationViews.hpp:20
armnn::OptimizationViews::GetUntouchedSubgraphs
Subgraphs & GetUntouchedSubgraphs()
Definition: OptimizationViews.hpp:65
armnn::NetworkOptions
std::vector< BackendOptions > NetworkOptions
Definition: BackendOptions.hpp:16
INetwork.hpp
armnn::SubgraphView
The SubgraphView class represents a subgraph of a Graph.
Definition: SubgraphView.hpp:31
armnn::OptimizationViews
Definition: OptimizationViews.hpp:17
armnn::OptimizationViews::AddSubstitution
void AddSubstitution(SubstitutionPair &&substitution)
Definition: OptimizationViews.hpp:38
armnn::OptimizationViews::GetFailedSubgraphs
Subgraphs & GetFailedSubgraphs()
Definition: OptimizationViews.hpp:64
SubgraphView.hpp
armnn::OptimizationViews::Validate
bool Validate(const SubgraphView &originalSubgraph) const
Definition: OptimizationViews.cpp:11
armnn::OptimizationViews::SubstitutionPair
Definition: OptimizationViews.hpp:26
armnn::OptimizationViews::AddFailedSubgraph
void AddFailedSubgraph(SubgraphView &&subgraph)
Definition: OptimizationViews.hpp:43
armnn::OptimizationViews::GetINetworkRef
INetwork & GetINetworkRef()
Definition: OptimizationViews.hpp:70
armnn::OptimizationViews::SubstitutionPair::m_ReplacementSubgraph
SubgraphView m_ReplacementSubgraph
A subgraph of new layers which will replace layers in m_SubstitutableSubgraph.
Definition: OptimizationViews.hpp:32
armnn::OptimizationViews::AddDeletedSubgraph
void AddDeletedSubgraph(SubgraphView &&subgraph)
Definition: OptimizationViews.hpp:53
armnn::OptimizationViews::GetSubstitutions
const Substitutions & GetSubstitutions() const
Definition: OptimizationViews.hpp:58
armnn::OptimizationViews::GetDeletedSubgraphs
const Subgraphs & GetDeletedSubgraphs() const
Definition: OptimizationViews.hpp:61
armnn::OptimizationViews::Substitutions
std::vector< SubstitutionPair > Substitutions
Definition: OptimizationViews.hpp:36
BackendOptions.hpp
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::OptimizationViews::GetINetwork
INetwork * GetINetwork()
Definition: OptimizationViews.hpp:69
armnn::OptimizationViews::GetSubstitutions
Substitutions & GetSubstitutions()
Definition: OptimizationViews.hpp:63
armnn::INetwork::Create
static INetworkPtr Create(const NetworkOptions &networkOptions={})
Definition: Network.cpp:682
armnn::INetwork
Main network class which provides the interface for building up a neural network.
Definition: INetwork.hpp:347