xref: /aosp_15_r20/external/armnn/src/armnn/layers/SwitchLayer.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #include "SwitchLayer.hpp"
6 
7 #include "LayerCloneBase.hpp"
8 
9 #include <armnn/backends/WorkloadData.hpp>
10 #include <armnn/backends/WorkloadFactory.hpp>
11 
12 namespace armnn
13 {
14 
SwitchLayer(const char * name)15 SwitchLayer::SwitchLayer(const char* name)
16     : Layer(2, 2, LayerType::Switch, name)
17 {}
18 
CreateWorkload(const IWorkloadFactory & factory) const19 std::unique_ptr<IWorkload> SwitchLayer::CreateWorkload(const IWorkloadFactory& factory) const
20 {
21     SwitchQueueDescriptor descriptor;
22     SetAdditionalInfo(descriptor);
23 
24     return factory.CreateWorkload(LayerType::Switch, descriptor, PrepInfoAndDesc(descriptor));
25 }
26 
Clone(Graph & graph) const27 SwitchLayer* SwitchLayer::Clone(Graph& graph) const
28 {
29     return CloneBase<SwitchLayer>(graph, GetName());
30 }
31 
ValidateTensorShapesFromInputs()32 void SwitchLayer::ValidateTensorShapesFromInputs()
33 {
34     VerifyLayerConnections(2, CHECK_LOCATION());
35 
36     const TensorShape& outputShape = GetOutputSlot(0).GetTensorInfo().GetShape();
37 
38     VerifyShapeInferenceType(outputShape, m_ShapeInferenceMethod);
39 
40     ARMNN_ASSERT_MSG(GetNumOutputSlots() == 2, "SwitchLayer: The layer should return 2 outputs.");
41 
42     // Assuming first input is the Input and second input is the Constant
43     std::vector<TensorShape> inferredShapes = InferOutputShapes({
44         GetInputSlot(0).GetConnection()->GetTensorInfo().GetShape(),
45         GetInputSlot(1).GetConnection()->GetTensorInfo().GetShape()});
46 
47     ARMNN_ASSERT(inferredShapes.size() == 2);
48 
49     ValidateAndCopyShape(outputShape, inferredShapes[0], m_ShapeInferenceMethod, "SwitchLayer");
50 
51     ValidateAndCopyShape(
52             GetOutputSlot(1).GetTensorInfo().GetShape(), inferredShapes[1], m_ShapeInferenceMethod, "SwitchLayer", 1);
53 }
54 
ExecuteStrategy(IStrategy & strategy) const55 void SwitchLayer::ExecuteStrategy(IStrategy& strategy) const
56 {
57     strategy.ExecuteStrategy(this, GetParameters(), {}, GetName());
58 }
59 
60 } // namespace armnn
61