• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2018-2020 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 "src/core/NEON/kernels/NEConvertFullyConnectedWeightsKernel.h"
32 #include "src/core/NEON/kernels/NEConvertQuantizedSignednessKernel.h"
33 #include "src/core/NEON/kernels/NEGEMMInterleave4x4Kernel.h"
34 #include "src/core/NEON/kernels/NEGEMMLowpMatrixMultiplyKernel.h"
35 #include "src/core/NEON/kernels/NEGEMMLowpOffsetContributionKernel.h"
36 #include "src/core/NEON/kernels/NEGEMMLowpOffsetContributionOutputStageKernel.h"
37 #include "src/core/NEON/kernels/NEGEMMLowpReductionKernel.h"
38 #include "src/core/NEON/kernels/NEGEMMMatrixAdditionKernel.h"
39 #include "src/core/NEON/kernels/NEGEMMMatrixMultiplyKernel.h"
40 #include "src/core/NEON/kernels/NEGEMMTranspose1xWKernel.h"
41 #include "src/core/NEON/kernels/NEQLSTMLayerNormalizationKernel.h"
42 #include "src/core/NEON/kernels/NEReshapeLayerKernel.h"
43 #include "src/core/NEON/kernels/NEWeightsReshapeKernel.h"
44 #include "support/Cast.h"
45 
46 using namespace arm_compute::utils::cast;
47 
48 namespace arm_compute
49 {
50 namespace graph
51 {
52 namespace backends
53 {
54 /** Collection of NEON element-wise functions */
55 struct NEEltwiseLayerFunctions
56 {
57     using ArithmeticAddition      = NEArithmeticAddition;
58     using ArithmeticSubtraction   = NEArithmeticSubtraction;
59     using PixelWiseMultiplication = NEPixelWiseMultiplication;
60     using ElementwiseMax          = NEElementwiseMax;
61 };
62 
63 /** Collection of NEON unary element-wise functions */
64 struct NEUnaryEltwiseLayerFunctions
65 {
66     using ExpLayer = NEExpLayer;
67 };
68 
validate(INode * node)69 Status NENodeValidator::validate(INode *node)
70 {
71     if(node == nullptr)
72     {
73         return Status{};
74     }
75 
76     NodeType type = node->type();
77     switch(type)
78     {
79         case NodeType::ArgMinMaxLayer:
80             return detail::validate_arg_min_max_layer<NEArgMinMaxLayer>(*polymorphic_downcast<ArgMinMaxLayerNode *>(node));
81         case NodeType::BoundingBoxTransformLayer:
82             return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : BoundingBoxTransformLayer");
83         case NodeType::ChannelShuffleLayer:
84             return detail::validate_channel_shuffle_layer<NEChannelShuffleLayer>(*polymorphic_downcast<ChannelShuffleLayerNode *>(node));
85         case NodeType::ConvolutionLayer:
86             return detail::validate_convolution_layer<NEConvolutionLayer,
87                    NEDirectConvolutionLayer,
88                    NEGEMMConvolutionLayer,
89                    NEWinogradConvolutionLayer>(*polymorphic_downcast<ConvolutionLayerNode *>(node));
90         case NodeType::DepthToSpaceLayer:
91             return detail::validate_depth_to_space_layer<NEDepthToSpaceLayer>(*polymorphic_downcast<DepthToSpaceLayerNode *>(node));
92         case NodeType::DepthwiseConvolutionLayer:
93             return detail::validate_depthwise_convolution_layer<NEDepthwiseConvolutionLayer>(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
94         case NodeType::DequantizationLayer:
95             return detail::validate_dequantization_layer<NEDequantizationLayer>(*polymorphic_downcast<DequantizationLayerNode *>(node));
96         case NodeType::DetectionOutputLayer:
97             return detail::validate_detection_output_layer<CPPDetectionOutputLayer>(*polymorphic_downcast<DetectionOutputLayerNode *>(node));
98         case NodeType::DetectionPostProcessLayer:
99             return detail::validate_detection_post_process_layer<NEDetectionPostProcessLayer>(*polymorphic_downcast<DetectionPostProcessLayerNode *>(node));
100         case NodeType::GenerateProposalsLayer:
101             return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : GenerateProposalsLayer");
102         case NodeType::L2NormalizeLayer:
103             return detail::validate_l2_normalize_layer<NEL2NormalizeLayer>(*polymorphic_downcast<L2NormalizeLayerNode *>(node));
104         case NodeType::NormalizePlanarYUVLayer:
105             return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : NormalizePlanarYUVLayer");
106         case NodeType::PadLayer:
107             return detail::validate_pad_layer<NEPadLayer>(*polymorphic_downcast<PadLayerNode *>(node));
108         case NodeType::PermuteLayer:
109             return detail::validate_permute_layer<NEPermute>(*polymorphic_downcast<PermuteLayerNode *>(node));
110         case NodeType::PReluLayer:
111             return detail::validate_prelu_layer<NEPReluLayer>(*polymorphic_downcast<PReluLayerNode *>(node));
112         case NodeType::PriorBoxLayer:
113             return detail::validate_priorbox_layer<NEPriorBoxLayer>(*polymorphic_downcast<PriorBoxLayerNode *>(node));
114         case NodeType::QuantizationLayer:
115             return detail::validate_quantization_layer<NEQuantizationLayer>(*polymorphic_downcast<QuantizationLayerNode *>(node));
116         case NodeType::ReductionOperationLayer:
117             return detail::validate_reduction_operation_layer<NEReductionOperation>(*polymorphic_downcast<ReductionLayerNode *>(node));
118         case NodeType::ReorgLayer:
119             return detail::validate_reorg_layer<NEReorgLayer>(*polymorphic_downcast<ReorgLayerNode *>(node));
120         case NodeType::ReshapeLayer:
121             return detail::validate_reshape_layer<NEReshapeLayer>(*polymorphic_downcast<ReshapeLayerNode *>(node));
122         case NodeType::ROIAlignLayer:
123             return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ROIAlignLayer");
124         case NodeType::SliceLayer:
125             return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : SliceLayer");
126         case NodeType::StridedSliceLayer:
127             return detail::validate_strided_slice_layer<NEStridedSlice>(*polymorphic_downcast<StridedSliceLayerNode *>(node));
128         case NodeType::UpsampleLayer:
129             return detail::validate_upsample_layer<NEUpsampleLayer>(*polymorphic_downcast<UpsampleLayerNode *>(node));
130         case NodeType::YOLOLayer:
131             return detail::validate_yolo_layer<NEYOLOLayer>(*polymorphic_downcast<YOLOLayerNode *>(node));
132         case NodeType::EltwiseLayer:
133             return detail::validate_eltwise_Layer<NEEltwiseLayerFunctions>(*polymorphic_downcast<EltwiseLayerNode *>(node));
134         case NodeType::UnaryEltwiseLayer:
135             return detail::validate_unary_eltwise_layer<NEUnaryEltwiseLayerFunctions>(*polymorphic_downcast<UnaryEltwiseLayerNode *>(node));
136         default:
137             return Status{};
138     }
139 }
140 } // namespace backends
141 } // namespace graph
142 } // namespace arm_compute
143