From 01f72693d39ed966ad06adadc8aac141bc395659 Mon Sep 17 00:00:00 2001 From: Francis Murtagh Date: Wed, 21 Dec 2022 09:10:04 +0000 Subject: IVGCVSW-7418 Allow working copy SubgraphView to get Original Slots * API to remove need for workaround so backend users can get slots * OutputSlots outside the SubgraphView needed to obtain TensorInfo * Fix a few Copyright headers * Add shared_ptr back to original subgraph view using std::enable_shared_from_this Signed-off-by: Francis Murtagh Change-Id: I033a00d6fc4020619d406ac06a156b7e380a426a --- src/armnn/SubgraphView.cpp | 56 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 46 insertions(+), 10 deletions(-) (limited to 'src/armnn/SubgraphView.cpp') diff --git a/src/armnn/SubgraphView.cpp b/src/armnn/SubgraphView.cpp index b48529c523..fef6390bf2 100644 --- a/src/armnn/SubgraphView.cpp +++ b/src/armnn/SubgraphView.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2017, 2019-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -42,7 +42,8 @@ void AssertIfNullsOrDuplicates(const C& container, const std::string& errorMessa } // anonymous namespace SubgraphView::SubgraphView(Graph& graph) - : m_InputSlots{} + : enable_shared_from_this() + , m_InputSlots{} , m_OutputSlots{} , m_Layers(graph.begin(), graph.end()) , m_IConnectableLayers(graph.begin(), graph.end()) @@ -53,7 +54,8 @@ SubgraphView::SubgraphView(Graph& graph) /// IConnectable Duplication to maintain backwards compatibility SubgraphView::SubgraphView(InputSlots&& inputs, OutputSlots&& outputs, Layers&& layers) - : m_InputSlots{InputSlots{inputs.begin(), inputs.end()}} + : enable_shared_from_this() + , m_InputSlots{InputSlots{inputs.begin(), inputs.end()}} , m_IInputSlots{IInputSlots{inputs.begin(), inputs.end()}} , m_OutputSlots{OutputSlots{outputs.begin(), outputs.end()}} , m_IOutputSlots{IOutputSlots{outputs.begin(), outputs.end()}} @@ -68,7 +70,8 @@ SubgraphView::SubgraphView(InputSlots&& inputs, OutputSlots&& outputs, Layers&& SubgraphView::SubgraphView(SubgraphView::IConnectableLayers&& layers, SubgraphView::IInputSlots&& inputs, SubgraphView::IOutputSlots&& outputs) - : m_IInputSlots{inputs} + : enable_shared_from_this() + , m_IInputSlots{inputs} , m_IOutputSlots{outputs} , m_IConnectableLayers(IConnectableLayers{layers.begin(), layers.end()}) { @@ -104,7 +107,8 @@ SubgraphView::SubgraphView(SubgraphView::IConnectableLayers&& layers, SubgraphView::IInputSlots&& inputs, SubgraphView::IOutputSlots&& outputs, std::shared_ptr ptr) - : m_IInputSlots{inputs} + : enable_shared_from_this() + , m_IInputSlots{inputs} , m_IOutputSlots{outputs} , m_IConnectableLayers(IConnectableLayers{layers.begin(), layers.end()}) , p_WorkingCopyImpl(std::move(ptr)) @@ -137,7 +141,8 @@ SubgraphView::SubgraphView(SubgraphView::IConnectableLayers&& layers, } SubgraphView::SubgraphView(const SubgraphView& subgraph) - : m_InputSlots(subgraph.m_InputSlots.begin(), subgraph.m_InputSlots.end()) + : enable_shared_from_this() + , m_InputSlots(subgraph.m_InputSlots.begin(), subgraph.m_InputSlots.end()) , m_IInputSlots(subgraph.m_IInputSlots.begin(), subgraph.m_IInputSlots.end()) , m_OutputSlots(subgraph.m_OutputSlots.begin(), subgraph.m_OutputSlots.end()) , m_IOutputSlots(subgraph.m_IOutputSlots.begin(), subgraph.m_IOutputSlots.end()) @@ -150,7 +155,8 @@ SubgraphView::SubgraphView(const SubgraphView& subgraph) } SubgraphView::SubgraphView(SubgraphView&& subgraph) - : m_InputSlots(std::move(subgraph.m_InputSlots)) + : enable_shared_from_this() + , m_InputSlots(std::move(subgraph.m_InputSlots)) , m_IInputSlots(std::move(subgraph.m_IInputSlots)) , m_OutputSlots(std::move(subgraph.m_OutputSlots)) , m_IOutputSlots(std::move(subgraph.m_IOutputSlots)) @@ -162,7 +168,8 @@ SubgraphView::SubgraphView(SubgraphView&& subgraph) } SubgraphView::SubgraphView(IConnectableLayer* layer) - : m_Layers{PolymorphicDowncast(layer)} + : enable_shared_from_this() + , m_Layers{PolymorphicDowncast(layer)} , m_IConnectableLayers{layer} { unsigned int numInputSlots = layer->GetNumInputSlots(); @@ -408,11 +415,13 @@ struct SubgraphView::SubgraphViewWorkingCopy public: SubgraphViewWorkingCopy() = default; - SubgraphViewWorkingCopy(Graph graph) + SubgraphViewWorkingCopy(Graph graph, std::shared_ptr originalSubgraphView) : m_Graph(graph) + , m_OriginalSubgraphView(originalSubgraphView) {}; Graph m_Graph; + std::shared_ptr m_OriginalSubgraphView; }; @@ -426,7 +435,7 @@ SubgraphView SubgraphView::GetWorkingCopy() const // Create a cut down SubgraphView with underlying graph containing only the relevant layers. // It needs its own underlying layers so that they can be replaced safely. - auto ptr = std::make_shared(Graph()); + auto ptr = std::make_shared(Graph(), shared_from_this()); std::unordered_map originalToClonedLayerMap; std::list originalSubgraphLayers = GetIConnectableLayers(); @@ -607,5 +616,32 @@ void SubgraphView::SubstituteSubgraph(SubgraphView& patternSubgraph, const Subgr workingCopyGraph->m_Layers.end() }; } +const SubgraphView::IInputSlots& SubgraphView::GetOriginalInputSlots() const +{ + if (!p_WorkingCopyImpl) + { + throw NullPointerException("The SubgraphView calling GetOriginalInputSlots is not a working copy. " + "Call this function on SubgraphView returned from SubgraphView::GetWorkingCopy()"); + } + if (!p_WorkingCopyImpl->m_OriginalSubgraphView) + { + throw NullPointerException("The working copy SubgraphView pointer to its original SubgraphView is null."); + } + return p_WorkingCopyImpl->m_OriginalSubgraphView->GetIInputSlots(); +} +const SubgraphView::IOutputSlots& SubgraphView::GetOriginalOutputSlots() const +{ + if (!p_WorkingCopyImpl) + { + throw NullPointerException("The SubgraphView calling GetOriginalOutputSlots is not a working copy. " + "Call this function on SubgraphView returned from SubgraphView::GetWorkingCopy()"); + } + if (!p_WorkingCopyImpl->m_OriginalSubgraphView) + { + throw NullPointerException("The working copy SubgraphView pointer to its original SubgraphView is null."); + } + return p_WorkingCopyImpl->m_OriginalSubgraphView->GetIOutputSlots(); +} + } // namespace armnn -- cgit v1.2.1