aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/layers/SwitchLayer.cpp
diff options
context:
space:
mode:
authorSadik Armagan <sadik.armagan@arm.com>2019-04-05 15:25:46 +0100
committerAron Virginas-Tar <Aron.Virginas-Tar@arm.com>2019-04-05 17:11:02 +0100
commiteff363d58992fb6384053259f9e1ee773f8cd4df (patch)
treee0bce8c4694ee15e016951f9168afbf9b75a9c79 /src/armnn/layers/SwitchLayer.cpp
parent1f88630874fe346cd0cca8d8e38e0fb96cc1a3f4 (diff)
downloadarmnn-eff363d58992fb6384053259f9e1ee773f8cd4df.tar.gz
IVGCVSW-2914 Add Switch Layer and no-op factory method
Change-Id: I6a6ece708a49e8a97c83a3e7fec11c88af1e1cfa Signed-off-by: Sadik Armagan <sadik.armagan@arm.com> Signed-off-by: Aron Virginas-Tar <Aron.Virginas-Tar@arm.com>
Diffstat (limited to 'src/armnn/layers/SwitchLayer.cpp')
-rw-r--r--src/armnn/layers/SwitchLayer.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/armnn/layers/SwitchLayer.cpp b/src/armnn/layers/SwitchLayer.cpp
new file mode 100644
index 0000000000..eae6e0dfe2
--- /dev/null
+++ b/src/armnn/layers/SwitchLayer.cpp
@@ -0,0 +1,60 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#include "SwitchLayer.hpp"
+
+#include "LayerCloneBase.hpp"
+
+#include <backendsCommon/WorkloadData.hpp>
+#include <backendsCommon/WorkloadFactory.hpp>
+
+namespace armnn
+{
+
+SwitchLayer::SwitchLayer(const char* name)
+ : Layer(2, 2, LayerType::Switch, name)
+{}
+
+std::unique_ptr<IWorkload> SwitchLayer::CreateWorkload(const Graph& graph,
+ const IWorkloadFactory& factory) const
+{
+ SwitchQueueDescriptor descriptor;
+ return factory.CreateSwitch(descriptor, PrepInfoAndDesc(descriptor, graph));
+}
+
+SwitchLayer* SwitchLayer::Clone(Graph& graph) const
+{
+ return CloneBase<SwitchLayer>(graph, GetName());
+}
+
+void SwitchLayer::ValidateTensorShapesFromInputs()
+{
+ VerifyLayerConnections(2, CHECK_LOCATION());
+
+ BOOST_ASSERT_MSG(GetNumOutputSlots() == 2, "SwitchLayer: The layer should return 2 outputs.");
+
+ // Assuming first input is the Input and second input is the Constant
+ std::vector<TensorShape> inferredShapes = InferOutputShapes({
+ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape(),
+ GetInputSlot(1).GetConnection()->GetTensorInfo().GetShape() });
+
+ BOOST_ASSERT(inferredShapes.size() == 1);
+
+ ConditionalThrowIfNotEqual<LayerValidationException>(
+ "SwitchLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
+ GetOutputSlot(0).GetTensorInfo().GetShape(),
+ inferredShapes[0]);
+
+ ConditionalThrowIfNotEqual<LayerValidationException>(
+ "SwitchLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
+ GetOutputSlot(1).GetTensorInfo().GetShape(),
+ inferredShapes[0]);
+}
+
+void SwitchLayer::Accept(ILayerVisitor& visitor) const
+{
+ visitor.VisitSwitchLayer(this, GetName());
+}
+
+} // namespace armnn