aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/test
diff options
context:
space:
mode:
authorCathal Corbett <cathal.corbett@arm.com>2021-12-13 13:03:22 +0000
committerCathal Corbett <cathal.corbett@arm.com>2021-12-14 14:09:55 +0000
commit18655b8d326f6109c6fedacf42b46dc4bc942324 (patch)
tree79a4cff6e46ea41f404a693ac3a9de2787498f06 /src/armnn/test
parenta097d2a0ed8e30d5aaf6d29ec18d0c39201b7b67 (diff)
downloadarmnn-18655b8d326f6109c6fedacf42b46dc4bc942324.tar.gz
IVGCVSW-6630 Add new method AddPrecompiledLayer() to INetwork
* Add new method AddPrecompiledLayer() to INetwork with Comments noting it is for backend users. * Added unit test to SubgraphViewTests.cpp. * Bug fix and code refactor in Graph.cpp specifically around Graph::SubstituteSubgraph(SubgraphView& subgraph, IConnectableLayer* substituteLayer) Change-Id: If2d816e5109e48ce920bf92d8823b39130c23a16 Signed-off-by: Cathal Corbett <cathal.corbett@arm.com>
Diffstat (limited to 'src/armnn/test')
-rw-r--r--src/armnn/test/SubgraphViewTests.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/armnn/test/SubgraphViewTests.cpp b/src/armnn/test/SubgraphViewTests.cpp
index d270787968..4e509be78b 100644
--- a/src/armnn/test/SubgraphViewTests.cpp
+++ b/src/armnn/test/SubgraphViewTests.cpp
@@ -168,6 +168,91 @@ TEST_CASE("SingleInputSingleOutput")
CHECK_EQ(preCompiledLayer->GetOutputSlot(0).GetConnection(0), subgraphOutputConn);
}
+TEST_CASE("SingleInputSingleOutputAddPrecompiledLayerSubstituteSubgraph1")
+{
+ // Construct graph.
+ Graph graph;
+
+ Layer* const inputLayer = graph.AddLayer<InputLayer>(0, "input");
+
+ Convolution2dDescriptor convDescriptor;
+ Layer* const convLayer1 = graph.AddLayer<Convolution2dLayer>(convDescriptor, "conv1");
+ Layer* const convLayer2 = graph.AddLayer<Convolution2dLayer>(convDescriptor, "conv2");
+
+ Layer* const outputLayer = graph.AddLayer<OutputLayer>(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);
+
+ PreCompiledDescriptor preCompiledDescriptor(1, 1);
+ CompiledBlobPtr compiledBlobPtr;
+ BackendId backend = Compute::CpuRef;
+
+ // Construct dummy pre-compiled layer
+ INetworkPtr network = INetwork::Create();
+ IConnectableLayer* preCompiledLayer = network->AddPrecompiledLayer(preCompiledDescriptor, compiledBlobPtr, backend);
+
+ // Substitute sub-graph with pre-compiled layer
+ graph.SubstituteSubgraph(*subgraph, preCompiledLayer);
+
+ // Check that connections are correct after substitution
+ CHECK_EQ(preCompiledLayer->GetInputSlot(0).GetConnection(), subgraphInputConn);
+ CHECK_EQ(preCompiledLayer->GetOutputSlot(0).GetConnection(0), subgraphOutputConn);
+}
+
+TEST_CASE("SingleInputSingleOutputAddPrecompiledLayerSubstituteSubgraph2")
+{
+ // Construct graph.
+ Graph graph;
+
+ Layer* const inputLayer = graph.AddLayer<InputLayer>(0, "input");
+
+ Convolution2dDescriptor convDescriptor;
+ Layer* const convLayer1 = graph.AddLayer<Convolution2dLayer>(convDescriptor, "conv1");
+ Layer* const convLayer2 = graph.AddLayer<Convolution2dLayer>(convDescriptor, "conv2");
+
+ Layer* const outputLayer = graph.AddLayer<OutputLayer>(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);
+
+ PreCompiledDescriptor preCompiledDescriptor(1, 1);
+ CompiledBlobPtr compiledBlobPtr;
+ BackendId backend = Compute::CpuRef;
+
+ // Construct dummy pre-compiled layer
+ INetworkPtr network = INetwork::Create();
+ IConnectableLayer* preCompiledLayer = network->AddPrecompiledLayer(preCompiledDescriptor, compiledBlobPtr, backend);
+ SubgraphView substituteSubgraph(preCompiledLayer);
+
+ // Substitute sub-graph with pre-compiled layer
+ graph.SubstituteSubgraph(*subgraph, substituteSubgraph);
+
+ // Check that connections are correct after substitution
+ CHECK_EQ(preCompiledLayer->GetInputSlot(0).GetConnection(), subgraphInputConn);
+ CHECK_EQ(preCompiledLayer->GetOutputSlot(0).GetConnection(0), subgraphOutputConn);
+}
+
TEST_CASE("SingleInputSingleOutputSubstituteGraph")
{
// Construct graph