Derek Lamberti | c2fe5fb | 2019-05-08 10:23:08 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | #include <SubgraphView.hpp> |
| 8 | |
| 9 | namespace armnn |
| 10 | { |
| 11 | class OptimizationViews |
| 12 | { |
| 13 | public: |
| 14 | OptimizationViews() = default; |
Matteo Martincigh | 77ba3df | 2019-05-09 15:26:51 +0100 | [diff] [blame^] | 15 | OptimizationViews(const OptimizationViews&) = delete; |
| 16 | OptimizationViews& operator=(const OptimizationViews&) = delete; |
| 17 | OptimizationViews(OptimizationViews&&) = default; |
| 18 | OptimizationViews& operator=(OptimizationViews&&) = default; |
Derek Lamberti | c2fe5fb | 2019-05-08 10:23:08 +0100 | [diff] [blame] | 19 | |
| 20 | struct SubstitutionPair |
| 21 | { |
| 22 | /// Subgraph of Layers from the original graph which should be replaced |
| 23 | SubgraphView m_SubstitutableSubgraph; |
| 24 | |
| 25 | /// A subgraph of new layers which will replace layers in m_SubstitutableSubgraph |
| 26 | SubgraphView m_ReplacementSubgraph; |
| 27 | }; |
| 28 | |
| 29 | using Subgraphs = std::vector<SubgraphView>; |
| 30 | using Substitutions = std::vector<SubstitutionPair>; |
| 31 | |
| 32 | void AddSubstituion(SubstitutionPair&& substitution) |
| 33 | { |
| 34 | m_SuccesfulOptimizations.emplace_back(substitution); |
| 35 | } |
| 36 | |
| 37 | void AddFailedSubgraph(SubgraphView&& subgraph) |
| 38 | { |
| 39 | m_FailedOptimizations.emplace_back(subgraph); |
| 40 | } |
| 41 | |
| 42 | void AddUntouchedSubgraph(SubgraphView&& subgraph) |
| 43 | { |
| 44 | m_UntouchedSubgraphs.emplace_back(subgraph); |
| 45 | } |
| 46 | |
| 47 | Substitutions GetSubstitutions() const { return m_SuccesfulOptimizations; } |
| 48 | Subgraphs GetFailedSubgraphs() const { return m_FailedOptimizations; } |
| 49 | Subgraphs GetUntouchedSubgraphs() const { return m_UntouchedSubgraphs; } |
| 50 | bool Validate(const SubgraphView& originalSubgraph) const; |
| 51 | |
Derek Lamberti | 8106b7c | 2019-05-07 21:33:30 +0100 | [diff] [blame] | 52 | Graph& GetGraph() { return m_Graph; }; |
| 53 | |
Derek Lamberti | c2fe5fb | 2019-05-08 10:23:08 +0100 | [diff] [blame] | 54 | private: |
| 55 | Substitutions m_SuccesfulOptimizations; ///< Proposed substitutions from successful optimizations |
| 56 | Subgraphs m_FailedOptimizations; ///< Subgraphs from the original subgraph which cannot be supported |
| 57 | Subgraphs m_UntouchedSubgraphs; ///< Subgraphs from the original subgraph which remain unmodified |
Derek Lamberti | 8106b7c | 2019-05-07 21:33:30 +0100 | [diff] [blame] | 58 | |
| 59 | Graph m_Graph; |
Derek Lamberti | c2fe5fb | 2019-05-08 10:23:08 +0100 | [diff] [blame] | 60 | }; |
Matteo Martincigh | 77ba3df | 2019-05-09 15:26:51 +0100 | [diff] [blame^] | 61 | } //namespace armnn |