xref: /aosp_15_r20/external/ComputeLibrary/src/graph/backends/NEON/NENodeValidator.cpp (revision c217d954acce2dbc11938adb493fc0abd69584f3)
1 /*
2  * Copyright (c) 2018-2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "arm_compute/graph/backends/NEON/NENodeValidator.h"
25 
26 #include "arm_compute/graph/backends/ValidateHelpers.h"
27 #include "arm_compute/graph/nodes/Nodes.h"
28 
29 #include "arm_compute/runtime/CPP/CPPFunctions.h"
30 #include "arm_compute/runtime/NEON/NEFunctions.h"
31 #include "support/Cast.h"
32 
33 using namespace arm_compute::utils::cast;
34 
35 namespace arm_compute
36 {
37 namespace graph
38 {
39 namespace backends
40 {
41 /** Collection of CPU element-wise functions */
42 struct NEEltwiseLayerFunctions
43 {
44     using ArithmeticAddition      = NEArithmeticAddition;
45     using ArithmeticSubtraction   = NEArithmeticSubtraction;
46     using PixelWiseMultiplication = NEPixelWiseMultiplication;
47     using ElementwiseMax          = NEElementwiseMax;
48     using ArithmeticDivision      = NEElementwiseDivision;
49 };
50 
51 /** Collection of CPU unary element-wise functions */
52 struct NEUnaryEltwiseLayerFunctions
53 {
54     using ExpLayer = NEExpLayer;
55 };
56 
validate(INode * node)57 Status NENodeValidator::validate(INode *node)
58 {
59     if(node == nullptr)
60     {
61         return Status{};
62     }
63 
64     NodeType type = node->type();
65     switch(type)
66     {
67         case NodeType::ArgMinMaxLayer:
68             return detail::validate_arg_min_max_layer<NEArgMinMaxLayer>(*polymorphic_downcast<ArgMinMaxLayerNode *>(node));
69         case NodeType::BoundingBoxTransformLayer:
70             return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : BoundingBoxTransformLayer");
71         case NodeType::ChannelShuffleLayer:
72             return detail::validate_channel_shuffle_layer<NEChannelShuffleLayer>(*polymorphic_downcast<ChannelShuffleLayerNode *>(node));
73         case NodeType::ConvolutionLayer:
74             return detail::validate_convolution_layer<NEConvolutionLayer,
75                    NEDirectConvolutionLayer,
76                    NEGEMMConvolutionLayer,
77                    NEWinogradConvolutionLayer>(*polymorphic_downcast<ConvolutionLayerNode *>(node));
78         case NodeType::DepthToSpaceLayer:
79             return detail::validate_depth_to_space_layer<NEDepthToSpaceLayer>(*polymorphic_downcast<DepthToSpaceLayerNode *>(node));
80         case NodeType::DepthwiseConvolutionLayer:
81             return detail::validate_depthwise_convolution_layer<NEDepthwiseConvolutionLayer>(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
82         case NodeType::DequantizationLayer:
83             return detail::validate_dequantization_layer<NEDequantizationLayer>(*polymorphic_downcast<DequantizationLayerNode *>(node));
84         case NodeType::DetectionOutputLayer:
85             return detail::validate_detection_output_layer<CPPDetectionOutputLayer>(*polymorphic_downcast<DetectionOutputLayerNode *>(node));
86         case NodeType::DetectionPostProcessLayer:
87             return detail::validate_detection_post_process_layer<NEDetectionPostProcessLayer>(*polymorphic_downcast<DetectionPostProcessLayerNode *>(node));
88         case NodeType::GenerateProposalsLayer:
89             return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : GenerateProposalsLayer");
90         case NodeType::L2NormalizeLayer:
91             return detail::validate_l2_normalize_layer<NEL2NormalizeLayer>(*polymorphic_downcast<L2NormalizeLayerNode *>(node));
92         case NodeType::NormalizePlanarYUVLayer:
93             return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : NormalizePlanarYUVLayer");
94         case NodeType::PadLayer:
95             return detail::validate_pad_layer<NEPadLayer>(*polymorphic_downcast<PadLayerNode *>(node));
96         case NodeType::PermuteLayer:
97             return detail::validate_permute_layer<NEPermute>(*polymorphic_downcast<PermuteLayerNode *>(node));
98         case NodeType::PReluLayer:
99             return detail::validate_prelu_layer<NEPReluLayer>(*polymorphic_downcast<PReluLayerNode *>(node));
100         case NodeType::PriorBoxLayer:
101             return detail::validate_priorbox_layer<NEPriorBoxLayer>(*polymorphic_downcast<PriorBoxLayerNode *>(node));
102         case NodeType::QuantizationLayer:
103             return detail::validate_quantization_layer<NEQuantizationLayer>(*polymorphic_downcast<QuantizationLayerNode *>(node));
104         case NodeType::ReductionOperationLayer:
105             return detail::validate_reduction_operation_layer<NEReductionOperation>(*polymorphic_downcast<ReductionLayerNode *>(node));
106         case NodeType::ReorgLayer:
107             return detail::validate_reorg_layer<NEReorgLayer>(*polymorphic_downcast<ReorgLayerNode *>(node));
108         case NodeType::ReshapeLayer:
109             return detail::validate_reshape_layer<NEReshapeLayer>(*polymorphic_downcast<ReshapeLayerNode *>(node));
110         case NodeType::ROIAlignLayer:
111             return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ROIAlignLayer");
112         case NodeType::SliceLayer:
113             return detail::validate_slice_layer<NESlice>(*polymorphic_downcast<SliceLayerNode *>(node));
114         case NodeType::StridedSliceLayer:
115             return detail::validate_strided_slice_layer<NEStridedSlice>(*polymorphic_downcast<StridedSliceLayerNode *>(node));
116         case NodeType::EltwiseLayer:
117             return detail::validate_eltwise_Layer<NEEltwiseLayerFunctions>(*polymorphic_downcast<EltwiseLayerNode *>(node));
118         case NodeType::UnaryEltwiseLayer:
119             return detail::validate_unary_eltwise_layer<NEUnaryEltwiseLayerFunctions>(*polymorphic_downcast<UnaryEltwiseLayerNode *>(node));
120         default:
121             return Status{};
122     }
123 }
124 } // namespace backends
125 } // namespace graph
126 } // namespace arm_compute
127