Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 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 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 24 | #include "arm_compute/graph/backends/NEON/NENodeValidator.h" |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 25 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 26 | #include "arm_compute/graph/backends/ValidateHelpers.h" |
| 27 | #include "arm_compute/graph/nodes/Nodes.h" |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 28 | |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 29 | #include "arm_compute/runtime/CPP/CPPFunctions.h" |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 30 | #include "arm_compute/runtime/NEON/NEFunctions.h" |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 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" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 44 | #include "support/Cast.h" |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 45 | |
| 46 | using namespace arm_compute::utils::cast; |
| 47 | |
| 48 | namespace arm_compute |
| 49 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 50 | namespace graph |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 51 | { |
| 52 | namespace backends |
| 53 | { |
Sheri Zhang | 16dddd2 | 2020-05-27 15:03:48 +0100 | [diff] [blame] | 54 | /** Collection of NEON element-wise functions */ |
| 55 | struct NEEltwiseLayerFunctions |
| 56 | { |
| 57 | using ArithmeticAddition = NEArithmeticAddition; |
| 58 | using ArithmeticSubtraction = NEArithmeticSubtraction; |
| 59 | using PixelWiseMultiplication = NEPixelWiseMultiplication; |
thecha01 | f8e3584 | 2020-07-28 17:28:17 +0100 | [diff] [blame] | 60 | using ElementwiseMax = NEElementwiseMax; |
Sheri Zhang | 16dddd2 | 2020-05-27 15:03:48 +0100 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | /** Collection of NEON unary element-wise functions */ |
| 64 | struct NEUnaryEltwiseLayerFunctions |
| 65 | { |
| 66 | using ExpLayer = NEExpLayer; |
| 67 | }; |
| 68 | |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 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 | { |
thecha01 | e8f05da | 2020-08-24 17:21:41 +0100 | [diff] [blame] | 79 | case NodeType::ArgMinMaxLayer: |
| 80 | return detail::validate_arg_min_max_layer<NEArgMinMaxLayer>(*polymorphic_downcast<ArgMinMaxLayerNode *>(node)); |
Manuel Bottini | d2048ce | 2018-10-23 17:00:42 +0100 | [diff] [blame] | 81 | case NodeType::BoundingBoxTransformLayer: |
| 82 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : BoundingBoxTransformLayer"); |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 83 | case NodeType::ChannelShuffleLayer: |
Georgios Pinitas | f1adf11 | 2018-11-02 12:54:18 +0000 | [diff] [blame] | 84 | return detail::validate_channel_shuffle_layer<NEChannelShuffleLayer>(*polymorphic_downcast<ChannelShuffleLayerNode *>(node)); |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 85 | case NodeType::ConvolutionLayer: |
| 86 | return detail::validate_convolution_layer<NEConvolutionLayer, |
| 87 | NEDirectConvolutionLayer, |
| 88 | NEGEMMConvolutionLayer, |
Georgios Pinitas | 9fb1159 | 2018-04-26 20:34:58 +0100 | [diff] [blame] | 89 | NEWinogradConvolutionLayer>(*polymorphic_downcast<ConvolutionLayerNode *>(node)); |
thecha01 | 0a05e6a | 2020-08-28 18:40:38 +0100 | [diff] [blame] | 90 | case NodeType::DepthToSpaceLayer: |
| 91 | return detail::validate_depth_to_space_layer<NEDepthToSpaceLayer>(*polymorphic_downcast<DepthToSpaceLayerNode *>(node)); |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 92 | case NodeType::DepthwiseConvolutionLayer: |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 93 | return detail::validate_depthwise_convolution_layer<NEDepthwiseConvolutionLayer>(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node)); |
Isabella Gottardi | cd4e9ab | 2019-11-05 17:50:27 +0000 | [diff] [blame] | 94 | case NodeType::DequantizationLayer: |
| 95 | return detail::validate_dequantization_layer<NEDequantizationLayer>(*polymorphic_downcast<DequantizationLayerNode *>(node)); |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 96 | case NodeType::DetectionOutputLayer: |
| 97 | return detail::validate_detection_output_layer<CPPDetectionOutputLayer>(*polymorphic_downcast<DetectionOutputLayerNode *>(node)); |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 98 | case NodeType::DetectionPostProcessLayer: |
Giuseppe Rossini | d985378 | 2019-10-25 11:11:44 +0100 | [diff] [blame] | 99 | return detail::validate_detection_post_process_layer<NEDetectionPostProcessLayer>(*polymorphic_downcast<DetectionPostProcessLayerNode *>(node)); |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 100 | case NodeType::GenerateProposalsLayer: |
| 101 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : GenerateProposalsLayer"); |
thecha01 | 3603aff | 2020-09-01 14:52:38 +0100 | [diff] [blame] | 102 | case NodeType::L2NormalizeLayer: |
| 103 | return detail::validate_l2_normalize_layer<NEL2NormalizeLayer>(*polymorphic_downcast<L2NormalizeLayerNode *>(node)); |
Michele Di Giorgio | c30b668 | 2018-09-12 17:44:08 +0100 | [diff] [blame] | 104 | case NodeType::NormalizePlanarYUVLayer: |
| 105 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : NormalizePlanarYUVLayer"); |
Michele Di Giorgio | 4bb1733 | 2018-09-26 13:56:51 +0100 | [diff] [blame] | 106 | case NodeType::PadLayer: |
Georgios Pinitas | 07fbe37 | 2020-02-04 13:21:02 +0000 | [diff] [blame] | 107 | return detail::validate_pad_layer<NEPadLayer>(*polymorphic_downcast<PadLayerNode *>(node)); |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 108 | case NodeType::PermuteLayer: |
| 109 | return detail::validate_permute_layer<NEPermute>(*polymorphic_downcast<PermuteLayerNode *>(node)); |
Georgios Pinitas | f8c4749 | 2020-02-04 17:39:59 +0000 | [diff] [blame] | 110 | case NodeType::PReluLayer: |
| 111 | return detail::validate_prelu_layer<NEPReluLayer>(*polymorphic_downcast<PReluLayerNode *>(node)); |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 112 | case NodeType::PriorBoxLayer: |
| 113 | return detail::validate_priorbox_layer<NEPriorBoxLayer>(*polymorphic_downcast<PriorBoxLayerNode *>(node)); |
Isabella Gottardi | 3db1ba9 | 2019-05-17 12:35:20 +0100 | [diff] [blame] | 114 | case NodeType::QuantizationLayer: |
| 115 | return detail::validate_quantization_layer<NEQuantizationLayer>(*polymorphic_downcast<QuantizationLayerNode *>(node)); |
thecha01 | d64444b | 2020-09-07 14:50:21 +0100 | [diff] [blame] | 116 | case NodeType::ReductionOperationLayer: |
| 117 | return detail::validate_reduction_operation_layer<NEReductionOperation>(*polymorphic_downcast<ReductionLayerNode *>(node)); |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 118 | case NodeType::ReorgLayer: |
| 119 | return detail::validate_reorg_layer<NEReorgLayer>(*polymorphic_downcast<ReorgLayerNode *>(node)); |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 120 | case NodeType::ReshapeLayer: |
| 121 | return detail::validate_reshape_layer<NEReshapeLayer>(*polymorphic_downcast<ReshapeLayerNode *>(node)); |
Manuel Bottini | 3f9d4d7 | 2018-10-19 14:04:42 +0100 | [diff] [blame] | 122 | case NodeType::ROIAlignLayer: |
| 123 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ROIAlignLayer"); |
Michele Di Giorgio | c30b668 | 2018-09-12 17:44:08 +0100 | [diff] [blame] | 124 | case NodeType::SliceLayer: |
| 125 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : SliceLayer"); |
thecha01 | 2bfadd9 | 2020-08-12 17:25:51 +0100 | [diff] [blame] | 126 | case NodeType::StridedSliceLayer: |
| 127 | return detail::validate_strided_slice_layer<NEStridedSlice>(*polymorphic_downcast<StridedSliceLayerNode *>(node)); |
Michalis Spyrou | 4e1c3f3 | 2018-09-20 17:14:03 +0100 | [diff] [blame] | 128 | case NodeType::UpsampleLayer: |
Michalis Spyrou | 7c9541c | 2018-09-20 17:40:04 +0100 | [diff] [blame] | 129 | return detail::validate_upsample_layer<NEUpsampleLayer>(*polymorphic_downcast<UpsampleLayerNode *>(node)); |
Michalis Spyrou | 96f6769 | 2018-09-13 11:39:28 +0100 | [diff] [blame] | 130 | case NodeType::YOLOLayer: |
Michalis Spyrou | e22aa13 | 2018-09-13 10:35:33 +0100 | [diff] [blame] | 131 | return detail::validate_yolo_layer<NEYOLOLayer>(*polymorphic_downcast<YOLOLayerNode *>(node)); |
Sheri Zhang | 16dddd2 | 2020-05-27 15:03:48 +0100 | [diff] [blame] | 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)); |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 136 | default: |
| 137 | return Status{}; |
| 138 | } |
| 139 | } |
| 140 | } // namespace backends |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 141 | } // namespace graph |
Michele Di Giorgio | c30b668 | 2018-09-12 17:44:08 +0100 | [diff] [blame] | 142 | } // namespace arm_compute |