aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/layers
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnn/layers')
-rw-r--r--src/armnn/layers/SwitchLayer.cpp60
-rw-r--r--src/armnn/layers/SwitchLayer.hpp42
2 files changed, 102 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
diff --git a/src/armnn/layers/SwitchLayer.hpp b/src/armnn/layers/SwitchLayer.hpp
new file mode 100644
index 0000000000..bfda8c2b1b
--- /dev/null
+++ b/src/armnn/layers/SwitchLayer.hpp
@@ -0,0 +1,42 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#pragma once
+
+#include "Layer.hpp"
+
+namespace armnn
+{
+
+/// This layer calculates both true and false outputs for input.
+class SwitchLayer : public Layer
+{
+public:
+ /// Makes a workload for the Switch type.
+ /// @param [in] graph The graph where this layer can be found.
+ /// @param [in] factory The workload factory which will create the workload.
+ /// @return A pointer to the created workload, or nullptr if not created.
+ virtual std::unique_ptr<IWorkload> CreateWorkload(const Graph& graph,
+ const IWorkloadFactory& factory) const override;
+
+ /// Creates a dynamically-allocated copy of this layer.
+ /// @param [in] graph The graph into which this layer is being cloned.
+ SwitchLayer* Clone(Graph& graph) const override;
+
+ /// Check if the input tensor shape(s)
+ /// will lead to a valid configuration of @ref SwitchLayer.
+ void ValidateTensorShapesFromInputs() override;
+
+ void Accept(ILayerVisitor& visitor) const override;
+
+protected:
+ /// Constructor to create a SwitchLayer.
+ /// @param [in] name Optional name for the layer.
+ SwitchLayer(const char* name);
+
+ /// Default destructor
+ ~SwitchLayer() = default;
+};
+
+} // namespace armnn