From bdf2aab823c123bb9d91e584cd53778f9b0524d1 Mon Sep 17 00:00:00 2001 From: David Monahan Date: Fri, 10 May 2019 15:08:53 +0100 Subject: IVGCVSW-3034 Adding a unit test to check substituteSubGraph now works when substituting layers from another Graph Signed-off-by: David Monahan Change-Id: Iebd21a4975dd0ea1fc9d62708555dae4b1809623 --- src/armnn/test/SubgraphViewTests.cpp | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/armnn/test/SubgraphViewTests.cpp b/src/armnn/test/SubgraphViewTests.cpp index 7938171a33..8369fc4c79 100644 --- a/src/armnn/test/SubgraphViewTests.cpp +++ b/src/armnn/test/SubgraphViewTests.cpp @@ -166,6 +166,49 @@ BOOST_AUTO_TEST_CASE(SingleInputSingleOutput) BOOST_CHECK_EQUAL(preCompiledLayer->GetOutputSlot(0).GetConnection(0), subgraphOutputConn); } +BOOST_AUTO_TEST_CASE(SingleInputSingleOutputSubstituteGraph) +{ + // Construct graph + Graph graph; + + Layer* const inputLayer = graph.AddLayer(0, "input"); + + Convolution2dDescriptor convDescriptor; + Layer* const convLayer1 = graph.AddLayer(convDescriptor, "conv1"); + Layer* const convLayer2 = graph.AddLayer(convDescriptor, "conv2"); + + Layer* const outputLayer = graph.AddLayer(0, "output"); + + inputLayer->GetOutputSlot(0).Connect(convLayer1->GetInputSlot(0)); + convLayer1->GetOutputSlot(0).Connect(convLayer2->GetInputSlot(0)); + convLayer2->GetOutputSlot(0).Connect(outputLayer->GetInputSlot(0)); + + // Construct sub-graph + SubgraphViewSelector::SubgraphViewPtr subgraph = CreateSubgraphViewFrom(CreateInputsFrom({convLayer1}), + CreateOutputsFrom({convLayer2}), + {}); + + // Save sub-graph connections for comparison after substitution + IOutputSlot* subgraphInputConn = subgraph->GetInputSlot(0)->GetConnection(); + IInputSlot* subgraphOutputConn = subgraph->GetOutputSlot(0)->GetConnection(0); + + // Construct second graph with a single pre-compiled layer + Graph substituteGraph; + PreCompiledDescriptor preCompiledDescriptor(1, 1); + Layer* const preCompiledLayer = substituteGraph.AddLayer(preCompiledDescriptor, "pre-compiled"); + + SubgraphViewSelector::SubgraphViewPtr substituteSubgraph = + CreateSubgraphViewFrom(CreateInputsFrom({preCompiledLayer}), + CreateOutputsFrom({preCompiledLayer}), + {preCompiledLayer}); + // Substitute subgraph with pre-compiled layer + graph.SubstituteSubgraph(*subgraph, *substituteSubgraph); + + // Check that connections are correct after substitution + BOOST_CHECK_EQUAL(preCompiledLayer->GetInputSlot(0).GetConnection(), subgraphInputConn); + BOOST_CHECK_EQUAL(preCompiledLayer->GetOutputSlot(0).GetConnection(0), subgraphOutputConn); +} + BOOST_AUTO_TEST_CASE(MultiInputSingleOutput) { // Construct graph -- cgit v1.2.1