From 56ccf68c7858560f2ba00f19076b3cb112970881 Mon Sep 17 00:00:00 2001 From: Francis Murtagh Date: Mon, 13 Dec 2021 18:48:12 +0000 Subject: IVGCVSW-6633 SubgraphView uses IConnectableLayer rather than Layer in its m_Layers * Added IInputSlot, IOutputSlot and IConnectableLayer to SubgraphView * Deprecated old member functions * Removed deprecated calls in ArmNN * Added GetOwningIConnectableLayer function to IOutputSlot * Updates ArmNN Core Major version for IOutputSlot ABI break * Updated Minor version of TfliteParser, OnnxParser and Delegate Signed-off-by: Francis Murtagh Change-Id: I2a8611bfabf5ae09d3602fe6a4bef166e18117b9 --- src/backends/backendsCommon/OptimizationViews.cpp | 20 +- src/backends/backendsCommon/test/MockBackend.cpp | 14 +- .../test/OptimizeSubgraphViewTests.cpp | 248 ++++++++++++--------- 3 files changed, 165 insertions(+), 117 deletions(-) (limited to 'src/backends/backendsCommon') diff --git a/src/backends/backendsCommon/OptimizationViews.cpp b/src/backends/backendsCommon/OptimizationViews.cpp index eee2c67ea9..e81a6912a1 100644 --- a/src/backends/backendsCommon/OptimizationViews.cpp +++ b/src/backends/backendsCommon/OptimizationViews.cpp @@ -17,24 +17,28 @@ bool OptimizationViews::Validate(const armnn::SubgraphView& originalSubgraph) co bool valid = true; // Create a copy of the layer list from the original subgraph and sort it - SubgraphView::Layers originalLayers = originalSubgraph.GetLayers(); + SubgraphView::IConnectableLayers originalLayers = originalSubgraph.GetIConnectableLayers(); originalLayers.sort(); // Create a new list based on the sum of all the subgraphs and sort it - SubgraphView::Layers countedLayers; + SubgraphView::IConnectableLayers countedLayers; for (auto& failed : m_FailedOptimizations) { - countedLayers.insert(countedLayers.end(), failed.GetLayers().begin(), failed.GetLayers().end()); + countedLayers.insert(countedLayers.end(), + failed.GetIConnectableLayers().begin(), + failed.GetIConnectableLayers().end()); } for (auto& untouched : m_UntouchedSubgraphs) { - countedLayers.insert(countedLayers.end(), untouched.GetLayers().begin(), untouched.GetLayers().end()); + countedLayers.insert(countedLayers.end(), + untouched.GetIConnectableLayers().begin(), + untouched.GetIConnectableLayers().end()); } for (auto& successful : m_SuccesfulOptimizations) { countedLayers.insert(countedLayers.end(), - successful.m_SubstitutableSubgraph.GetLayers().begin(), - successful.m_SubstitutableSubgraph.GetLayers().end()); + successful.m_SubstitutableSubgraph.GetIConnectableLayers().begin(), + successful.m_SubstitutableSubgraph.GetIConnectableLayers().end()); } countedLayers.sort(); @@ -56,8 +60,8 @@ bool OptimizationViews::Validate(const armnn::SubgraphView& originalSubgraph) co bool validSubstitution = true; const SubgraphView& replacement = substitution.m_ReplacementSubgraph; const SubgraphView& old = substitution.m_SubstitutableSubgraph; - validSubstitution &= replacement.GetInputSlots().size() == old.GetInputSlots().size(); - validSubstitution &= replacement.GetOutputSlots().size() == old.GetOutputSlots().size(); + validSubstitution &= replacement.GetIInputSlots().size() == old.GetIInputSlots().size(); + validSubstitution &= replacement.GetIOutputSlots().size() == old.GetIOutputSlots().size(); valid &= validSubstitution; } } diff --git a/src/backends/backendsCommon/test/MockBackend.cpp b/src/backends/backendsCommon/test/MockBackend.cpp index d95cfc3a34..2ce14f92a4 100644 --- a/src/backends/backendsCommon/test/MockBackend.cpp +++ b/src/backends/backendsCommon/test/MockBackend.cpp @@ -130,21 +130,21 @@ OptimizationViews MockBackend::OptimizeSubgraphView(const SubgraphView& subgraph OptimizationViews optimizationViews; // Get the layers of the input sub-graph - const SubgraphView::Layers& subgraphLayers = subgraph.GetLayers(); + const SubgraphView::IConnectableLayers& subgraphLayers = subgraph.GetIConnectableLayers(); // Parse the layers - SubgraphView::Layers supportedLayers; - SubgraphView::Layers unsupportedLayers; - SubgraphView::Layers untouchedLayers; + SubgraphView::IConnectableLayers supportedLayers; + SubgraphView::IConnectableLayers unsupportedLayers; + SubgraphView::IConnectableLayers untouchedLayers; std::for_each(subgraphLayers.begin(), subgraphLayers.end(), - [&](Layer* layer) + [&](IConnectableLayer* layer) { - bool supported = IsLayerSupported(layer); + bool supported = IsLayerSupported(PolymorphicDowncast(layer)); if (supported) { // Layer supported, check if it's optimizable - bool optimizable = IsLayerOptimizable(layer); + bool optimizable = IsLayerOptimizable(PolymorphicDowncast(layer)); if (optimizable) { // Layer fully supported diff --git a/src/backends/backendsCommon/test/OptimizeSubgraphViewTests.cpp b/src/backends/backendsCommon/test/OptimizeSubgraphViewTests.cpp index 4dd6bc955d..8036b41fb2 100644 --- a/src/backends/backendsCommon/test/OptimizeSubgraphViewTests.cpp +++ b/src/backends/backendsCommon/test/OptimizeSubgraphViewTests.cpp @@ -56,6 +56,18 @@ std::vector ConvertReferenceTypeToPointerType(const std::vector +std::vector ConvertSlotsToISlots(const std::vector input) +{ + std::vector output; + for (auto slot : input) + { + output.push_back(PolymorphicDowncast(slot)); + } + return output; +} + // Convenience function to add an input layer to a graph Layer* AddInputLayer(Graph& graph, const std::string& layerName, @@ -125,19 +137,20 @@ AdditionLayer* AddAdditionaLayer(Graph& graph, void CheckSubstitution(const OptimizationViews::SubstitutionPair& substitution, const ExpectedSubgraphSize& expectedSubstitutableSubgraphSize, const ExpectedSubgraphSize& expectedReplacementSubgraphSize, - const SubgraphView::InputSlots& expectedSubstitutableInputSlots, - const SubgraphView::OutputSlots& expectedSubstitutableOutputSlots, - const SubgraphView::Layers& expectedSubstitutableLayers) + const SubgraphView::IInputSlots& expectedSubstitutableInputSlots, + const SubgraphView::IOutputSlots& expectedSubstitutableOutputSlots, + const SubgraphView::IConnectableLayers& expectedSubstitutableLayers) { - const SubgraphView& substitutableSubgraph = substitution.m_SubstitutableSubgraph; - const SubgraphView::InputSlots& substitutableSubgraphInputSlots = substitutableSubgraph.GetInputSlots(); - const SubgraphView::OutputSlots& substitutableSubgraphOutputSlots = substitutableSubgraph.GetOutputSlots(); - const SubgraphView::Layers& substitutableSubgraphLayers = substitutableSubgraph.GetLayers(); + const SubgraphView& substitutableSubgraph = substitution.m_SubstitutableSubgraph; + const SubgraphView::IInputSlots& substitutableSubgraphInputSlots = substitutableSubgraph.GetIInputSlots(); + const SubgraphView::IOutputSlots& substitutableSubgraphOutputSlots = substitutableSubgraph.GetIOutputSlots(); + const SubgraphView::IConnectableLayers& substitutableSubgraphLayers = + substitutableSubgraph.GetIConnectableLayers(); - const SubgraphView& replacementSubgraph = substitution.m_ReplacementSubgraph; - const SubgraphView::InputSlots& replacementSubgraphInputSlots = replacementSubgraph.GetInputSlots(); - const SubgraphView::OutputSlots& replacementSubgraphOutputSlots = replacementSubgraph.GetOutputSlots(); - const SubgraphView::Layers& replacementSubgraphLayers = replacementSubgraph.GetLayers(); + const SubgraphView& replacementSubgraph = substitution.m_ReplacementSubgraph; + const SubgraphView::IInputSlots& replacementSubgraphInputSlots = replacementSubgraph.GetIInputSlots(); + const SubgraphView::IOutputSlots& replacementSubgraphOutputSlots = replacementSubgraph.GetIOutputSlots(); + const SubgraphView::IConnectableLayers& replacementSubgraphLayers = replacementSubgraph.GetIConnectableLayers(); CHECK(substitutableSubgraphInputSlots.size() == expectedSubstitutableSubgraphSize.m_NumInputSlots); CHECK(substitutableSubgraphOutputSlots.size() == expectedSubstitutableSubgraphSize.m_NumOutputSlots); @@ -157,7 +170,7 @@ void CheckSubstitution(const OptimizationViews::SubstitutionPair& substitution, CHECK(std::all_of(replacementSubgraphLayers.begin(), replacementSubgraphLayers.end(), - [](const Layer* layer) + [](const IConnectableLayer* layer) { return layer->GetType() == LayerType::PreCompiled; })); @@ -166,13 +179,13 @@ void CheckSubstitution(const OptimizationViews::SubstitutionPair& substitution, // Convenience function to check that the given failed subgraph matches the specified expected values void CheckFailedSubgraph(const SubgraphView& failedSubgraph, const ExpectedSubgraphSize& expectedFailedSubgraphSize, - const SubgraphView::InputSlots& expectedFailedInputSlots, - const SubgraphView::OutputSlots& expectedFailedOutputSlots, - const SubgraphView::Layers& expectedFailedLayers) + const SubgraphView::IInputSlots& expectedFailedInputSlots, + const SubgraphView::IOutputSlots& expectedFailedOutputSlots, + const SubgraphView::IConnectableLayers& expectedFailedLayers) { - const SubgraphView::InputSlots& failedSubgraphInputSlots = failedSubgraph.GetInputSlots(); - const SubgraphView::OutputSlots& failedSubgraphOutputSlots = failedSubgraph.GetOutputSlots(); - const SubgraphView::Layers& failedSubgraphLayers = failedSubgraph.GetLayers(); + const SubgraphView::IInputSlots& failedSubgraphInputSlots = failedSubgraph.GetIInputSlots(); + const SubgraphView::IOutputSlots& failedSubgraphOutputSlots = failedSubgraph.GetIOutputSlots(); + const SubgraphView::IConnectableLayers& failedSubgraphLayers = failedSubgraph.GetIConnectableLayers(); CHECK(failedSubgraphInputSlots.size() == expectedFailedSubgraphSize.m_NumInputSlots); CHECK(failedSubgraphOutputSlots.size() == expectedFailedSubgraphSize.m_NumOutputSlots); @@ -186,13 +199,13 @@ void CheckFailedSubgraph(const SubgraphView& failedSubgraph, // Convenience function to check that the given untouched subgraph matches the specified expected values void CheckUntouchedSubgraph(const SubgraphView& untouchedSubgraph, const ExpectedSubgraphSize& expectedUntouchedSubgraphSize, - const SubgraphView::InputSlots& expectedUntouchedInputSlots, - const SubgraphView::OutputSlots& expectedUntouchedOutputSlots, - const SubgraphView::Layers& expectedUntouchedLayers) + const SubgraphView::IInputSlots& expectedUntouchedInputSlots, + const SubgraphView::IOutputSlots& expectedUntouchedOutputSlots, + const SubgraphView::IConnectableLayers& expectedUntouchedLayers) { - const SubgraphView::InputSlots& untouchedSubgraphInputSlots = untouchedSubgraph.GetInputSlots(); - const SubgraphView::OutputSlots& untouchedSubgraphOutputSlots = untouchedSubgraph.GetOutputSlots(); - const SubgraphView::Layers& untouchedSubgraphLayers = untouchedSubgraph.GetLayers(); + const SubgraphView::IInputSlots& untouchedSubgraphInputSlots = untouchedSubgraph.GetIInputSlots(); + const SubgraphView::IOutputSlots& untouchedSubgraphOutputSlots = untouchedSubgraph.GetIOutputSlots(); + const SubgraphView::IConnectableLayers& untouchedSubgraphLayers = untouchedSubgraph.GetIConnectableLayers(); CHECK(untouchedSubgraphInputSlots.size() == expectedUntouchedSubgraphSize.m_NumInputSlots); CHECK(untouchedSubgraphOutputSlots.size() == expectedUntouchedSubgraphSize.m_NumOutputSlots); @@ -552,9 +565,9 @@ void FullyUnsupporteSubgraphTestImpl1() SubgraphView::SubgraphViewPtr subgraphPtr = BuildFullyUnsupportedSubgraph1(graph, layersInGraph); CHECK((subgraphPtr != nullptr)); - const SubgraphView::InputSlots& subgraphInputSlots = subgraphPtr->GetInputSlots(); - const SubgraphView::OutputSlots& subgraphOutputSlots = subgraphPtr->GetOutputSlots(); - const SubgraphView::Layers& subgraphLayers = subgraphPtr->GetLayers(); + const SubgraphView::IInputSlots& subgraphInputSlots = subgraphPtr->GetIInputSlots(); + const SubgraphView::IOutputSlots& subgraphOutputSlots = subgraphPtr->GetIOutputSlots(); + const SubgraphView::IConnectableLayers& subgraphLayers = subgraphPtr->GetIConnectableLayers(); CHECK(subgraphInputSlots.size() == 1); CHECK(subgraphOutputSlots.size() == 1); @@ -616,9 +629,9 @@ void FullyUnsupporteSubgraphTestImpl2() SubgraphView::SubgraphViewPtr subgraphPtr = BuildFullyUnsupportedSubgraph2(graph, layersInGraph); CHECK((subgraphPtr != nullptr)); - const SubgraphView::InputSlots& subgraphInputSlots = subgraphPtr->GetInputSlots(); - const SubgraphView::OutputSlots& subgraphOutputSlots = subgraphPtr->GetOutputSlots(); - const SubgraphView::Layers& subgraphLayers = subgraphPtr->GetLayers(); + const SubgraphView::IInputSlots& subgraphInputSlots = subgraphPtr->GetIInputSlots(); + const SubgraphView::IOutputSlots& subgraphOutputSlots = subgraphPtr->GetIOutputSlots(); + const SubgraphView::IConnectableLayers& subgraphLayers = subgraphPtr->GetIConnectableLayers(); CHECK(subgraphInputSlots.size() == 1); CHECK(subgraphOutputSlots.size() == 1); @@ -659,7 +672,7 @@ void FullyUnsupporteSubgraphTestImpl2() const OptimizationViews::Subgraphs& failedSubgraphs = optimizationViews.GetFailedSubgraphs(); CHECK(failedSubgraphs.size() == 1); - std::list expectedFailedLayers{ layersInGraph.at("pooling1 layer"), + std::list expectedFailedLayers{ layersInGraph.at("pooling1 layer"), layersInGraph.at("pooling2 layer"), layersInGraph.at("pooling3 layer") }; @@ -671,7 +684,7 @@ void FullyUnsupporteSubgraphTestImpl2() subgraphOutputSlots, subgraphLayers); - const SubgraphView::Layers& failedSubgraphLayers = failedSubgraph.GetLayers(); + const SubgraphView::IConnectableLayers& failedSubgraphLayers = failedSubgraph.GetIConnectableLayers(); CHECK_EQ(failedSubgraphLayers.front() + 0, expectedFailedLayers.front() + 0); CHECK_EQ(failedSubgraphLayers.front() + 1, expectedFailedLayers.front() + 1); @@ -694,9 +707,9 @@ void FullyOptimizableSubgraphTestImpl1() SubgraphViewSelector::SubgraphViewPtr subgraphPtr = BuildFullyOptimizableSubgraph1(graph, layersInGraph); CHECK((subgraphPtr != nullptr)); - const SubgraphView::InputSlots& subgraphInputSlots = subgraphPtr->GetInputSlots(); - const SubgraphView::OutputSlots& subgraphOutputSlots = subgraphPtr->GetOutputSlots(); - const SubgraphView::Layers& subgraphLayers = subgraphPtr->GetLayers(); + const SubgraphView::IInputSlots& subgraphInputSlots = subgraphPtr->GetIInputSlots(); + const SubgraphView::IOutputSlots& subgraphOutputSlots = subgraphPtr->GetIOutputSlots(); + const SubgraphView::IConnectableLayers& subgraphLayers = subgraphPtr->GetIConnectableLayers(); CHECK(subgraphInputSlots.size() == 1); CHECK(subgraphOutputSlots.size() == 1); @@ -759,13 +772,13 @@ void FullyOptimizableSubgraphTestImpl2() SubgraphViewSelector::SubgraphViewPtr subgraphPtr = BuildFullyOptimizableSubgraph2(graph, layersInGraph); CHECK((subgraphPtr != nullptr)); - const SubgraphView::InputSlots& subgraphInputSlots = subgraphPtr->GetInputSlots(); - const SubgraphView::OutputSlots& subgraphOutputSlots = subgraphPtr->GetOutputSlots(); - const SubgraphView::Layers& subgraphLayers = subgraphPtr->GetLayers(); + const SubgraphView::IInputSlots& subgraphInputSlots = subgraphPtr->GetIInputSlots(); + const SubgraphView::IOutputSlots& subgraphOutputSlots = subgraphPtr->GetIOutputSlots(); + const SubgraphView::IConnectableLayers& subgraphLayers = subgraphPtr->GetIConnectableLayers(); - CHECK(subgraphPtr->GetInputSlots().size() == 1); - CHECK(subgraphPtr->GetOutputSlots().size() == 1); - CHECK(subgraphPtr->GetLayers().size() == 5); + CHECK(subgraphPtr->GetIInputSlots().size() == 1); + CHECK(subgraphPtr->GetIOutputSlots().size() == 1); + CHECK(subgraphPtr->GetIConnectableLayers().size() == 5); CHECK(Contains(layersInGraph, "conv1 layer")); CHECK(Contains(layersInGraph, "conv2 layer")); @@ -798,7 +811,7 @@ void FullyOptimizableSubgraphTestImpl2() const OptimizationViews::Substitutions& substitutions = optimizationViews.GetSubstitutions(); CHECK(substitutions.size() == 1); - std::list expectedSubstitutableLayers{ layersInGraph.at("conv1 layer"), + std::list expectedSubstitutableLayers{ layersInGraph.at("conv1 layer"), layersInGraph.at("conv2 layer"), layersInGraph.at("conv3 layer"), layersInGraph.at("conv4 layer"), @@ -813,7 +826,8 @@ void FullyOptimizableSubgraphTestImpl2() subgraphOutputSlots, expectedSubstitutableLayers); - const SubgraphView::Layers& substitutableSubgraphLayers = substitution.m_SubstitutableSubgraph.GetLayers(); + const SubgraphView::IConnectableLayers& substitutableSubgraphLayers = + substitution.m_SubstitutableSubgraph.GetIConnectableLayers(); CHECK_EQ(substitutableSubgraphLayers.front() + 0, expectedSubstitutableLayers.front() + 0); CHECK_EQ(substitutableSubgraphLayers.front() + 1, expectedSubstitutableLayers.front() + 1); @@ -845,9 +859,9 @@ void PartiallySupportedSubgraphTestImpl() SubgraphViewSelector::SubgraphViewPtr subgraphPtr = BuildPartiallySupportedSubgraph(graph, layersInGraph); CHECK((subgraphPtr != nullptr)); - const SubgraphView::InputSlots& subgraphInputSlots = subgraphPtr->GetInputSlots(); - const SubgraphView::OutputSlots& subgraphOutputSlots = subgraphPtr->GetOutputSlots(); - const SubgraphView::Layers& subgraphLayers = subgraphPtr->GetLayers(); + const SubgraphView::IInputSlots& subgraphInputSlots = subgraphPtr->GetIInputSlots(); + const SubgraphView::IOutputSlots& subgraphOutputSlots = subgraphPtr->GetIOutputSlots(); + const SubgraphView::IConnectableLayers& subgraphLayers = subgraphPtr->GetIConnectableLayers(); CHECK(subgraphInputSlots.size() == 1); CHECK(subgraphOutputSlots.size() == 1); @@ -885,25 +899,30 @@ void PartiallySupportedSubgraphTestImpl() CHECK(substitutions.size() == 2); // Sort into a consistent order std::sort(substitutions.begin(), substitutions.end(), [](auto s1, auto s2) { - return strcmp(s1.m_SubstitutableSubgraph.GetLayers().front()->GetName(), - s2.m_SubstitutableSubgraph.GetLayers().front()->GetName()) < 0; + return strcmp(s1.m_SubstitutableSubgraph.GetIConnectableLayers().front()->GetName(), + s2.m_SubstitutableSubgraph.GetIConnectableLayers().front()->GetName()) < 0; }); std::vector expectedSubstitutableSubgraphSizes{ { 1, 1, 1 }, { 1, 1, 1 } }; std::vector expectedReplacementSubgraphSizes{ { 1, 1, 1 }, { 1, 1, 1 } }; - std::vector expectedSubstitutableInputSlots + std::vector expectedSubstitutableInputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("conv1 layer")->GetInputSlots()), - ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer")->GetInputSlots()) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv1 layer")->GetInputSlots())), + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer")->GetInputSlots())) }; - std::vector expectedSubstitutableOutputSlots + + std::vector expectedSubstitutableOutputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("conv1 layer")->GetOutputSlots()), - ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer")->GetOutputSlots()) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv1 layer")->GetOutputSlots())), + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer")->GetOutputSlots())) }; - std::vector expectedSubstitutableLayers + std::vector expectedSubstitutableLayers { { layersInGraph.at("conv1 layer") }, { layersInGraph.at("conv2 layer") } @@ -927,22 +946,27 @@ void PartiallySupportedSubgraphTestImpl() CHECK(failedSubgraphs.size() == 2); // Sort into a consistent order std::sort(failedSubgraphs.begin(), failedSubgraphs.end(), [](auto s1, auto s2) { - return strcmp(s1.GetLayers().front()->GetName(), s2.GetLayers().front()->GetName()) < 0; + return strcmp(s1.GetIConnectableLayers().front()->GetName(), + s2.GetIConnectableLayers().front()->GetName()) < 0; }); std::vector expectedFailedSubgraphSizes{ { 1, 1, 2 }, { 1, 1, 1 } }; - std::vector expectedFailedInputSlots + std::vector expectedFailedInputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("pooling1 layer")->GetInputSlots()), - ConvertReferenceTypeToPointerType(layersInGraph.at("pooling3 layer")->GetInputSlots()) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("pooling1 layer")->GetInputSlots())), + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("pooling3 layer")->GetInputSlots())) }; - std::vector expectedFailedOutputSlots + std::vector expectedFailedOutputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("pooling2 layer")->GetOutputSlots()), - ConvertReferenceTypeToPointerType(layersInGraph.at("pooling3 layer")->GetOutputSlots()) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("pooling2 layer")->GetOutputSlots())), + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("pooling3 layer")->GetOutputSlots())) }; - std::vector expectedFailedLayers + std::vector expectedFailedLayers { { layersInGraph.at("pooling1 layer"), layersInGraph.at("pooling2 layer") }, @@ -975,9 +999,9 @@ void FullyUnoptimizableSubgraphTestImpl1() SubgraphViewSelector::SubgraphViewPtr subgraphPtr = BuildFullyUnoptimizableSubgraph1(graph, layersInGraph); CHECK((subgraphPtr != nullptr)); - const SubgraphView::InputSlots& subgraphInputSlots = subgraphPtr->GetInputSlots(); - const SubgraphView::OutputSlots& subgraphOutputSlots = subgraphPtr->GetOutputSlots(); - const SubgraphView::Layers& subgraphLayers = subgraphPtr->GetLayers(); + const SubgraphView::IInputSlots& subgraphInputSlots = subgraphPtr->GetIInputSlots(); + const SubgraphView::IOutputSlots& subgraphOutputSlots = subgraphPtr->GetIOutputSlots(); + const SubgraphView::IConnectableLayers& subgraphLayers = subgraphPtr->GetIConnectableLayers(); CHECK(subgraphInputSlots.size() == 1); CHECK(subgraphOutputSlots.size() == 1); @@ -1039,9 +1063,9 @@ void PartiallyOptimizableSubgraphTestImpl1() SubgraphViewSelector::SubgraphViewPtr subgraphPtr = BuildPartiallyOptimizableSubgraph1(graph, layersInGraph); CHECK((subgraphPtr != nullptr)); - const SubgraphView::InputSlots& subgraphInputSlots = subgraphPtr->GetInputSlots(); - const SubgraphView::OutputSlots& subgraphOutputSlots = subgraphPtr->GetOutputSlots(); - const SubgraphView::Layers& subgraphLayers = subgraphPtr->GetLayers(); + const SubgraphView::IInputSlots& subgraphInputSlots = subgraphPtr->GetIInputSlots(); + const SubgraphView::IOutputSlots& subgraphOutputSlots = subgraphPtr->GetIOutputSlots(); + const SubgraphView::IConnectableLayers& subgraphLayers = subgraphPtr->GetIConnectableLayers(); CHECK(subgraphInputSlots.size() == 1); CHECK(subgraphOutputSlots.size() == 1); @@ -1079,8 +1103,9 @@ void PartiallyOptimizableSubgraphTestImpl1() CHECK(substitutions.size() == 3); // Sort into a consistent order std::sort(substitutions.begin(), substitutions.end(), - [](auto s1, auto s2) { return strcmp(s1.m_SubstitutableSubgraph.GetLayers().front()->GetName(), - s2.m_SubstitutableSubgraph.GetLayers().front()->GetName()) < 0; }); + [](auto s1, auto s2) + { return strcmp(s1.m_SubstitutableSubgraph.GetIConnectableLayers().front()->GetName(), + s2.m_SubstitutableSubgraph.GetIConnectableLayers().front()->GetName()) < 0; }); std::vector expectedSubstitutableSubgraphSizes{ { 1, 1, 1 }, { 1, 1, 1 }, @@ -1088,19 +1113,25 @@ void PartiallyOptimizableSubgraphTestImpl1() std::vector expectedReplacementSubgraphSizes{ { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } }; - std::vector expectedSubstitutableInputSlots + std::vector expectedSubstitutableInputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("conv1 layer")->GetInputSlots()), - ConvertReferenceTypeToPointerType(layersInGraph.at("conv3 layer")->GetInputSlots()), - ConvertReferenceTypeToPointerType(layersInGraph.at("conv5 layer")->GetInputSlots()) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv1 layer")->GetInputSlots())), + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv3 layer")->GetInputSlots())), + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv5 layer")->GetInputSlots())) }; - std::vector expectedSubstitutableOutputSlots + std::vector expectedSubstitutableOutputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("conv1 layer")->GetOutputSlots()), - ConvertReferenceTypeToPointerType(layersInGraph.at("conv3 layer")->GetOutputSlots()), - ConvertReferenceTypeToPointerType(layersInGraph.at("conv5 layer")->GetOutputSlots()) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv1 layer")->GetOutputSlots())), + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv3 layer")->GetOutputSlots())), + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv5 layer")->GetOutputSlots())) }; - std::vector expectedSubstitutableLayers + std::vector expectedSubstitutableLayers { { layersInGraph.at("conv1 layer") }, { layersInGraph.at("conv3 layer") }, @@ -1131,22 +1162,27 @@ void PartiallyOptimizableSubgraphTestImpl1() CHECK(untouchedSubgraphs.size() == 2); // Sort into a consistent order std::sort(untouchedSubgraphs.begin(), untouchedSubgraphs.end(), [](auto s1, auto s2) { - return strcmp(s1.GetLayers().front()->GetName(), s2.GetLayers().front()->GetName()) < 0; + return strcmp(s1.GetIConnectableLayers().front()->GetName(), + s2.GetIConnectableLayers().front()->GetName()) < 0; }); std::vector expectedUntouchedSubgraphSizes{ { 1, 1, 1 }, { 1, 1, 1 } }; - std::vector expectedUntouchedInputSlots + std::vector expectedUntouchedInputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer unoptimizable")->GetInputSlots()), - ConvertReferenceTypeToPointerType(layersInGraph.at("conv4 layer unoptimizable")->GetInputSlots()) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer unoptimizable")->GetInputSlots())), + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv4 layer unoptimizable")->GetInputSlots())) }; - std::vector expectedUntouchedOutputSlots + std::vector expectedUntouchedOutputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer unoptimizable")->GetOutputSlots()), - ConvertReferenceTypeToPointerType(layersInGraph.at("conv4 layer unoptimizable")->GetOutputSlots()) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer unoptimizable")->GetOutputSlots())), + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv4 layer unoptimizable")->GetOutputSlots())) }; - std::vector expectedUntouchedLayers + std::vector expectedUntouchedLayers { { layersInGraph.at("conv2 layer unoptimizable") }, { layersInGraph.at("conv4 layer unoptimizable") } @@ -1173,9 +1209,9 @@ void PartiallyOptimizableSubgraphTestImpl2() SubgraphViewSelector::SubgraphViewPtr subgraphPtr = BuildPartiallyOptimizableSubgraph2(graph, layersInGraph); CHECK((subgraphPtr != nullptr)); - const SubgraphView::InputSlots& subgraphInputSlots = subgraphPtr->GetInputSlots(); - const SubgraphView::OutputSlots& subgraphOutputSlots = subgraphPtr->GetOutputSlots(); - const SubgraphView::Layers& subgraphLayers = subgraphPtr->GetLayers(); + const SubgraphView::IInputSlots& subgraphInputSlots = subgraphPtr->GetIInputSlots(); + const SubgraphView::IOutputSlots& subgraphOutputSlots = subgraphPtr->GetIOutputSlots(); + const SubgraphView::IConnectableLayers& subgraphLayers = subgraphPtr->GetIConnectableLayers(); CHECK(subgraphInputSlots.size() == 2); CHECK(subgraphOutputSlots.size() == 1); @@ -1214,15 +1250,21 @@ void PartiallyOptimizableSubgraphTestImpl2() ExpectedSubgraphSize expectedSubstitutableSubgraphSizes{ 2, 1, 3 }; ExpectedSubgraphSize expectedReplacementSubgraphSizes{ 2, 1, 1 }; - SubgraphView::InputSlots expectedSubstitutableInputSlots = { - ConvertReferenceTypeToPointerType(layersInGraph.at("conv1 layer")->GetInputSlots()[0]), - ConvertReferenceTypeToPointerType(layersInGraph.at("conv3 layer")->GetInputSlots()[0]) + SubgraphView::IInputSlots expectedSubstitutableInputSlots + { + ConvertSlotsToISlots({ + ConvertReferenceTypeToPointerType(layersInGraph.at("conv1 layer")->GetInputSlots()[0])})[0], + ConvertSlotsToISlots({ + ConvertReferenceTypeToPointerType(layersInGraph.at("conv3 layer")->GetInputSlots()[0])})[0] }; - SubgraphView::OutputSlots expectedSubstitutableOutputSlots = + + SubgraphView::IOutputSlots expectedSubstitutableOutputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("add layer")->GetOutputSlots()[0]) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("add layer")->GetOutputSlots())) }; - SubgraphView::Layers expectedSubstitutableLayers + + SubgraphView::IConnectableLayers expectedSubstitutableLayers { layersInGraph.at("conv1 layer"), layersInGraph.at("conv3 layer"), @@ -1250,15 +1292,17 @@ void PartiallyOptimizableSubgraphTestImpl2() CHECK(untouchedSubgraphs.size() == 1); std::vector expectedUntouchedSubgraphSizes{ { 1, 1, 1 } }; - std::vector expectedUntouchedInputSlots + std::vector expectedUntouchedInputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer unoptimizable")->GetInputSlots()) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer unoptimizable")->GetInputSlots())) }; - std::vector expectedUntouchedOutputSlots + std::vector expectedUntouchedOutputSlots { - ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer unoptimizable")->GetOutputSlots()) + ConvertSlotsToISlots( + ConvertReferenceTypeToPointerType(layersInGraph.at("conv2 layer unoptimizable")->GetOutputSlots())) }; - std::vector expectedUntouchedLayers + std::vector expectedUntouchedLayers { { layersInGraph.at("conv2 layer unoptimizable") } }; -- cgit v1.2.1