diff options
author | Francis Murtagh <francis.murtagh@arm.com> | 2022-01-17 17:08:01 +0000 |
---|---|---|
committer | Francis Murtagh <francis.murtagh@arm.com> | 2022-01-19 15:43:31 +0000 |
commit | a49ff0841e86acb0a77747d93e6c9f18b8517ee8 (patch) | |
tree | 61a0c3d8d3d21d30f1d55508e294cd1fbcae84a2 | |
parent | 34b429c2215bab7fd12b761dd5c200414c1b4a5b (diff) | |
download | armnn-a49ff0841e86acb0a77747d93e6c9f18b8517ee8.tar.gz |
IVGCVSW-6712 Move SubgraphView to backends include folder
* Make subgraphview a public interface for backends.
Change-Id: I615a29ffec41e947215c3d29c2d7d214e327fb90
Signed-off-by: Francis Murtagh <francis.murtagh@arm.com>
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | include/armnn/backends/IBackendInternal.hpp | 2 | ||||
-rw-r--r-- | include/armnn/backends/OptimizationViews.hpp | 2 | ||||
-rw-r--r-- | include/armnn/backends/SubgraphView.hpp | 172 | ||||
-rw-r--r-- | src/armnn/Graph.cpp | 7 | ||||
-rw-r--r-- | src/armnn/Network.hpp | 11 | ||||
-rw-r--r-- | src/armnn/SubgraphView.cpp | 5 | ||||
-rw-r--r-- | src/armnn/SubgraphView.hpp | 167 | ||||
-rw-r--r-- | src/armnn/SubgraphViewSelector.hpp | 2 | ||||
-rw-r--r-- | src/armnn/test/SubgraphViewTests.cpp | 8 | ||||
-rw-r--r-- | src/armnnTestUtils/CommonTestUtils.hpp | 4 | ||||
-rw-r--r-- | src/backends/backendsCommon/test/OptimizationViewsTests.cpp | 7 |
12 files changed, 200 insertions, 189 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 629a79880b..5368401e2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,6 +185,7 @@ list(APPEND armnn_sources include/armnn/utility/PolymorphicDowncast.hpp include/armnn/utility/StringUtils.hpp include/armnn/utility/TransformIterator.hpp + include/armnn/backends/SubgraphView.hpp src/armnn/layers/LayerCloneBase.hpp src/armnn/layers/LayerWithParameters.hpp src/armnn/layers/ActivationLayer.hpp @@ -386,7 +387,6 @@ list(APPEND armnn_sources src/armnn/SerializeLayerParameters.cpp src/armnn/SerializeLayerParameters.hpp src/armnn/SubgraphView.cpp - src/armnn/SubgraphView.hpp src/armnn/SubgraphViewSelector.cpp src/armnn/SubgraphViewSelector.hpp src/armnn/Tensor.cpp diff --git a/include/armnn/backends/IBackendInternal.hpp b/include/armnn/backends/IBackendInternal.hpp index 0756fdd8fb..c64150a484 100644 --- a/include/armnn/backends/IBackendInternal.hpp +++ b/include/armnn/backends/IBackendInternal.hpp @@ -10,12 +10,12 @@ #include <armnn/Deprecated.hpp> #include <ISubgraphViewConverter.hpp> -#include <SubgraphView.hpp> #include <armnn/backends/IBackendContext.hpp> #include <armnn/backends/IMemoryManager.hpp> #include <armnn/backends/ITensorHandleFactory.hpp> #include <armnn/backends/OptimizationViews.hpp> +#include <armnn/backends/SubgraphView.hpp> #include <armnn/backends/profiling/IBackendProfiling.hpp> #include <armnn/backends/profiling/IBackendProfilingContext.hpp> diff --git a/include/armnn/backends/OptimizationViews.hpp b/include/armnn/backends/OptimizationViews.hpp index f3479febd3..3146dd7f74 100644 --- a/include/armnn/backends/OptimizationViews.hpp +++ b/include/armnn/backends/OptimizationViews.hpp @@ -5,7 +5,7 @@ #pragma once -#include <SubgraphView.hpp> +#include <armnn/backends/SubgraphView.hpp> namespace armnn { diff --git a/include/armnn/backends/SubgraphView.hpp b/include/armnn/backends/SubgraphView.hpp new file mode 100644 index 0000000000..b5a74bab5d --- /dev/null +++ b/include/armnn/backends/SubgraphView.hpp @@ -0,0 +1,172 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include <Layer.hpp> +#include <Graph.hpp> + +#include <vector> +#include <list> + +namespace armnn +{ + +/// +/// The SubgraphView class represents a subgraph of a Graph. +/// The data it holds, points to data held by layers of the Graph, so the +/// the contents of the SubgraphView become invalid when the Layers are destroyed +/// or changed. +/// +class SubgraphView final +{ +public: + template <typename Func> + void ForEachLayer(Func func) const + { + for (auto it = m_Layers.begin(); it != m_Layers.end(); ) + { + auto next = std::next(it); + func(*it); + it = next; + } + } + + template <typename Func> + void ForEachIConnectableLayer(Func func) const + { + for (auto it = m_IConnectableLayers.begin(); it != m_IConnectableLayers.end(); ) + { + auto next = std::next(it); + func(*it); + it = next; + } + } + + using SubgraphViewPtr = std::unique_ptr<SubgraphView>; + using InputSlots = std::vector<InputSlot*>; + using IInputSlots = std::vector<IInputSlot*>; + using OutputSlots = std::vector<OutputSlot*>; + using IOutputSlots = std::vector<IOutputSlot*>; + using Layers = std::list<Layer*>; + using IConnectableLayers = std::list<IConnectableLayer*>; + using Iterator = Layers::iterator; + using IConnectableLayerIterator = IConnectableLayers::iterator; + using ConstIterator = Layers::const_iterator; + using ConstIConnectableIterator = IConnectableLayers::const_iterator; + + /// Constructs a sub-graph from the entire given graph. + explicit SubgraphView(Graph& graph); + + /// Constructs a sub-graph with the given arguments. + ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use constructor with arguments: " + "IConnectableLayers, IInputSlots and IOutputSlots", "22.08") + SubgraphView(InputSlots&& inputs, OutputSlots&& outputs, Layers&& layers); + + /// Constructs a sub-graph with the given arguments. + SubgraphView(IConnectableLayers&& layers, IInputSlots&& inputs, IOutputSlots&& outputs); + + /// Copy-constructor. + SubgraphView(const SubgraphView& subgraph); + + /// Move-constructor. + SubgraphView(SubgraphView&& subgraph); + + /// Constructs a sub-graph with only the given layer. + SubgraphView(IConnectableLayer* layer); + + /// Move-assignment operator. + SubgraphView& operator=(SubgraphView&& other); + + ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIInputSlots() returning" + " public IInputSlots", "22.08") + const InputSlots& GetInputSlots() const; + const IInputSlots& GetIInputSlots() const; + + ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIOutputSlots() returning" + " public IOutputSlots", "22.08") + const OutputSlots& GetOutputSlots() const; + const IOutputSlots& GetIOutputSlots() const; + + ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIConnectableLayers() " + "returning public IConnectableLayers", "22.08") + const Layers& GetLayers() const; + const IConnectableLayers& GetIConnectableLayers() const; + + ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIInputSlot() returning public " + "IInputSlot", "22.08") + const InputSlot* GetInputSlot(unsigned int index) const; + const IInputSlot* GetIInputSlot(unsigned int index) const; + ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIInputSlot() returning public " + "IInputSlot", "22.08") + InputSlot* GetInputSlot(unsigned int index); + IInputSlot* GetIInputSlot(unsigned int index); + + ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIOutputSlot() returning" + " public IOutputSlot", "22.08") + const OutputSlot* GetOutputSlot(unsigned int index) const; + const IOutputSlot* GetIOutputSlot(unsigned int index) const; + ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIOutputSlot() returning" + " public IOutputSlot", "22.08") + OutputSlot* GetOutputSlot(unsigned int index); + IOutputSlot* GetIOutputSlot(unsigned int index); + + unsigned int GetNumInputSlots() const; + unsigned int GetNumOutputSlots() const; + + ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " + "IConnectableLayerIterator, until that occurs in 23.02; please use " + "beginIConnectable() returning public IConnectableLayerIterator", "23.02") + Iterator begin(); + IConnectableLayerIterator beginIConnectable(); + ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " + "IConnectableLayerIterator, until that occurs in 23.02; please use " + "endIConnectable() returning public IConnectableLayerIterator", "23.02") + Iterator end(); + IConnectableLayerIterator endIConnectable(); + + ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " + "ConstIConnectableIterator, until that occurs in 23.02; please use " + "beginIConnectable() returning public ConstIConnectableIterator", "23.02") + ConstIterator begin() const; + ConstIConnectableIterator beginIConnectable() const; + ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " + "ConstIConnectableIterator, until that occurs in 23.02; please use " + "endIConnectable() returning public ConstIConnectableIterator", "23.02") + ConstIterator end() const; + ConstIConnectableIterator endIConnectable() const; + + ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " + "ConstIConnectableIterator, until that occurs in 23.02; please use " + "cbeginIConnectable() returning public ConstIConnectableIterator", "23.02") + ConstIterator cbegin() const; + ConstIConnectableIterator cbeginIConnectable() const; + ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " + "ConstIConnectableIterator, until that occurs in 23.02; please use " + "cendIConnectable() returning public ConstIConnectableIterator", "23.02") + ConstIterator cend() const; + ConstIConnectableIterator cendIConnectable() const; + + void Clear(); + +private: + void CheckSubgraph(); + + /// Arrange the order of layers topologically so that nodes can be visited in valid order + void ArrangeBySortOrder(); + + /// The list of pointers to the input slots of the parent graph. + InputSlots m_InputSlots; + IInputSlots m_IInputSlots; + + /// The list of pointers to the output slots of the parent graph. + OutputSlots m_OutputSlots; + IOutputSlots m_IOutputSlots; + + /// The list of pointers to the layers of the parent graph. + Layers m_Layers; + IConnectableLayers m_IConnectableLayers; +}; +} // namespace armnn diff --git a/src/armnn/Graph.cpp b/src/armnn/Graph.cpp index cdb323432c..1bea6cc2ae 100644 --- a/src/armnn/Graph.cpp +++ b/src/armnn/Graph.cpp @@ -3,16 +3,15 @@ // SPDX-License-Identifier: MIT // -#include "Graph.hpp" -#include "SubgraphView.hpp" -#include "LayersFwd.hpp" +#include <Graph.hpp> +#include <LayersFwd.hpp> #include <armnn/backends/IBackendInternal.hpp> +#include <armnn/backends/SubgraphView.hpp> #include <armnn/BackendId.hpp> #include <armnn/Logging.hpp> #include <armnn/TypesUtils.hpp> -#include <armnn/Utils.hpp> #include <armnn/utility/Assert.hpp> #include <armnn/utility/NumericCast.hpp> diff --git a/src/armnn/Network.hpp b/src/armnn/Network.hpp index a2ef0d8364..1e8e4c2d9e 100644 --- a/src/armnn/Network.hpp +++ b/src/armnn/Network.hpp @@ -5,23 +5,22 @@ #pragma once #include <armnn/DescriptorsFwd.hpp> +#include <armnn/INetwork.hpp> #include <armnn/LstmParams.hpp> #include <armnn/QuantizedLstmParams.hpp> #include <armnn/TensorFwd.hpp> #include <armnn/Types.hpp> -#include <armnn/INetwork.hpp> +#include <Graph.hpp> +#include <Layer.hpp> +#include <OptimizedNetworkImpl.hpp> +#include <armnn/backends/SubgraphView.hpp> #include <string> #include <vector> #include <map> #include <memory> -#include "Graph.hpp" -#include "Layer.hpp" -#include "OptimizedNetworkImpl.hpp" -#include "SubgraphView.hpp" - namespace armnn { class Graph; diff --git a/src/armnn/SubgraphView.cpp b/src/armnn/SubgraphView.cpp index 2de4510b7b..aac2a354d1 100644 --- a/src/armnn/SubgraphView.cpp +++ b/src/armnn/SubgraphView.cpp @@ -3,8 +3,9 @@ // SPDX-License-Identifier: MIT // -#include "SubgraphView.hpp" -#include "Graph.hpp" +#include <armnn/backends/SubgraphView.hpp> + +#include <Graph.hpp> #include <armnn/utility/IgnoreUnused.hpp> #include <armnn/utility/NumericCast.hpp> diff --git a/src/armnn/SubgraphView.hpp b/src/armnn/SubgraphView.hpp index f2ca44cb68..ddfd88402b 100644 --- a/src/armnn/SubgraphView.hpp +++ b/src/armnn/SubgraphView.hpp @@ -5,168 +5,7 @@ #pragma once -#include "Layer.hpp" -#include "Graph.hpp" +#include <armnn/backends/SubgraphView.hpp> -#include <vector> -#include <list> - -namespace armnn -{ - -/// -/// The SubgraphView class represents a subgraph of a Graph. -/// The data it holds, points to data held by layers of the Graph, so the -/// the contents of the SubgraphView become invalid when the Layers are destroyed -/// or changed. -/// -class SubgraphView final -{ -public: - template <typename Func> - void ForEachLayer(Func func) const - { - for (auto it = m_Layers.begin(); it != m_Layers.end(); ) - { - auto next = std::next(it); - func(*it); - it = next; - } - } - - template <typename Func> - void ForEachIConnectableLayer(Func func) const - { - for (auto it = m_IConnectableLayers.begin(); it != m_IConnectableLayers.end(); ) - { - auto next = std::next(it); - func(*it); - it = next; - } - } - - using SubgraphViewPtr = std::unique_ptr<SubgraphView>; - using InputSlots = std::vector<InputSlot*>; - using IInputSlots = std::vector<IInputSlot*>; - using OutputSlots = std::vector<OutputSlot*>; - using IOutputSlots = std::vector<IOutputSlot*>; - using Layers = std::list<Layer*>; - using IConnectableLayers = std::list<IConnectableLayer*>; - using Iterator = Layers::iterator; - using IConnectableLayerIterator = IConnectableLayers::iterator; - using ConstIterator = Layers::const_iterator; - using ConstIConnectableIterator = IConnectableLayers::const_iterator; - - /// Constructs a sub-graph from the entire given graph. - explicit SubgraphView(Graph& graph); - - /// Constructs a sub-graph with the given arguments. - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use constructor with arguments: " - "IConnectableLayers, IInputSlots and IOutputSlots", "22.08") - SubgraphView(InputSlots&& inputs, OutputSlots&& outputs, Layers&& layers); - - /// Constructs a sub-graph with the given arguments. - SubgraphView(IConnectableLayers&& layers, IInputSlots&& inputs, IOutputSlots&& outputs); - - /// Copy-constructor. - SubgraphView(const SubgraphView& subgraph); - - /// Move-constructor. - SubgraphView(SubgraphView&& subgraph); - - /// Constructs a sub-graph with only the given layer. - SubgraphView(IConnectableLayer* layer); - - /// Move-assignment operator. - SubgraphView& operator=(SubgraphView&& other); - - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIInputSlots() returning" - " public IInputSlots", "22.08") - const InputSlots& GetInputSlots() const; - const IInputSlots& GetIInputSlots() const; - - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIOutputSlots() returning" - " public IOutputSlots", "22.08") - const OutputSlots& GetOutputSlots() const; - const IOutputSlots& GetIOutputSlots() const; - - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIConnectableLayers() " - "returning public IConnectableLayers", "22.08") - const Layers& GetLayers() const; - const IConnectableLayers& GetIConnectableLayers() const; - - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIInputSlot() returning public " - "IInputSlot", "22.08") - const InputSlot* GetInputSlot(unsigned int index) const; - const IInputSlot* GetIInputSlot(unsigned int index) const; - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIInputSlot() returning public " - "IInputSlot", "22.08") - InputSlot* GetInputSlot(unsigned int index); - IInputSlot* GetIInputSlot(unsigned int index); - - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIOutputSlot() returning" - " public IOutputSlot", "22.08") - const OutputSlot* GetOutputSlot(unsigned int index) const; - const IOutputSlot* GetIOutputSlot(unsigned int index) const; - ARMNN_DEPRECATED_MSG_REMOVAL_DATE("This function has been deprecated, please use GetIOutputSlot() returning" - " public IOutputSlot", "22.08") - OutputSlot* GetOutputSlot(unsigned int index); - IOutputSlot* GetIOutputSlot(unsigned int index); - - unsigned int GetNumInputSlots() const; - unsigned int GetNumOutputSlots() const; - - ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " - "IConnectableLayerIterator, until that occurs in 23.02; please use " - "beginIConnectable() returning public IConnectableLayerIterator", "23.02") - Iterator begin(); - IConnectableLayerIterator beginIConnectable(); - ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " - "IConnectableLayerIterator, until that occurs in 23.02; please use " - "endIConnectable() returning public IConnectableLayerIterator", "23.02") - Iterator end(); - IConnectableLayerIterator endIConnectable(); - - ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " - "ConstIConnectableIterator, until that occurs in 23.02; please use " - "beginIConnectable() returning public ConstIConnectableIterator", "23.02") - ConstIterator begin() const; - ConstIConnectableIterator beginIConnectable() const; - ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " - "ConstIConnectableIterator, until that occurs in 23.02; please use " - "endIConnectable() returning public ConstIConnectableIterator", "23.02") - ConstIterator end() const; - ConstIConnectableIterator endIConnectable() const; - - ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " - "ConstIConnectableIterator, until that occurs in 23.02; please use " - "cbeginIConnectable() returning public ConstIConnectableIterator", "23.02") - ConstIterator cbegin() const; - ConstIConnectableIterator cbeginIConnectable() const; - ARMNN_DEPRECATED_MSG_CHANGE_DATE("This function is deprecated and will be changed to return an " - "ConstIConnectableIterator, until that occurs in 23.02; please use " - "cendIConnectable() returning public ConstIConnectableIterator", "23.02") - ConstIterator cend() const; - ConstIConnectableIterator cendIConnectable() const; - - void Clear(); - -private: - void CheckSubgraph(); - - /// Arrange the order of layers topologically so that nodes can be visited in valid order - void ArrangeBySortOrder(); - - /// The list of pointers to the input slots of the parent graph. - InputSlots m_InputSlots; - IInputSlots m_IInputSlots; - - /// The list of pointers to the output slots of the parent graph. - OutputSlots m_OutputSlots; - IOutputSlots m_IOutputSlots; - - /// The list of pointers to the layers of the parent graph. - Layers m_Layers; - IConnectableLayers m_IConnectableLayers; -}; -} // namespace armnn +#pragma message("src/armnn/SubgraphView.hpp has been deprecated, it is due for removal in" \ + " 22.08 release. Please use include/armnn/backends/SubgraphView.hpp instead.") diff --git a/src/armnn/SubgraphViewSelector.hpp b/src/armnn/SubgraphViewSelector.hpp index d4ed8f799a..0a05bc259e 100644 --- a/src/armnn/SubgraphViewSelector.hpp +++ b/src/armnn/SubgraphViewSelector.hpp @@ -4,7 +4,7 @@ // #pragma once -#include "SubgraphView.hpp" +#include <armnn/backends/SubgraphView.hpp> #include <functional> #include <memory> diff --git a/src/armnn/test/SubgraphViewTests.cpp b/src/armnn/test/SubgraphViewTests.cpp index 2ea465ea04..14c18eeae1 100644 --- a/src/armnn/test/SubgraphViewTests.cpp +++ b/src/armnn/test/SubgraphViewTests.cpp @@ -3,15 +3,15 @@ // SPDX-License-Identifier: MIT // -#include <doctest/doctest.h> - #include <Graph.hpp> -#include <SubgraphView.hpp> #include <SubgraphViewSelector.hpp> +#include <armnn/backends/SubgraphView.hpp> +#include <armnn/backends/TensorHandle.hpp> #include <armnn/utility/NumericCast.hpp> -#include <armnn/backends/TensorHandle.hpp> +#include <doctest/doctest.h> + #include <fstream> #include <map> #include <queue> diff --git a/src/armnnTestUtils/CommonTestUtils.hpp b/src/armnnTestUtils/CommonTestUtils.hpp index 3fadc888b9..b75a32be61 100644 --- a/src/armnnTestUtils/CommonTestUtils.hpp +++ b/src/armnnTestUtils/CommonTestUtils.hpp @@ -8,12 +8,12 @@ #include "TestUtils.hpp" #include <Graph.hpp> -#include <SubgraphView.hpp> -#include <SubgraphViewSelector.hpp> #include <ResolveType.hpp> +#include <SubgraphViewSelector.hpp> #include <armnn/BackendRegistry.hpp> #include <armnn/Types.hpp> +#include <armnn/backends/SubgraphView.hpp> #include <armnn/backends/TensorHandle.hpp> #include <algorithm> diff --git a/src/backends/backendsCommon/test/OptimizationViewsTests.cpp b/src/backends/backendsCommon/test/OptimizationViewsTests.cpp index 8e51a527b9..a551dfca55 100644 --- a/src/backends/backendsCommon/test/OptimizationViewsTests.cpp +++ b/src/backends/backendsCommon/test/OptimizationViewsTests.cpp @@ -7,13 +7,14 @@ #include <CommonTestUtils.hpp> #include "MockBackend.hpp" -#include <armnn/backends/OptimizationViews.hpp> -#include <armnn/utility/PolymorphicDowncast.hpp> #include <Graph.hpp> #include <Network.hpp> -#include <SubgraphView.hpp> #include <SubgraphViewSelector.hpp> +#include <armnn/backends/OptimizationViews.hpp> +#include <armnn/backends/SubgraphView.hpp> +#include <armnn/utility/PolymorphicDowncast.hpp> + #include <doctest/doctest.h> using namespace armnn; |