1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "ShapeLayer.hpp"
7
8 #include "LayerCloneBase.hpp"
9
10 #include <armnn/TypesUtils.hpp>
11 #include <armnn/utility/NumericCast.hpp>
12
13 #include <armnn/backends/WorkloadData.hpp>
14 #include <armnn/backends/WorkloadFactory.hpp>
15
16 namespace armnn
17 {
18
ShapeLayer(const char * name)19 ShapeLayer::ShapeLayer(const char* name)
20 : Layer(1, 1, LayerType::Shape, name)
21 {
22 }
23
CreateWorkload(const IWorkloadFactory & factory) const24 std::unique_ptr<IWorkload> ShapeLayer::CreateWorkload(const IWorkloadFactory& factory) const
25 {
26 ShapeQueueDescriptor descriptor;
27 SetAdditionalInfo(descriptor);
28
29 return factory.CreateWorkload(LayerType::Shape, descriptor, PrepInfoAndDesc(descriptor));
30 }
31
Clone(Graph & graph) const32 ShapeLayer* ShapeLayer::Clone(Graph& graph) const
33 {
34 return CloneBase<ShapeLayer>(graph, GetName());
35 }
36
ValidateTensorShapesFromInputs()37 void ShapeLayer::ValidateTensorShapesFromInputs()
38 {
39 VerifyLayerConnections(1, CHECK_LOCATION());
40
41 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
42
43 VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
44
45 auto inferredShape = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
46
47 ARMNN_ASSERT(inferredShape.size() == 1);
48
49 ValidateAndCopyShape(outputShape, inferredShape[0], m_ShapeInferenceMethod, "ShapeLayer");
50 }
51
InferOutputShapes(const std::vector<TensorShape> & inputShapes) const52 std::vector<TensorShape> ShapeLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
53 {
54 IgnoreUnused(inputShapes);
55 ARMNN_ASSERT(inputShapes.size() == 1);
56
57 TensorShape outputShape({ inputShapes[0].GetNumDimensions()} );
58
59 return std::vector<TensorShape>({ outputShape });
60 }
61
62
ExecuteStrategy(IStrategy & strategy) const63 void ShapeLayer::ExecuteStrategy(IStrategy& strategy) const
64 {
65 strategy.ExecuteStrategy(this, BaseDescriptor(), {}, GetName());
66 }
67
68 } // namespace armnn
69