1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5
6 #include "ElementwiseUnaryLayer.hpp"
7
8 #include "LayerCloneBase.hpp"
9
10 #include <armnn/backends/WorkloadData.hpp>
11 #include <armnn/backends/WorkloadFactory.hpp>
12
13 #include <algorithm>
14
15 namespace armnn
16 {
17
ElementwiseUnaryLayer(const ElementwiseUnaryDescriptor & param,const char * name)18 ElementwiseUnaryLayer::ElementwiseUnaryLayer(const ElementwiseUnaryDescriptor& param, const char* name)
19 : LayerWithParameters(1, 1, LayerType::ElementwiseUnary, param, name)
20 {
21 }
22
CreateWorkload(const IWorkloadFactory & factory) const23 std::unique_ptr<IWorkload> ElementwiseUnaryLayer::CreateWorkload(const IWorkloadFactory& factory) const
24 {
25 ElementwiseUnaryQueueDescriptor descriptor;
26 return factory.CreateWorkload(LayerType::ElementwiseUnary, descriptor, PrepInfoAndDesc(descriptor));
27 }
28
Clone(Graph & graph) const29 ElementwiseUnaryLayer* ElementwiseUnaryLayer::Clone(Graph& graph) const
30 {
31 return CloneBase<ElementwiseUnaryLayer>(graph, m_Param, GetName());
32 }
33
InferOutputShapes(const std::vector<TensorShape> & inputShapes) const34 std::vector<TensorShape> ElementwiseUnaryLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
35 {
36 // Should return the shape of the input tensor
37 ARMNN_ASSERT(inputShapes.size() == 1);
38 const TensorShape& input = inputShapes[0];
39
40 return std::vector<TensorShape>({ input });
41 }
42
ValidateTensorShapesFromInputs()43 void ElementwiseUnaryLayer::ValidateTensorShapesFromInputs()
44 {
45 VerifyLayerConnections(1, CHECK_LOCATION());
46
47 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
48
49 VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
50
51 std::vector<TensorShape> inferredShapes = InferOutputShapes({
52 GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape()});
53 ARMNN_ASSERT(inferredShapes.size() == 1);
54
55 ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, GetLayerTypeAsCString(GetType()));
56 }
57
ExecuteStrategy(IStrategy & strategy) const58 void ElementwiseUnaryLayer::ExecuteStrategy(IStrategy& strategy) const
59 {
60 strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
61 }
62
63 } // namespace armnn
64