blob: c50782db48bed4decd0b8a825c05474cc9ebb007 [file] [log] [blame]
Georgios Pinitas28705162018-03-21 20:10:53 +00001/*
Alessandro Navone6413e492021-02-02 11:39:05 +00002 * Copyright (c) 2018-2021 Arm Limited.
Georgios Pinitas28705162018-03-21 20:10:53 +00003 *
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 Pinitasd9eb2752018-04-03 13:44:29 +010024#include "arm_compute/graph/backends/CL/CLNodeValidator.h"
Georgios Pinitas28705162018-03-21 20:10:53 +000025
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010026#include "arm_compute/graph/backends/ValidateHelpers.h"
27#include "arm_compute/graph/nodes/Nodes.h"
Georgios Pinitas28705162018-03-21 20:10:53 +000028
Georgios Pinitas28705162018-03-21 20:10:53 +000029#include "arm_compute/runtime/CL/CLFunctions.h"
Isabella Gottardi7234ed82018-11-27 08:51:10 +000030#include "arm_compute/runtime/CPP/CPPFunctions.h"
Georgios Pinitas11d84152021-04-28 10:20:18 +010031
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010032#include "support/Cast.h"
Georgios Pinitas28705162018-03-21 20:10:53 +000033
34using namespace arm_compute::utils::cast;
35
36namespace arm_compute
37{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010038namespace graph
Georgios Pinitas28705162018-03-21 20:10:53 +000039{
40namespace backends
41{
Sheri Zhang16dddd22020-05-27 15:03:48 +010042/** Collection of CL element-wise functions */
43struct CLEltwiseLayerFunctions
44{
45 using ArithmeticAddition = CLArithmeticAddition;
46 using ArithmeticSubtraction = CLArithmeticSubtraction;
47 using PixelWiseMultiplication = CLPixelWiseMultiplication;
thecha01f8e35842020-07-28 17:28:17 +010048 using ElementwiseMax = CLElementwiseMax;
Alessandro Navone6413e492021-02-02 11:39:05 +000049 using ArithmeticDivision = CLArithmeticDivision;
Sheri Zhang16dddd22020-05-27 15:03:48 +010050};
51
52/** Collection of CL unary element-wise functions */
53struct CLUnaryEltwiseLayerFunctions
54{
55 using ExpLayer = CLExpLayer;
56};
57
Georgios Pinitas28705162018-03-21 20:10:53 +000058Status CLNodeValidator::validate(INode *node)
59{
60 if(node == nullptr)
61 {
62 return Status{};
63 }
64
65 NodeType type = node->type();
66 switch(type)
67 {
thecha01e8f05da2020-08-24 17:21:41 +010068 case NodeType::ArgMinMaxLayer:
69 return detail::validate_arg_min_max_layer<CLArgMinMaxLayer>(*polymorphic_downcast<ArgMinMaxLayerNode *>(node));
Manuel Bottinid2048ce2018-10-23 17:00:42 +010070 case NodeType::BoundingBoxTransformLayer:
71 return detail::validate_bounding_box_transform_layer<CLBoundingBoxTransform>(*polymorphic_downcast<BoundingBoxTransformLayerNode *>(node));
Georgios Pinitas087eaf62018-05-16 15:52:35 +010072 case NodeType::ChannelShuffleLayer:
73 return detail::validate_channel_shuffle_layer<CLChannelShuffleLayer>(*polymorphic_downcast<ChannelShuffleLayerNode *>(node));
Georgios Pinitas28705162018-03-21 20:10:53 +000074 case NodeType::ConvolutionLayer:
75 return detail::validate_convolution_layer<CLConvolutionLayer,
76 CLDirectConvolutionLayer,
77 CLGEMMConvolutionLayer,
78 CLWinogradConvolutionLayer>(*polymorphic_downcast<ConvolutionLayerNode *>(node));
Sheri Zhangfb228032021-11-02 10:45:07 +000079 case NodeType::FusedConvolutionWithPostOp:
80 return detail::validate_fused_convolution_with_post_op<CLGEMMConvolutionLayer>(*polymorphic_downcast<FusedConvolutionWithPostOpNode *>(node));
thecha010a05e6a2020-08-28 18:40:38 +010081 case NodeType::DepthToSpaceLayer:
82 return detail::validate_depth_to_space_layer<CLDepthToSpaceLayer>(*polymorphic_downcast<DepthToSpaceLayerNode *>(node));
Georgios Pinitas28705162018-03-21 20:10:53 +000083 case NodeType::DepthwiseConvolutionLayer:
Manuel Bottini05069f02019-09-26 17:18:26 +010084 return detail::validate_depthwise_convolution_layer<CLDepthwiseConvolutionLayer>(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
Isabella Gottardicd4e9ab2019-11-05 17:50:27 +000085 case NodeType::DequantizationLayer:
86 return detail::validate_dequantization_layer<CLDequantizationLayer>(*polymorphic_downcast<DequantizationLayerNode *>(node));
Isabella Gottardi7234ed82018-11-27 08:51:10 +000087 case NodeType::DetectionOutputLayer:
88 return detail::validate_detection_output_layer<CPPDetectionOutputLayer>(*polymorphic_downcast<DetectionOutputLayerNode *>(node));
Isabella Gottardia7acb3c2019-01-08 13:48:44 +000089 case NodeType::DetectionPostProcessLayer:
90 return detail::validate_detection_post_process_layer<CPPDetectionPostProcessLayer>(*polymorphic_downcast<DetectionPostProcessLayerNode *>(node));
Manuel Bottini5209be52019-02-13 16:34:56 +000091 case NodeType::GenerateProposalsLayer:
92 return detail::validate_generate_proposals_layer<CLGenerateProposalsLayer>(*polymorphic_downcast<GenerateProposalsLayerNode *>(node));
thecha013603aff2020-09-01 14:52:38 +010093 case NodeType::L2NormalizeLayer:
94 return detail::validate_l2_normalize_layer<CLL2NormalizeLayer>(*polymorphic_downcast<L2NormalizeLayerNode *>(node));
Michele Di Giorgio555d1102018-09-12 13:51:59 +010095 case NodeType::NormalizePlanarYUVLayer:
96 return detail::validate_normalize_planar_yuv_layer<CLNormalizePlanarYUVLayer>(*polymorphic_downcast<NormalizePlanarYUVLayerNode *>(node));
Michele Di Giorgio4bb17332018-09-26 13:56:51 +010097 case NodeType::PadLayer:
98 return detail::validate_pad_layer<CLPadLayer>(*polymorphic_downcast<PadLayerNode *>(node));
Georgios Pinitas57c48242018-08-02 13:41:49 +010099 case NodeType::PermuteLayer:
100 return detail::validate_permute_layer<CLPermute>(*polymorphic_downcast<PermuteLayerNode *>(node));
Georgios Pinitasf8c47492020-02-04 17:39:59 +0000101 case NodeType::PReluLayer:
102 return detail::validate_prelu_layer<CLPReluLayer>(*polymorphic_downcast<PReluLayerNode *>(node));
Pablo Tello32521432018-11-15 14:43:10 +0000103 case NodeType::PriorBoxLayer:
104 return detail::validate_priorbox_layer<CLPriorBoxLayer>(*polymorphic_downcast<PriorBoxLayerNode *>(node));
Isabella Gottardi3db1ba92019-05-17 12:35:20 +0100105 case NodeType::QuantizationLayer:
106 return detail::validate_quantization_layer<CLQuantizationLayer>(*polymorphic_downcast<QuantizationLayerNode *>(node));
thecha01d64444b2020-09-07 14:50:21 +0100107 case NodeType::ReductionOperationLayer:
108 return detail::validate_reduction_operation_layer<CLReductionOperation>(*polymorphic_downcast<ReductionLayerNode *>(node));
Gian Marco Iodice23e24792018-09-07 15:32:14 +0100109 case NodeType::ReorgLayer:
110 return detail::validate_reorg_layer<CLReorgLayer>(*polymorphic_downcast<ReorgLayerNode *>(node));
Isabella Gottardi0ae5de92019-03-14 10:32:11 +0000111 case NodeType::ReshapeLayer:
112 return detail::validate_reshape_layer<CLReshapeLayer>(*polymorphic_downcast<ReshapeLayerNode *>(node));
Manuel Bottini3f9d4d72018-10-19 14:04:42 +0100113 case NodeType::ROIAlignLayer:
114 return detail::validate_roi_align_layer<CLROIAlignLayer>(*polymorphic_downcast<ROIAlignLayerNode *>(node));
Michele Di Giorgioc30b6682018-09-12 17:44:08 +0100115 case NodeType::SliceLayer:
116 return detail::validate_slice_layer<CLSlice>(*polymorphic_downcast<SliceLayerNode *>(node));
thecha012bfadd92020-08-12 17:25:51 +0100117 case NodeType::StridedSliceLayer:
118 return detail::validate_strided_slice_layer<CLStridedSlice>(*polymorphic_downcast<StridedSliceLayerNode *>(node));
Sheri Zhang16dddd22020-05-27 15:03:48 +0100119 case NodeType::EltwiseLayer:
120 return detail::validate_eltwise_Layer<CLEltwiseLayerFunctions>(*polymorphic_downcast<EltwiseLayerNode *>(node));
121 case NodeType::UnaryEltwiseLayer:
122 return detail::validate_unary_eltwise_layer<CLUnaryEltwiseLayerFunctions>(*polymorphic_downcast<UnaryEltwiseLayerNode *>(node));
Georgios Pinitas28705162018-03-21 20:10:53 +0000123 default:
124 return Status{};
125 }
126}
127} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100128} // namespace graph
Michele Di Giorgio555d1102018-09-12 13:51:59 +0100129} // namespace arm_compute