xref: /aosp_15_r20/external/armnn/src/armnn/layers/PermuteLayer.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "PermuteLayer.hpp"
7 
8 #include "LayerCloneBase.hpp"
9 
10 #include <armnn/TypesUtils.hpp>
11 
12 #include <armnnUtils/Permute.hpp>
13 
14 #include <armnn/backends/WorkloadData.hpp>
15 #include <armnn/backends/WorkloadFactory.hpp>
16 
17 namespace armnn
18 {
19 
PermuteLayer(const PermuteDescriptor & param,const char * name)20 PermuteLayer::PermuteLayer(const PermuteDescriptor& param, const char* name)
21     : LayerWithParameters(1, 1, LayerType::Permute, param, name)
22 {
23 }
24 
CreateWorkload(const IWorkloadFactory & factory) const25 std::unique_ptr<IWorkload> PermuteLayer::CreateWorkload(const IWorkloadFactory& factory) const
26 {
27     PermuteQueueDescriptor descriptor;
28     SetAdditionalInfo(descriptor);
29 
30     return factory.CreateWorkload(LayerType::Permute, descriptor, PrepInfoAndDesc(descriptor));
31 }
32 
Clone(Graph & graph) const33 PermuteLayer* PermuteLayer::Clone(Graph& graph) const
34 {
35     return CloneBase<PermuteLayer>(graph, m_Param, GetName());
36 }
37 
InferOutputShapes(const std::vector<TensorShape> & inputShapes) const38 std::vector<TensorShape> PermuteLayer::InferOutputShapes(const std::vector<TensorShape>& inputShapes) const
39 {
40     ARMNN_ASSERT(inputShapes.size() == 1);
41     const TensorShape& inShape = inputShapes[0];
42     return std::vector<TensorShape> ({armnnUtils::Permuted(inShape, m_Param.m_DimMappings)});
43 }
44 
ValidateTensorShapesFromInputs()45 void PermuteLayer::ValidateTensorShapesFromInputs()
46 {
47     VerifyLayerConnections(1, CHECK_LOCATION());
48 
49     const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
50 
51     VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
52 
53     auto inferredShapes = InferOutputShapes({ GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape() });
54 
55     ARMNN_ASSERT(inferredShapes.size() == 1);
56 
57     ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "PermuteLayer");
58 }
59 
ExecuteStrategy(IStrategy & strategy) const60 void PermuteLayer::ExecuteStrategy(IStrategy& strategy) const
61 {
62     strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
63 }
64 
65 } // namespace armnn
66