aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Bentham <matthew.bentham@arm.com>2019-04-30 10:17:40 +0100
committerMatthew Bentham <matthew.bentham@arm.com>2019-04-30 12:42:19 +0100
commitd78b891d30b9b3a1aaf29e46c1d008bdc6bcd674 (patch)
tree1d0877c0f673af1305213454c186604b265fdd27
parent386681af17ec143a0ea6f503e579e5cd8a334966 (diff)
downloadarmnn-d78b891d30b9b3a1aaf29e46c1d008bdc6bcd674.tar.gz
IVGCVSW-3021 Add end-to-end flow control integration test
Currently asserts that the net fails to optimise as that is the expected behaviour, but it's complete enough to exercise most of the code in SwitchLayer.cpp and MergeLayer.cpp Also, fix a bug in SwitchLayer::ValidateTensorShapesFromInputs found by the new test. Also, make topological sort slightly more robust to missing connections as it should not be the job of the sorter to validate the graph. Change-Id: I30b9e2d4769ab14a6820284871a79a5bb3eef1ef Signed-off-by: Matthew Bentham <matthew.bentham@arm.com>
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/armnn/Layer.cpp13
-rw-r--r--src/armnn/layers/SwitchLayer.cpp2
-rw-r--r--src/armnn/test/FlowControl.cpp53
4 files changed, 66 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 297cbcd628..6dc1a1f02d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -421,6 +421,7 @@ if(BUILD_UNIT_TESTS)
src/armnn/test/EndToEndTest.cpp
src/armnn/test/ExecutionFrameTest.cpp
src/armnn/test/FloatingPointConverterTest.cpp
+ src/armnn/test/FlowControl.cpp
src/armnn/test/GraphTests.cpp
src/armnn/test/GraphUtils.cpp
src/armnn/test/GraphUtils.hpp
diff --git a/src/armnn/Layer.cpp b/src/armnn/Layer.cpp
index 0a6328ba3d..ced87b095c 100644
--- a/src/armnn/Layer.cpp
+++ b/src/armnn/Layer.cpp
@@ -262,8 +262,17 @@ LayerPriority Layer::GetPriority() const
auto maxPrio = [](const LayerPriority prio, const InputSlot& slot) -> LayerPriority
{
- const Layer& input = slot.GetConnectedOutputSlot()->GetOwningLayer();
- return std::max(prio, input.GetPriority());
+ const OutputSlot *outputSlot = slot.GetConnectedOutputSlot();
+ if (outputSlot)
+ {
+ const Layer& input = outputSlot->GetOwningLayer();
+ return std::max(prio, input.GetPriority());
+ }
+ else
+ {
+ // unconnected input slot
+ return prio;
+ }
};
m_Visiting = true;
diff --git a/src/armnn/layers/SwitchLayer.cpp b/src/armnn/layers/SwitchLayer.cpp
index eae6e0dfe2..4f0eb9b703 100644
--- a/src/armnn/layers/SwitchLayer.cpp
+++ b/src/armnn/layers/SwitchLayer.cpp
@@ -39,7 +39,7 @@ void SwitchLayer::ValidateTensorShapesFromInputs()
GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape(),
GetInputSlot(1).GetConnection()->GetTensorInfo().GetShape() });
- BOOST_ASSERT(inferredShapes.size() == 1);
+ BOOST_ASSERT(inferredShapes.size() == 2);
ConditionalThrowIfNotEqual<LayerValidationException>(
"SwitchLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
diff --git a/src/armnn/test/FlowControl.cpp b/src/armnn/test/FlowControl.cpp
new file mode 100644
index 0000000000..3bc993b33b
--- /dev/null
+++ b/src/armnn/test/FlowControl.cpp
@@ -0,0 +1,53 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include <armnn/Descriptors.hpp>
+#include <armnn/IRuntime.hpp>
+#include <armnn/INetwork.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+#include <set>
+
+BOOST_AUTO_TEST_SUITE(FlowControl)
+
+BOOST_AUTO_TEST_CASE(ErrorOnLoadNetwork)
+{
+ using namespace armnn;
+
+ // Create runtime in which test will run
+ IRuntime::CreationOptions options;
+ IRuntimePtr runtime(IRuntime::Create(options));
+
+ // build up the structure of the network
+ // It's equivalent to something like
+ // if (0) {} else {}
+ INetworkPtr net(INetwork::Create());
+
+ std::vector<uint8_t> falseData = {0};
+ ConstTensor falseTensor(armnn::TensorInfo({1}, armnn::DataType::Boolean), falseData);
+ IConnectableLayer* constLayer = net->AddConstantLayer(falseTensor, "const");
+ constLayer->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({1}, armnn::DataType::Boolean));
+
+ IConnectableLayer* input = net->AddInputLayer(0);
+
+ IConnectableLayer* switchLayer = net->AddSwitchLayer("switch");
+ IConnectableLayer* mergeLayer = net->AddMergeLayer("merge");
+
+ IConnectableLayer* output = net->AddOutputLayer(0);
+
+ input->GetOutputSlot(0).Connect(switchLayer->GetInputSlot(0));
+ constLayer->GetOutputSlot(0).Connect(switchLayer->GetInputSlot(1));
+ switchLayer->GetOutputSlot(0).Connect(mergeLayer->GetInputSlot(0));
+ switchLayer->GetOutputSlot(1).Connect(mergeLayer->GetInputSlot(1));
+ mergeLayer->GetOutputSlot(0).Connect(output->GetInputSlot(0));
+
+ // optimize the network
+ std::vector<BackendId> backends = {Compute::CpuRef};
+ IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime->GetDeviceSpec());
+ BOOST_CHECK(!optNet); // Should have failed to optimise, as flow control is not yet implemented
+}
+
+BOOST_AUTO_TEST_SUITE_END()