mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 1 | // |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 2 | // Copyright © 2021-2024 Arm Ltd and Contributors. All rights reserved. |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | #include "CastLayer.hpp" |
| 6 | |
| 7 | #include "LayerCloneBase.hpp" |
| 8 | #include <armnn/TypesUtils.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> |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 12 | |
| 13 | namespace armnn |
| 14 | { |
| 15 | |
| 16 | CastLayer::CastLayer(const char* name) |
| 17 | : Layer(1, 1, LayerType::Cast, name) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | std::unique_ptr<IWorkload> CastLayer::CreateWorkload(const IWorkloadFactory& factory) const |
| 22 | { |
| 23 | CastQueueDescriptor descriptor; |
| 24 | SetAdditionalInfo(descriptor); |
| 25 | |
Teresa Charlin | 611c7fb | 2022-01-07 09:47:29 +0000 | [diff] [blame] | 26 | return factory.CreateWorkload(LayerType::Cast, descriptor, PrepInfoAndDesc(descriptor)); |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | CastLayer* CastLayer::Clone(Graph& graph) const |
| 30 | { |
| 31 | return CloneBase<CastLayer>(graph, GetName()); |
| 32 | } |
| 33 | |
| 34 | void CastLayer::ValidateTensorShapesFromInputs() |
| 35 | { |
| 36 | VerifyLayerConnections(1, CHECK_LOCATION()); |
| 37 | |
| 38 | const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape(); |
| 39 | |
| 40 | VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod); |
| 41 | |
Mike Kelly | a9ac6ba | 2023-06-30 15:18:26 +0100 | [diff] [blame] | 42 | auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetTensorInfo().GetShape() }); |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 43 | |
Declan-ARM | 7c75e33 | 2024-03-12 16:40:25 +0000 | [diff] [blame^] | 44 | if (inferredShapes.size() != 1) |
| 45 | { |
| 46 | throw armnn::LayerValidationException("inferredShapes has " |
| 47 | + std::to_string(inferredShapes.size()) + |
| 48 | " elements - should only have 1."); |
| 49 | } |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 50 | |
| 51 | ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "CastLayer"); |
| 52 | } |
| 53 | |
mathad01 | b392e98 | 2021-04-07 12:07:30 +0100 | [diff] [blame] | 54 | } // namespace armnn |