aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/layers
diff options
context:
space:
mode:
authorKeith Davis <keith.davis@arm.com>2021-05-21 16:33:48 +0100
committerKeith Davis <keith.davis@arm.com>2021-06-16 17:27:59 +0100
commit3ae3f978cf9ce3174609b7152af87acb410b0fe0 (patch)
tree9c71ea6aafbacfeba6938b5e0e29cdc97a784b70 /src/armnn/layers
parent50de4fa4e7e0dd02a442ba350a1b40f293cb5a01 (diff)
downloadarmnn-3ae3f978cf9ce3174609b7152af87acb410b0fe0.tar.gz
MLCE-510 Add CpuRef Shape Operator to ArmNN
* Add front end * Add reference workload * Serialization/Deserialization * Add unit tests * Update ArmNN Versioning Signed-off-by: Keith Davis <keith.davis@arm.com> Change-Id: I6fcb1fa341d6f08dea4003b13544e6e9f53fefd3
Diffstat (limited to 'src/armnn/layers')
-rw-r--r--src/armnn/layers/ShapeLayer.cpp73
-rw-r--r--src/armnn/layers/ShapeLayer.hpp50
2 files changed, 123 insertions, 0 deletions
diff --git a/src/armnn/layers/ShapeLayer.cpp b/src/armnn/layers/ShapeLayer.cpp
new file mode 100644
index 0000000000..4193fa9aab
--- /dev/null
+++ b/src/armnn/layers/ShapeLayer.cpp
@@ -0,0 +1,73 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ShapeLayer.hpp"
+
+#include "LayerCloneBase.hpp"
+
+#include <armnn/TypesUtils.hpp>
+#include <armnn/utility/NumericCast.hpp>
+
+#include <backendsCommon/WorkloadData.hpp>
+#include <backendsCommon/WorkloadFactory.hpp>
+
+namespace armnn
+{
+
+ShapeLayer::ShapeLayer(const char* name)
+ : Layer(1, 1, LayerType::Shape, name)
+{
+}
+
+std::unique_ptr<IWorkload> ShapeLayer::CreateWorkload(const IWorkloadFactory& factory) const
+{
+ ShapeQueueDescriptor descriptor;
+ SetAdditionalInfo(descriptor);
+
+ return factory.CreateShape(descriptor, PrepInfoAndDesc(descriptor));
+}
+
+ShapeLayer* ShapeLayer::Clone(Graph& graph) const
+{
+ return CloneBase<ShapeLayer>(graph, GetName());
+}
+
+void ShapeLayer::ValidateTensorShapesFromInputs()
+{
+ VerifyLayerConnections(1, CHECK_LOCATION());
+
+ const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
+
+ VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
+
+ auto inferredShape = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
+
+ ARMNN_ASSERT(inferredShape.size() == 1);
+
+ ValidateAndCopyShape(outputShape, inferredShape[0], m_ShapeInferenceMethod, "ShapeLayer");
+}
+
+std::vector<TensorShape> ShapeLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
+{
+ IgnoreUnused(inputShapes);
+ ARMNN_ASSERT(inputShapes.size() == 1);
+
+ TensorShape outputShape({ inputShapes[0].GetNumDimensions()} );
+
+ return std::vector<TensorShape>({ outputShape });
+}
+
+void ShapeLayer::Accept(ILayerVisitor& visitor) const
+{
+ IgnoreUnused(visitor);
+ throw armnn::Exception("ShapeLayer VisitShapeLayer is not implemented");
+}
+
+void ShapeLayer::ExecuteStrategy(IStrategy& strategy) const
+{
+ strategy.ExecuteStrategy(this, BaseDescriptor(), {}, GetName());
+}
+
+} // namespace armnn
diff --git a/src/armnn/layers/ShapeLayer.hpp b/src/armnn/layers/ShapeLayer.hpp
new file mode 100644
index 0000000000..fee285c2f0
--- /dev/null
+++ b/src/armnn/layers/ShapeLayer.hpp
@@ -0,0 +1,50 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include "LayerWithParameters.hpp"
+
+namespace armnn
+{
+
+class ShapeLayer : public Layer
+{
+public:
+ /// Makes a workload for the Shape 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 IWorkloadFactory& factory) const override;
+
+ /// Creates a dynamically-allocated copy of this layer.
+ /// @param [in] graph The graph into which this layer is being cloned.
+ ShapeLayer* Clone(Graph& graph) const override;
+
+ /// Check if the input tensor shape(s)
+ /// will lead to a valid configuration of @ref ShapeLayer.
+ /// @param [in] shapeInferenceMethod Indicates if output shape shall be overwritten or just validated.
+ void ValidateTensorShapesFromInputs() 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;
+
+ void Accept(ILayerVisitor& visitor) const override;
+
+ void ExecuteStrategy(IStrategy& strategy) const override;
+
+protected:
+ /// Constructor to create a ShapeLayer.
+ /// @param [in] name Optional name for the layer.
+ ShapeLayer(const char* name);
+
+ /// Default destructor.
+ ~ShapeLayer() = default;
+};
+
+} // namespace armnn