aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/layers
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnn/layers')
-rw-r--r--src/armnn/layers/ComparisonLayer.cpp80
-rw-r--r--src/armnn/layers/ComparisonLayer.hpp50
-rw-r--r--src/armnn/layers/EqualLayer.cpp39
-rw-r--r--src/armnn/layers/EqualLayer.hpp38
-rw-r--r--src/armnn/layers/GreaterLayer.cpp39
-rw-r--r--src/armnn/layers/GreaterLayer.hpp39
6 files changed, 130 insertions, 155 deletions
diff --git a/src/armnn/layers/ComparisonLayer.cpp b/src/armnn/layers/ComparisonLayer.cpp
new file mode 100644
index 0000000000..75518e580e
--- /dev/null
+++ b/src/armnn/layers/ComparisonLayer.cpp
@@ -0,0 +1,80 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ComparisonLayer.hpp"
+
+#include "LayerCloneBase.hpp"
+
+#include <backendsCommon/WorkloadData.hpp>
+#include <backendsCommon/WorkloadFactory.hpp>
+
+#include <algorithm>
+
+namespace armnn
+{
+
+ComparisonLayer::ComparisonLayer(const ComparisonDescriptor& param, const char* name)
+ : LayerWithParameters(2, 1, LayerType::Comparison, param, name)
+{
+}
+
+std::unique_ptr<IWorkload> ComparisonLayer::CreateWorkload(const Graph& graph,
+ const IWorkloadFactory& factory) const
+{
+ ComparisonQueueDescriptor descriptor;
+ return factory.CreateComparison(descriptor, PrepInfoAndDesc(descriptor, graph));
+}
+
+ComparisonLayer* ComparisonLayer::Clone(Graph& graph) const
+{
+ return CloneBase<ComparisonLayer>(graph, m_Param, GetName());
+}
+
+std::vector<TensorShape> ComparisonLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
+{
+ BOOST_ASSERT(inputShapes.size() == 2);
+ const TensorShape& input0 = inputShapes[0];
+ const TensorShape& input1 = inputShapes[1];
+
+ BOOST_ASSERT(input0.GetNumDimensions() == input1.GetNumDimensions());
+ unsigned int numDims = input0.GetNumDimensions();
+
+ std::vector<unsigned int> dims(numDims);
+ for (unsigned int i = 0; i < numDims; i++)
+ {
+ unsigned int dim0 = input0[i];
+ unsigned int dim1 = input1[i];
+
+ BOOST_ASSERT_MSG(dim0 == dim1 || dim0 == 1 || dim1 == 1,
+ "Dimensions should either match or one should be of size 1.");
+
+ dims[i] = std::max(dim0, dim1);
+ }
+
+ return std::vector<TensorShape>({ TensorShape(numDims, dims.data()) });
+}
+
+void ComparisonLayer::ValidateTensorShapesFromInputs()
+{
+ VerifyLayerConnections(2, CHECK_LOCATION());
+
+ std::vector<TensorShape> inferredShapes = InferOutputShapes({
+ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape(),
+ GetInputSlot(1).GetConnection()->GetTensorInfo().GetShape()
+ });
+ BOOST_ASSERT(inferredShapes.size() == 1);
+
+ ConditionalThrowIfNotEqual<LayerValidationException>(
+ "ComparisonLayer: TensorShape set on OutputSlot[0] does not match the inferred shape.",
+ GetOutputSlot(0).GetTensorInfo().GetShape(),
+ inferredShapes[0]);
+}
+
+void ComparisonLayer::Accept(ILayerVisitor& visitor) const
+{
+ visitor.VisitComparisonLayer(this, GetParameters(), GetName());
+}
+
+} // namespace armnn
diff --git a/src/armnn/layers/ComparisonLayer.hpp b/src/armnn/layers/ComparisonLayer.hpp
new file mode 100644
index 0000000000..bbc2b573bf
--- /dev/null
+++ b/src/armnn/layers/ComparisonLayer.hpp
@@ -0,0 +1,50 @@
+//
+// Copyright © 2019 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include "LayerWithParameters.hpp"
+
+namespace armnn
+{
+
+/// This layer represents a comparison operation.
+class ComparisonLayer : public LayerWithParameters<ComparisonDescriptor>
+{
+public:
+ /// Makes a workload for the Comparison 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
+ ComparisonLayer* Clone(Graph& graph) const override;
+
+ /// By default returns inputShapes if the number of inputs are equal to number of outputs,
+ /// otherwise infers the output shapes from given input shapes and layer properties.
+ /// @param [in] inputShapes The input shapes layer has.
+ /// @return A vector to the inferred output shape.
+ std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const override;
+
+ /// Check if the input tensor shape(s) will lead to a valid configuration
+ /// of @ref ComparisonLayer
+ void ValidateTensorShapesFromInputs() override;
+
+ void Accept(ILayerVisitor& visitor) const override;
+
+protected:
+ /// Constructor to create a ComparisonLayer
+ /// @param [in] param ComparisonDescriptor to configure the ComparisonLayer
+ /// @param [in] name Optional name for the layer
+ ComparisonLayer(const ComparisonDescriptor& param, const char* name);
+
+ /// Default destructor
+ ~ComparisonLayer() = default;
+};
+
+} // namespace armnn
diff --git a/src/armnn/layers/EqualLayer.cpp b/src/armnn/layers/EqualLayer.cpp
deleted file mode 100644
index 7d16668b06..0000000000
--- a/src/armnn/layers/EqualLayer.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#include "EqualLayer.hpp"
-
-#include "LayerCloneBase.hpp"
-
-#include <armnn/TypesUtils.hpp>
-#include <backendsCommon/WorkloadData.hpp>
-#include <backendsCommon/WorkloadFactory.hpp>
-
-namespace armnn
-{
-
-EqualLayer::EqualLayer(const char* name)
- : ElementwiseBaseLayer(2, 1, LayerType::Equal, name)
-{
-}
-
-std::unique_ptr<IWorkload> EqualLayer::CreateWorkload(const Graph& graph,
- const IWorkloadFactory& factory) const
-{
- EqualQueueDescriptor descriptor;
- return factory.CreateEqual(descriptor, PrepInfoAndDesc(descriptor, graph));
-}
-
-EqualLayer* EqualLayer::Clone(Graph& graph) const
-{
- return CloneBase<EqualLayer>(graph, GetName());
-}
-
-void EqualLayer::Accept(ILayerVisitor& visitor) const
-{
- visitor.VisitEqualLayer(this, GetName());
-}
-
-} // namespace armnn
diff --git a/src/armnn/layers/EqualLayer.hpp b/src/armnn/layers/EqualLayer.hpp
deleted file mode 100644
index b6a01eff2d..0000000000
--- a/src/armnn/layers/EqualLayer.hpp
+++ /dev/null
@@ -1,38 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#pragma once
-
-#include "ElementwiseBaseLayer.hpp"
-
-namespace armnn
-{
-/// This layer represents an equal operation.
-class EqualLayer : public ElementwiseBaseLayer
-{
-public:
- /// Makes a workload for the Equal 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.
- EqualLayer* Clone(Graph& graph) const override;
-
- void Accept(ILayerVisitor& visitor) const override;
-
-protected:
- /// Constructor to create a EqualLayer.
- /// @param [in] name Optional name for the layer.
- EqualLayer(const char* name);
-
- /// Default destructor
- ~EqualLayer() = default;
-};
-
-} //namespace armnn
diff --git a/src/armnn/layers/GreaterLayer.cpp b/src/armnn/layers/GreaterLayer.cpp
deleted file mode 100644
index a9fe5e0d8c..0000000000
--- a/src/armnn/layers/GreaterLayer.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#include "GreaterLayer.hpp"
-
-#include "LayerCloneBase.hpp"
-
-#include <armnn/TypesUtils.hpp>
-#include <backendsCommon/WorkloadData.hpp>
-#include <backendsCommon/WorkloadFactory.hpp>
-
-namespace armnn
-{
-
-GreaterLayer::GreaterLayer(const char* name)
- : ElementwiseBaseLayer(2, 1, LayerType::Greater, name)
-{
-}
-
-std::unique_ptr<IWorkload> GreaterLayer::CreateWorkload(const Graph& graph,
- const IWorkloadFactory& factory) const
-{
- GreaterQueueDescriptor descriptor;
- return factory.CreateGreater(descriptor, PrepInfoAndDesc(descriptor, graph));
-}
-
-GreaterLayer* GreaterLayer::Clone(Graph& graph) const
-{
- return CloneBase<GreaterLayer>(graph, GetName());
-}
-
-void GreaterLayer::Accept(ILayerVisitor& visitor) const
-{
- visitor.VisitGreaterLayer(this, GetName());
-}
-
-} // namespace armnn
diff --git a/src/armnn/layers/GreaterLayer.hpp b/src/armnn/layers/GreaterLayer.hpp
deleted file mode 100644
index bdee948d6e..0000000000
--- a/src/armnn/layers/GreaterLayer.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-
-#pragma once
-
-#include "ElementwiseBaseLayer.hpp"
-
-namespace armnn
-{
-
-/// This layer represents a greater operation.
-class GreaterLayer : public ElementwiseBaseLayer
-{
-public:
- /// Makes a workload for the Greater 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.
- GreaterLayer* Clone(Graph& graph) const override;
-
- void Accept(ILayerVisitor& visitor) const override;
-
-protected:
- /// Constructor to create a GreaterLayer.
- /// @param [in] name Optional name for the layer.
- GreaterLayer(const char* name);
-
- /// Default destructor
- ~GreaterLayer() = default;
-};
-
-} //namespace armnn