From 59a950cefe927d002aa00d7c3af54f4389e00162 Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Thu, 13 Dec 2018 12:48:25 +0000 Subject: IVGCVSW-2377 Add no-op factory implementations for all backends for the Greater operation * Added QueueDescriptor in WorkloadData.hpp * Added CreateGreater function in WorkloadFactory.hpp * Added stub implementation of the CreateGreater function in RefWorkloadFactory, NeonWorkloadFactory and ClWorkloadFactory * Added GreaterLayer stub implementation * Renamed ArithmeticBaseLayer to ElementwiseBaseLayer Change-Id: I7e38c2936de905da921a92ba3f918478169ec7f5 --- src/armnn/layers/ElementwiseBaseLayer.cpp | 69 +++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/armnn/layers/ElementwiseBaseLayer.cpp (limited to 'src/armnn/layers/ElementwiseBaseLayer.cpp') diff --git a/src/armnn/layers/ElementwiseBaseLayer.cpp b/src/armnn/layers/ElementwiseBaseLayer.cpp new file mode 100644 index 0000000000..761814176d --- /dev/null +++ b/src/armnn/layers/ElementwiseBaseLayer.cpp @@ -0,0 +1,69 @@ +// +// Copyright © 2017 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "ElementwiseBaseLayer.hpp" + +#include "InternalTypes.hpp" +#include "armnn/Exceptions.hpp" +#include + +#include + +namespace armnn +{ + +ElementwiseBaseLayer::ElementwiseBaseLayer(unsigned int numInputSlots, unsigned int numOutputSlots, + LayerType type, const char* name) + : Layer(numInputSlots, numOutputSlots, type, name) +{ +} + +std::vector ElementwiseBaseLayer::InferOutputShapes(const std::vector& inputShapes) const +{ + BOOST_ASSERT(inputShapes.size() == 2); + auto& input0 = inputShapes[0]; + auto& input1 = inputShapes[1]; + + // Get the max of the inputs. + BOOST_ASSERT(input0.GetNumDimensions() == input1.GetNumDimensions()); + unsigned int numDims = input0.GetNumDimensions(); + std::vector dims(numDims); + + for (unsigned int i = 0; i < numDims; i++) + { + unsigned int dim0 = input0[i]; + unsigned int dim1 = input1[i]; + +#if !NDEBUG + // Validate inputs are broadcast compatible. + BOOST_ASSERT_MSG(dim0 == dim1 || dim0 == 1 || dim1 == 1, + "Dimensions should either match or one should be of size 1."); +#endif + + dims[i] = std::max(dim0, dim1); + } + + return std::vector({ TensorShape(numDims, dims.data()) }); +} + +void ElementwiseBaseLayer::ValidateTensorShapesFromInputs() +{ + VerifyLayerConnections(2, CHECK_LOCATION()); + + auto inferredShapes = InferOutputShapes({ + GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape(), + GetInputSlot(1).GetConnection()->GetTensorInfo().GetShape() + }); + + BOOST_ASSERT(inferredShapes.size() == 1); + + std::string msg = GetLayerTypeAsCString(GetType()); + msg += "Layer: TensorShape set on OutputSlot[0] does not match the inferred shape."; + ConditionalThrowIfNotEqual(msg, + GetOutputSlot(0).GetTensorInfo().GetShape(), + inferredShapes[0]); +} + +} // namespace armnn -- cgit v1.2.1