blob: 791a3d5d8954361059111e33c62b238511a49347 [file] [log] [blame]
josh minor4a3c6102020-01-06 16:40:46 -06001//
Declan-ARM7c75e332024-03-12 16:40:25 +00002// Copyright © 2020-2024 Arm Ltd and Contributors. All rights reserved.
josh minor4a3c6102020-01-06 16:40:46 -06003// SPDX-License-Identifier: MIT
4//
5
6#include "ElementwiseUnaryLayer.hpp"
7
8#include "LayerCloneBase.hpp"
9
Colm Donelan0c479742021-12-10 12:43:54 +000010#include <armnn/backends/WorkloadData.hpp>
11#include <armnn/backends/WorkloadFactory.hpp>
josh minor4a3c6102020-01-06 16:40:46 -060012
13#include <algorithm>
14
15namespace armnn
16{
17
18ElementwiseUnaryLayer::ElementwiseUnaryLayer(const ElementwiseUnaryDescriptor& param, const char* name)
19 : LayerWithParameters(1, 1, LayerType::ElementwiseUnary, param, name)
20{
21}
22
23std::unique_ptr<IWorkload> ElementwiseUnaryLayer::CreateWorkload(const IWorkloadFactory& factory) const
24{
25 ElementwiseUnaryQueueDescriptor descriptor;
Teresa Charlin611c7fb2022-01-07 09:47:29 +000026 return factory.CreateWorkload(LayerType::ElementwiseUnary, descriptor, PrepInfoAndDesc(descriptor));
josh minor4a3c6102020-01-06 16:40:46 -060027}
28
29ElementwiseUnaryLayer* ElementwiseUnaryLayer::Clone(Graph& graph) const
30{
31 return CloneBase<ElementwiseUnaryLayer>(graph, m_Param, GetName());
32}
33
34std::vector<TensorShape> ElementwiseUnaryLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
35{
36 // Should return the shape of the input tensor
Declan-ARM7c75e332024-03-12 16:40:25 +000037 if (inputShapes.size() != 1)
38 {
39 throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) +
40 "\" - should be \"1\".");
41 }
42
josh minor4a3c6102020-01-06 16:40:46 -060043 const TensorShape& input = inputShapes[0];
44
45 return std::vector<TensorShape>({ input });
46}
47
Finn Williamsf24effa2020-07-03 10:12:03 +010048void ElementwiseUnaryLayer::ValidateTensorShapesFromInputs()
josh minor4a3c6102020-01-06 16:40:46 -060049{
50 VerifyLayerConnections(1, CHECK_LOCATION());
51
Finn Williams87d0bda2020-07-03 10:12:03 +010052 const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
53
Finn Williamsf24effa2020-07-03 10:12:03 +010054 VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
Finn Williams87d0bda2020-07-03 10:12:03 +010055
josh minor4a3c6102020-01-06 16:40:46 -060056 std::vector<TensorShape> inferredShapes = InferOutputShapes({
Mike Kellya9ac6ba2023-06-30 15:18:26 +010057 GetInputSlot(0).GetTensorInfo().GetShape()});
Declan-ARM7c75e332024-03-12 16:40:25 +000058
59 if (inferredShapes.size() != 1)
60 {
61 throw armnn::Exception("inferredShapes has "
62 + std::to_string(inferredShapes.size()) +
63 " elements - should only have 1.");
64 }
josh minor4a3c6102020-01-06 16:40:46 -060065
Finn Williamsf24effa2020-07-03 10:12:03 +010066 ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, GetLayerTypeAsCString(GetType()));
josh minor4a3c6102020-01-06 16:40:46 -060067}
68
Nikhil Raj4d2eec02022-05-30 11:08:52 +010069void ElementwiseUnaryLayer::ExecuteStrategy(IStrategy& strategy) const
josh minor4a3c6102020-01-06 16:40:46 -060070{
Nikhil Raj4d2eec02022-05-30 11:08:52 +010071 strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
josh minor4a3c6102020-01-06 16:40:46 -060072}
josh minor4a3c6102020-01-06 16:40:46 -060073
74} // namespace armnn