From eff363d58992fb6384053259f9e1ee773f8cd4df Mon Sep 17 00:00:00 2001 From: Sadik Armagan Date: Fri, 5 Apr 2019 15:25:46 +0100 Subject: IVGCVSW-2914 Add Switch Layer and no-op factory method Change-Id: I6a6ece708a49e8a97c83a3e7fec11c88af1e1cfa Signed-off-by: Sadik Armagan Signed-off-by: Aron Virginas-Tar --- src/armnn/layers/SwitchLayer.cpp | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/armnn/layers/SwitchLayer.cpp (limited to 'src/armnn/layers/SwitchLayer.cpp') 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 +#include + +namespace armnn +{ + +SwitchLayer::SwitchLayer(const char* name) + : Layer(2, 2, LayerType::Switch, name) +{} + +std::unique_ptr 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(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 inferredShapes = InferOutputShapes({ + GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape(), + GetInputSlot(1).GetConnection()->GetTensorInfo().GetShape() }); + + BOOST_ASSERT(inferredShapes.size() == 1); + + ConditionalThrowIfNotEqual( + "SwitchLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.", + GetOutputSlot(0).GetTensorInfo().GetShape(), + inferredShapes[0]); + + ConditionalThrowIfNotEqual( + "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 -- cgit v1.2.1