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 | { |
Matteo Martincigh | 8492433 | 2019-05-09 12:46:16 +0100 | [diff] [blame] | 11 | |
Derek Lamberti | c2fe5fb | 2019-05-08 10:23:08 +0100 | [diff] [blame] | 12 | class OptimizationViews |
| 13 | { |
| 14 | public: |
| 15 | OptimizationViews() = default; |
Matteo Martincigh | 77ba3df | 2019-05-09 15:26:51 +0100 | [diff] [blame] | 16 | OptimizationViews(const OptimizationViews&) = delete; |
| 17 | OptimizationViews& operator=(const OptimizationViews&) = delete; |
| 18 | OptimizationViews(OptimizationViews&&) = default; |
| 19 | OptimizationViews& operator=(OptimizationViews&&) = default; |
Derek Lamberti | c2fe5fb | 2019-05-08 10:23:08 +0100 | [diff] [blame] | 20 | |
| 21 | struct SubstitutionPair |
| 22 | { |
| 23 | /// Subgraph of Layers from the original graph which should be replaced |
| 24 | SubgraphView m_SubstitutableSubgraph; |
| 25 | |
| 26 | /// A subgraph of new layers which will replace layers in m_SubstitutableSubgraph |
| 27 | SubgraphView m_ReplacementSubgraph; |
| 28 | }; |
| 29 | |
| 30 | using Subgraphs = std::vector<SubgraphView>; |
| 31 | using Substitutions = std::vector<SubstitutionPair>; |
| 32 | |
Matteo Martincigh | 88054f8 | 2019-05-17 12:15:30 +0100 | [diff] [blame] | 33 | void AddSubstitution(SubstitutionPair&& substitution) |
Derek Lamberti | c2fe5fb | 2019-05-08 10:23:08 +0100 | [diff] [blame] | 34 | { |
| 35 | m_SuccesfulOptimizations.emplace_back(substitution); |
| 36 | } |
| 37 | |
| 38 | void AddFailedSubgraph(SubgraphView&& subgraph) |
| 39 | { |
| 40 | m_FailedOptimizations.emplace_back(subgraph); |
| 41 | } |
| 42 | |
| 43 | void AddUntouchedSubgraph(SubgraphView&& subgraph) |
| 44 | { |
| 45 | m_UntouchedSubgraphs.emplace_back(subgraph); |
| 46 | } |
| 47 | |
Matteo Martincigh | 8492433 | 2019-05-09 12:46:16 +0100 | [diff] [blame] | 48 | const Substitutions& GetSubstitutions() const { return m_SuccesfulOptimizations; } |
| 49 | const Subgraphs& GetFailedSubgraphs() const { return m_FailedOptimizations; } |
| 50 | const Subgraphs& GetUntouchedSubgraphs() const { return m_UntouchedSubgraphs; } |
| 51 | |
| 52 | Substitutions& GetSubstitutions() { return m_SuccesfulOptimizations; } |
| 53 | Subgraphs& GetFailedSubgraphs() { return m_FailedOptimizations; } |
| 54 | Subgraphs& GetUntouchedSubgraphs() { return m_UntouchedSubgraphs; } |
| 55 | |
Derek Lamberti | c2fe5fb | 2019-05-08 10:23:08 +0100 | [diff] [blame] | 56 | bool Validate(const SubgraphView& originalSubgraph) const; |
| 57 | |
Matteo Martincigh | 8492433 | 2019-05-09 12:46:16 +0100 | [diff] [blame] | 58 | Graph& GetGraph() { return m_Graph; } |
Derek Lamberti | 8106b7c | 2019-05-07 21:33:30 +0100 | [diff] [blame] | 59 | |
Derek Lamberti | c2fe5fb | 2019-05-08 10:23:08 +0100 | [diff] [blame] | 60 | private: |
| 61 | Substitutions m_SuccesfulOptimizations; ///< Proposed substitutions from successful optimizations |
| 62 | Subgraphs m_FailedOptimizations; ///< Subgraphs from the original subgraph which cannot be supported |
| 63 | Subgraphs m_UntouchedSubgraphs; ///< Subgraphs from the original subgraph which remain unmodified |
Derek Lamberti | 8106b7c | 2019-05-07 21:33:30 +0100 | [diff] [blame] | 64 | |
Matteo Martincigh | 8492433 | 2019-05-09 12:46:16 +0100 | [diff] [blame] | 65 | /// Graph object used only as a container for any layer generated by the optimization process |
Derek Lamberti | 8106b7c | 2019-05-07 21:33:30 +0100 | [diff] [blame] | 66 | Graph m_Graph; |
Derek Lamberti | c2fe5fb | 2019-05-08 10:23:08 +0100 | [diff] [blame] | 67 | }; |
Matteo Martincigh | 8492433 | 2019-05-09 12:46:16 +0100 | [diff] [blame] | 68 | |
Matteo Martincigh | 77ba3df | 2019-05-09 15:26:51 +0100 | [diff] [blame] | 69 | } //namespace armnn |