josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 1 | // |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 2 | // Copyright © 2020-2024 Arm Ltd and Contributors. All rights reserved. |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ElementwiseUnaryLayer.hpp" |
| 7 | |
| 8 | #include "LayerCloneBase.hpp" |
| 9 | |
Colm Donelan | 0c47974 | 2021-12-10 12:43:54 +0000 | [diff] [blame] | 10 | #include <armnn/backends/WorkloadData.hpp> |
| 11 | #include <armnn/backends/WorkloadFactory.hpp> |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 12 | |
| 13 | #include <algorithm> |
| 14 | |
| 15 | namespace armnn |
| 16 | { |
| 17 | |
| 18 | ElementwiseUnaryLayer::ElementwiseUnaryLayer(const ElementwiseUnaryDescriptor& param, const char* name) |
| 19 | : LayerWithParameters(1, 1, LayerType::ElementwiseUnary, param, name) |
| 20 | { |
| 21 | } |
| 22 | |
| 23 | std::unique_ptr<IWorkload> ElementwiseUnaryLayer::CreateWorkload(const IWorkloadFactory& factory) const |
| 24 | { |
| 25 | ElementwiseUnaryQueueDescriptor descriptor; |
Teresa Charlin | 611c7fb | 2022-01-07 09:47:29 +0000 | [diff] [blame] | 26 | return factory.CreateWorkload(LayerType::ElementwiseUnary, descriptor, PrepInfoAndDesc(descriptor)); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | ElementwiseUnaryLayer* ElementwiseUnaryLayer::Clone(Graph& graph) const |
| 30 | { |
| 31 | return CloneBase<ElementwiseUnaryLayer>(graph, m_Param, GetName()); |
| 32 | } |
| 33 | |
| 34 | std::vector<TensorShape> ElementwiseUnaryLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const |
| 35 | { |
| 36 | // Should return the shape of the input tensor |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 37 | if (inputShapes.size() != 1) |
| 38 | { |
| 39 | throw armnn::Exception("inputShapes' size is \"" + std::to_string(inputShapes.size()) + |
| 40 | "\" - should be \"1\"."); |
| 41 | } |
| 42 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 43 | const TensorShape& input = inputShapes[0]; |
| 44 | |
| 45 | return std::vector<TensorShape>({ input }); |
| 46 | } |
| 47 | |
Finn Williams | f24effa | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 48 | void ElementwiseUnaryLayer::ValidateTensorShapesFromInputs() |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 49 | { |
| 50 | VerifyLayerConnections(1, CHECK_LOCATION()); |
| 51 | |
Finn Williams | 87d0bda | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 52 | const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape(); |
| 53 | |
Finn Williams | f24effa | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 54 | VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); |
Finn Williams | 87d0bda | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 55 | |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 56 | std::vector<TensorShape> inferredShapes = InferOutputShapes({ |
Mike Kelly | a9ac6ba | 2023-06-30 15:18:26 +0100 | [diff] [blame] | 57 | GetInputSlot(0).GetTensorInfo().GetShape()}); |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 58 | |
| 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 minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 65 | |
Finn Williams | f24effa | 2020-07-03 10:12:03 +0100 | [diff] [blame] | 66 | ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, GetLayerTypeAsCString(GetType())); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 67 | } |
| 68 | |
Nikhil Raj | 4d2eec0 | 2022-05-30 11:08:52 +0100 | [diff] [blame] | 69 | void ElementwiseUnaryLayer::ExecuteStrategy(IStrategy& strategy) const |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 70 | { |
Nikhil Raj | 4d2eec0 | 2022-05-30 11:08:52 +0100 | [diff] [blame] | 71 | strategy.ExecuteStrategy(this, GetParameters(), {}, GetName()); |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 72 | } |
josh minor | 4a3c610 | 2020-01-06 16:40:46 -0600 | [diff] [blame] | 73 | |
| 74 | } // namespace armnn |