blob: 89dccd88b759698dce9af9b19cd9d83bd74c3d35 [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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H
25#define ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H
Georgios Pinitas28705162018-03-21 20:10:53 +000026
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010027#include "arm_compute/graph/Logger.h"
28#include "arm_compute/graph/Tensor.h"
29#include "arm_compute/graph/Types.h"
30#include "arm_compute/graph/nodes/Nodes.h"
Georgios Pinitas28705162018-03-21 20:10:53 +000031
32#include "arm_compute/core/Error.h"
Georgios Pinitascac13b12018-04-27 19:07:19 +010033#include "arm_compute/core/Helpers.h"
Georgios Pinitas28705162018-03-21 20:10:53 +000034#include "arm_compute/core/ITensorInfo.h"
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{
42namespace detail
43{
44/** Returns backing tensor info of a given tensor
45 *
46 * @param[in] tensor Tensor to extract the backing tensor from
47 *
48 * @return Backing tensor tensor info if present else nullptr
49 */
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010050inline arm_compute::ITensorInfo *get_backing_tensor_info(arm_compute::graph::Tensor *tensor)
Georgios Pinitas28705162018-03-21 20:10:53 +000051{
52 return ((tensor == nullptr) || (tensor->handle() == nullptr)) ? nullptr : tensor->handle()->tensor().info();
53}
54
thecha01e8f05da2020-08-24 17:21:41 +010055/** Validates a ArgMinMax layer node
56 *
57 * @tparam ArgMinMax layer function type
58 *
59 * @param[in] node Node to validate
60 *
61 * @return Status
62 */
63template <typename ArgMinMaxLayer>
64Status validate_arg_min_max_layer(ArgMinMaxLayerNode &node)
65{
66 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ArgMinMaxLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
67 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
68 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
69
70 // Extract IO and info
71 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
72 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
73
74 // Validate function
75 return ArgMinMaxLayer::validate(input, node.axis(), output, node.reduction_operation());
76}
77
Manuel Bottinid2048ce2018-10-23 17:00:42 +010078/** Validates a Bounding Box Transform layer node
79 *
80 * @tparam BoundingBoxTransformLayer Bounding Box Transform layer function type
81 *
82 * @param[in] node Node to validate
83 *
84 * @return Status
85 */
86template <typename BoundingBoxTransformLayer>
87Status validate_bounding_box_transform_layer(BoundingBoxTransformLayerNode &node)
88{
89 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating BoundingBoxTransformLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
90 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
91 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
92
93 // Extract IO and info
94 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
95 arm_compute::ITensorInfo *deltas = get_backing_tensor_info(node.input(1));
96 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
97 const BoundingBoxTransformInfo bbox_info = node.info();
98
99 return BoundingBoxTransformLayer::validate(input, output, deltas, bbox_info);
100}
101
Georgios Pinitas087eaf62018-05-16 15:52:35 +0100102/** Validates a Channel Shuffle layer node
103 *
104 * @tparam ChannelShuffleLayer Channel Shuffle layer function type
105 *
106 * @param[in] node Node to validate
107 *
108 * @return Status
109 */
110template <typename ChannelShuffleLayer>
111Status validate_channel_shuffle_layer(ChannelShuffleLayerNode &node)
112{
113 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ChannelShuffle node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
114 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
115 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
116
117 // Extract IO and info
118 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
119 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
120 const unsigned int num_groups = node.num_groups();
121
122 return ChannelShuffleLayer::validate(input, output, num_groups);
123}
124
Georgios Pinitas28705162018-03-21 20:10:53 +0000125/** Validates a Convolution layer node
126 *
127 * @tparam ConvolutionLayer Default Convolution layer function type
128 * @tparam DirectConvolutionLayer Direct Convolution layer function type
129 * @tparam GEMMConvolutionLayer GEMM Convolution layer function type
130 * @tparam WinogradConvolutionLayer Winograd Convolution layer function type
131 *
132 * @param[in] node Node to validate
133 *
134 * @return Status
135 */
136template <typename ConvolutionLayer, typename DirectConvolutionLayer, typename GEMMConvolutionLayer, typename WinogradConvolutionLayer>
137Status validate_convolution_layer(ConvolutionLayerNode &node)
138{
139 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
140 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
141 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
142
143 // Extract IO and info
Giorgio Arenabb54e4e2018-04-05 17:20:34 +0100144 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
145 arm_compute::ITensorInfo *weights = get_backing_tensor_info(node.input(1));
146 arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2));
147 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
148
149 if(is_data_type_quantized_asymmetric(input->data_type()))
150 {
151 biases->set_data_type(DataType::S32);
152 }
153
154 const PadStrideInfo conv_info = node.convolution_info();
155 const ConvolutionMethod conv_algorithm = node.convolution_method();
Georgios Pinitase2220552018-07-20 13:23:44 +0100156 const bool fast_math = node.fast_math_hint() == FastMathHint::Enabled;
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100157 const unsigned int num_groups = node.num_groups();
Georgios Pinitas28705162018-03-21 20:10:53 +0000158
159 // Validate function
160 Status status{};
161 switch(conv_algorithm)
162 {
Georgios Pinitase2220552018-07-20 13:23:44 +0100163 case ConvolutionMethod::Direct:
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100164 ARM_COMPUTE_RETURN_ERROR_ON_MSG(num_groups != 1, "DirectConvolutionLayer does not support grouping!");
Georgios Pinitas28705162018-03-21 20:10:53 +0000165 status = DirectConvolutionLayer::validate(input, weights, biases, output, conv_info);
166 break;
167 case ConvolutionMethod::GEMM:
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100168 status = GEMMConvolutionLayer::validate(input, weights, biases, output, conv_info,
169 WeightsInfo(), Size2D(1, 1), ActivationLayerInfo(), num_groups);
Georgios Pinitas28705162018-03-21 20:10:53 +0000170 break;
Georgios Pinitase2220552018-07-20 13:23:44 +0100171 case ConvolutionMethod::Winograd:
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100172 ARM_COMPUTE_RETURN_ERROR_ON_MSG(num_groups != 1, "WinogradConvolutionLayer does not support grouping!");
Georgios Pinitase2220552018-07-20 13:23:44 +0100173 status = WinogradConvolutionLayer::validate(input, weights, biases, output, conv_info, ActivationLayerInfo(), fast_math);
Georgios Pinitas28705162018-03-21 20:10:53 +0000174 break;
Georgios Pinitase2220552018-07-20 13:23:44 +0100175 case ConvolutionMethod::Default:
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100176 status = ConvolutionLayer::validate(input, weights, biases, output, conv_info,
177 WeightsInfo(), Size2D(1, 1), ActivationLayerInfo(), fast_math, num_groups);
Georgios Pinitas54d6fae2018-05-10 15:50:14 +0100178 break;
Georgios Pinitas28705162018-03-21 20:10:53 +0000179 default:
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100180 ARM_COMPUTE_RETURN_ERROR_MSG("Unsupported convolution method");
Georgios Pinitas28705162018-03-21 20:10:53 +0000181 }
182
183 return status;
184}
185
Sheri Zhangfb228032021-11-02 10:45:07 +0000186/** Validates a Convolution layer node
187 *
188 * @tparam GEMMConvolutionLayer GEMM Convolution layer function type
189 *
190 * @param[in] node Node to validate
191 *
192 * @return Status
193 */
194template <typename GEMMConvolutionLayer>
195Status validate_fused_convolution_with_post_op(FusedConvolutionWithPostOpNode &node)
196{
197 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating fused ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
198 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 4);
199 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
200
201 // Extract IO and info
202 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
203 arm_compute::ITensorInfo *weights = get_backing_tensor_info(node.input(1));
204 arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2));
205 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
206
207 if(is_data_type_quantized_asymmetric(input->data_type()))
208 {
209 biases->set_data_type(DataType::S32);
210 }
211
212 const PadStrideInfo conv_info = node.convolution_info();
213 //const ConvolutionMethod conv_algorithm = node.convolution_method();
214 //const bool fast_math = node.fast_math_hint() == FastMathHint::Enabled;
215 const unsigned int num_groups = node.num_groups();
216
217 // Validate function
218 return GEMMConvolutionLayer::validate(input, weights, biases, output, conv_info,
219 WeightsInfo(), Size2D(1, 1), ActivationLayerInfo(), num_groups);
220}
221
Georgios Pinitas28705162018-03-21 20:10:53 +0000222/** Validates a Depthwise Convolution layer node
223 *
224 * @tparam DepthwiseConvolutionLayer Default Depthwise Convolution layer type
Georgios Pinitas28705162018-03-21 20:10:53 +0000225 *
226 * @param[in] node Node to validate
227 *
228 * @return Status
229 */
Manuel Bottini05069f02019-09-26 17:18:26 +0100230template <typename DepthwiseConvolutionLayer>
Georgios Pinitas28705162018-03-21 20:10:53 +0000231Status validate_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node)
232{
233 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DepthwiseConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
234 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
235 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
236
237 // Extract IO and info
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100238 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
239 arm_compute::ITensorInfo *weights = detail::get_backing_tensor_info(node.input(1));
240 arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2));
241 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
Georgios Pinitas28705162018-03-21 20:10:53 +0000242
Georgios Pinitas05045c12018-12-07 18:31:47 +0000243 const PadStrideInfo conv_info = node.convolution_info();
244 const DepthwiseConvolutionMethod dwc_algorithm = node.depthwise_convolution_method();
245 const int depth_multiplier = node.depth_multiplier();
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100246
Georgios Pinitas28705162018-03-21 20:10:53 +0000247 // Validate function
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100248 Status status{};
249 switch(dwc_algorithm)
Georgios Pinitas28705162018-03-21 20:10:53 +0000250 {
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100251 case DepthwiseConvolutionMethod::Default:
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100252 case DepthwiseConvolutionMethod::Optimized3x3:
Manuel Bottini05069f02019-09-26 17:18:26 +0100253 status = DepthwiseConvolutionLayer::validate(input, weights, biases, output, conv_info, depth_multiplier);
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100254 break;
255 default:
256 ARM_COMPUTE_RETURN_ERROR_MSG("Unsupported depthwise convolution method");
Georgios Pinitas28705162018-03-21 20:10:53 +0000257 }
258
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100259 return status;
Georgios Pinitas28705162018-03-21 20:10:53 +0000260}
thecha010a05e6a2020-08-28 18:40:38 +0100261/** Validates a depth to space layer node
262 *
263 * @tparam DequantizationLayer Dequantize layer type
264 *
265 * @param[in] node Node to validate
266 *
267 * @return Status
268 */
269template <typename DepthToSpaceLayer>
270Status validate_depth_to_space_layer(DepthToSpaceLayerNode &node)
271{
272 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
273 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
274 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
275
276 // Extract IO and info
277 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
278 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
279
280 return DepthToSpaceLayer::validate(input, output, node.block_shape());
281}
Isabella Gottardicd4e9ab2019-11-05 17:50:27 +0000282/** Validates a dequantize layer node
283 *
284 * @tparam DequantizationLayer Dequantize layer type
285 *
286 * @param[in] node Node to validate
287 *
288 * @return Status
289 */
290template <typename DequantizationLayer>
291Status validate_dequantization_layer(DequantizationLayerNode &node)
292{
293 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
294 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
295 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
Isabella Gottardi0ae5de92019-03-14 10:32:11 +0000296
Isabella Gottardicd4e9ab2019-11-05 17:50:27 +0000297 // Extract IO and info
298 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
299 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
300
301 return DequantizationLayer::validate(input, output);
302}
Isabella Gottardi7234ed82018-11-27 08:51:10 +0000303/** Validates a detection output layer node
304 *
305 * @tparam DetectionOutputLayer DetectionOutput layer type
306 *
307 * @param[in] node Node to validate
308 *
309 * @return Status
310 */
311template <typename DetectionOutputLayer>
312Status validate_detection_output_layer(DetectionOutputLayerNode &node)
313{
314 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
315 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
316 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
317
318 // Extract IO and info
319 arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0));
320 arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1));
321 arm_compute::ITensorInfo *input2 = get_backing_tensor_info(node.input(2));
322 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
323 const DetectionOutputLayerInfo detect_info = node.detection_output_info();
324
325 return DetectionOutputLayer::validate(input0, input1, input2, output, detect_info);
326}
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000327/** Validates a detection post process layer node
328 *
329 * @tparam DetectionPostProcessLayer DetectionOutput layer type
330 *
331 * @param[in] node Node to validate
332 *
333 * @return Status
334 */
335template <typename DetectionPostProcessLayer>
336Status validate_detection_post_process_layer(DetectionPostProcessLayerNode &node)
337{
338 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionPostProcessLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
339 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
340 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 4);
341
342 // Extract IO and info
343 arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0));
344 arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1));
345 arm_compute::ITensorInfo *input2 = get_backing_tensor_info(node.input(2));
346 arm_compute::ITensorInfo *output0 = get_backing_tensor_info(node.output(0));
347 arm_compute::ITensorInfo *output1 = get_backing_tensor_info(node.output(1));
348 arm_compute::ITensorInfo *output2 = get_backing_tensor_info(node.output(2));
349 arm_compute::ITensorInfo *output3 = get_backing_tensor_info(node.output(3));
350 const DetectionPostProcessLayerInfo detect_info = node.detection_post_process_info();
351
352 return DetectionPostProcessLayer::validate(input0, input1, input2, output0, output1, output2, output3, detect_info);
353}
Georgios Pinitas57c48242018-08-02 13:41:49 +0100354
Manuel Bottini5209be52019-02-13 16:34:56 +0000355/** Validates a Generate Proposals layer node
356 *
357 * @tparam GenerateProposalsLayer Generate Proposals layer type
358 *
359 * @param[in] node Node to validate
360 *
361 * @return Status
362 */
363template <typename GenerateProposalsLayer>
364Status validate_generate_proposals_layer(GenerateProposalsLayerNode &node)
365{
366 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating GenerateProposalsLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
367 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
368 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 3);
369
370 // Extract IO and info
371 arm_compute::ITensorInfo *scores = detail::get_backing_tensor_info(node.input(0));
372 arm_compute::ITensorInfo *deltas = detail::get_backing_tensor_info(node.input(1));
373 arm_compute::ITensorInfo *anchors = detail::get_backing_tensor_info(node.input(2));
374 arm_compute::ITensorInfo *proposals = get_backing_tensor_info(node.output(0));
375 arm_compute::ITensorInfo *scores_out = get_backing_tensor_info(node.output(1));
376 arm_compute::ITensorInfo *num_valid_proposals = get_backing_tensor_info(node.output(2));
377 const GenerateProposalsInfo info = node.info();
378
379 return GenerateProposalsLayer::validate(scores, deltas, anchors, proposals, scores_out, num_valid_proposals, info);
380}
381
thecha013603aff2020-09-01 14:52:38 +0100382/** Validates a L2Normalization layer node
383 *
384 * @tparam L2Normalization layer type
385 *
386 * @param[in] node Node to validate
387 *
388 * @return Status
389 */
390template <typename L2NormalizeLayer>
391Status validate_l2_normalize_layer(L2NormalizeLayerNode &node)
392{
393 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating L2NormalizeLayerNode node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
394 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
395 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
396
397 // Extract IO and info
398 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
399 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
400 int axis = node.axis();
401 float epsilon = node.epsilon();
402
403 // Validate function
404 return L2NormalizeLayer::validate(input, output, axis, epsilon);
405}
406
Michele Di Giorgio555d1102018-09-12 13:51:59 +0100407/** Validates a NormalizePlanarYUV layer node
408 *
409 * @tparam NormalizePlanarYUVLayer layer type
410 *
411 * @param[in] node Node to validate
412 *
413 * @return Status
414 */
415template <typename NormalizePlanarYUVLayer>
416Status validate_normalize_planar_yuv_layer(NormalizePlanarYUVLayerNode &node)
417{
418 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating NormalizePlanarYUVLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
419 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
420 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
421
422 // Extract IO and info
423 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
424 arm_compute::ITensorInfo *mean = detail::get_backing_tensor_info(node.input(1));
425 arm_compute::ITensorInfo *std = detail::get_backing_tensor_info(node.input(2));
426 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
427
428 // Validate function
429 return NormalizePlanarYUVLayer::validate(input, output, mean, std);
430}
Michele Di Giorgio4bb17332018-09-26 13:56:51 +0100431
432/** Validates a pad layer node
433 *
434 * @tparam PadLayer Pad layer type
435 *
436 * @param[in] node Node to validate
437 *
438 * @return Status
439 */
440template <typename PadLayer>
441Status validate_pad_layer(PadLayerNode &node)
442{
443 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PadLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
444 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
445 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
446
447 // Extract IO and info
448 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
449 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
450 const PaddingList &padding = node.padding();
451
452 return PadLayer::validate(input, output, padding);
453}
454
Georgios Pinitas57c48242018-08-02 13:41:49 +0100455/** Validates a permute layer node
456 *
457 * @tparam PermuteLayer Permute layer type
458 *
459 * @param[in] node Node to validate
460 *
461 * @return Status
462 */
463template <typename PermuteLayer>
464Status validate_permute_layer(PermuteLayerNode &node)
465{
466 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PermuteLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
467 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
468 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
469
470 // Extract IO and info
471 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
472 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
473 const PermutationVector &perm = node.permutation_vector();
474
475 return PermuteLayer::validate(input, output, perm);
476}
Georgios Pinitasf8c47492020-02-04 17:39:59 +0000477
478/** Validates a PRelu layer node
479 *
480 * @tparam PReluLayer PRelu layer type
481 *
482 * @param[in] node Node to validate
483 *
484 * @return Status
485 */
486template <typename PReluLayer>
487Status validate_prelu_layer(PReluLayerNode &node)
488{
489 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PRelu node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
490 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
491 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
492
493 // Extract IO and info
494 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
495 arm_compute::ITensorInfo *alpha = get_backing_tensor_info(node.input(1));
496 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
497
498 return PReluLayer::validate(input, alpha, output);
499}
500
Pablo Tello32521432018-11-15 14:43:10 +0000501/** Validates a priorbox layer node
502 *
503 * @tparam PriorBoxLayer PriorBox layer type
504 *
505 * @param[in] node Node to validate
506 *
507 * @return Status
508 */
509template <typename PriorBoxLayer>
510Status validate_priorbox_layer(PriorBoxLayerNode &node)
511{
512 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PriorBoxLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
513 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
514 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
515
516 // Extract IO and info
517 arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0));
518 arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1));
519 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
520 const PriorBoxLayerInfo prior_info = node.priorbox_info();
521
522 return PriorBoxLayer::validate(input0, input1, output, prior_info);
523}
Gian Marco Iodice23e24792018-09-07 15:32:14 +0100524
Isabella Gottardi3db1ba92019-05-17 12:35:20 +0100525/** Validates a Quantization layer node
526 *
527 * @tparam QuantizationLayer Quantization layer type
528 *
529 * @param[in] node Node to validate
530 *
531 * @return Status
532 */
533template <typename QuantizationLayer>
534Status validate_quantization_layer(QuantizationLayerNode &node)
535{
536 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating QuantizationLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
537 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
538 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
539
540 // Extract input and output
541 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
542 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
543
544 // Validate function
545 return QuantizationLayer::validate(input, output);
546}
547
thecha01d64444b2020-09-07 14:50:21 +0100548/** Validates a Reduction operation layer node
549 *
550 * @tparam ReductionLayer Reduction layer type
551 *
552 * @param[in] node Node to validate
553 *
554 * @return Status
555 */
556template <typename ReductionLayer>
557Status validate_reduction_operation_layer(ReductionLayerNode &node)
558{
559 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReductionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
560
561 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
562 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
563
564 // Extract input and output
565 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
566 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
567
568 // Validate function
569 return ReductionLayer::validate(input, output, node.axis(), node.op(), node.keep_dims());
570}
571
Gian Marco Iodice23e24792018-09-07 15:32:14 +0100572/** Validates a Reorg layer node
573 *
574 * @tparam ReorgLayer Reorg layer type
575 *
576 * @param[in] node Node to validate
577 *
578 * @return Status
579 */
580template <typename ReorgLayer>
581Status validate_reorg_layer(ReorgLayerNode &node)
582{
583 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReorgLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
584 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
585 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
586
587 // Extract input and output
588 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
589 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
590
591 // Validate function
592 return ReorgLayer::validate(input, output, node.stride());
593}
Michalis Spyrou96f67692018-09-13 11:39:28 +0100594
Isabella Gottardi0ae5de92019-03-14 10:32:11 +0000595/** Validates a Reshape layer node
596 *
597 * @tparam ReshapeLayer Reshape layer type
598 *
599 * @param[in] node Node to validate
600 *
601 * @return Status
602 */
603template <typename ReshapeLayer>
604Status validate_reshape_layer(ReshapeLayerNode &node)
605{
606 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReshapeLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
607 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
608 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
609
610 // Extract input and output
611 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
612 arm_compute::ITensorInfo *output = detail::get_backing_tensor_info(node.output(0));
613
614 // Validate function
615 return ReshapeLayer::validate(input, output);
616}
617
Manuel Bottini3f9d4d72018-10-19 14:04:42 +0100618/** Validates a ROI Align layer node
619 *
620 * @tparam ROIAlignLayer ROIAlign layer type
621 *
622 * @param[in] node Node to validate
623 *
624 * @return Status
625 */
626template <typename ROIAlignLayer>
627Status validate_roi_align_layer(ROIAlignLayerNode &node)
628{
629 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ROIAlignLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
630 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
631 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
632
633 // Extract input and output
634 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
635 arm_compute::ITensorInfo *rois = detail::get_backing_tensor_info(node.input(1));
636 arm_compute::ITensorInfo *output = detail::get_backing_tensor_info(node.output(0));
637 const ROIPoolingLayerInfo &pool_info = node.pooling_info();
638
639 // Validate function
640 return ROIAlignLayer::validate(input, rois, output, pool_info);
641}
642
Michele Di Giorgioc30b6682018-09-12 17:44:08 +0100643/** Validates a Slice layer node
644 *
645 * @tparam SliceLayer Slice layer function type
646 *
647 * @param[in] node Node to validate
648 *
649 * @return Status
650 */
651template <typename SliceLayer>
652Status validate_slice_layer(SliceLayerNode &node)
653{
654 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating Slice node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
655 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
656 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
657
658 // Extract IO and info
659 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
660 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
661 const Coordinates starts = node.starts();
662 const Coordinates ends = node.ends();
663
664 return SliceLayer::validate(input, output, starts, ends);
665}
666
thecha012bfadd92020-08-12 17:25:51 +0100667/** Validates a Strided Slice layer node
668 *
669 * @tparam StridedSliceLayer Strided Slice layer function type
670 *
671 * @param[in] node Node to validate
672 *
673 * @return Status
674 */
675template <typename StridedSliceLayer>
676Status validate_strided_slice_layer(StridedSliceLayerNode &node)
677{
678 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating StridedSlice node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
679 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
680 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
681
682 // Extract IO and info
683 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
684 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
685 const Coordinates starts = node.starts();
686 const Coordinates ends = node.ends();
687 const BiStrides strides = node.strides();
688 const StridedSliceLayerInfo info = node.strided_slice_info();
689
690 return StridedSliceLayer::validate(input, output, starts, ends, strides, info.begin_mask(), info.end_mask(), info.shrink_axis_mask());
691}
692
Sheri Zhang16dddd22020-05-27 15:03:48 +0100693/** Validates a element-wise layer node
694 *
695 * @param[in] node Node to validate
696 *
697 * @return Status
698 */
699template <typename EltwiseLayerFunctions>
700Status validate_eltwise_Layer(EltwiseLayerNode &node)
701{
702 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
703 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
704 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
705
706 // Extract input and output
707 const arm_compute::ITensorInfo *input1 = detail::get_backing_tensor_info(node.input(0));
708 const arm_compute::ITensorInfo *input2 = detail::get_backing_tensor_info(node.input(1));
709 const arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
710 const EltwiseOperation eltwise_op = node.eltwise_operation();
711 const ConvertPolicy convert_policy = node.convert_policy();
712 const RoundingPolicy round_policy = node.rounding_policy();
713 const ActivationLayerInfo act_info = node.fused_activation();
714 const QuantizationInfo quant_info = node.output_quant_info();
Sheri Zhang16dddd22020-05-27 15:03:48 +0100715
716 // Validate function
717 if(eltwise_op == EltwiseOperation::Add)
718 {
719 return EltwiseLayerFunctions::ArithmeticAddition::validate(input1, input2, output, convert_policy, act_info);
720 }
721 else if(eltwise_op == EltwiseOperation::Sub)
722 {
723 return EltwiseLayerFunctions::ArithmeticSubtraction::validate(input1, input2, output, convert_policy, act_info);
724 }
725 else if(eltwise_op == EltwiseOperation::Mul)
726 {
Manuel Bottini7e725cf2020-08-12 16:05:16 +0100727 return EltwiseLayerFunctions::PixelWiseMultiplication::validate(input1, input2, output, 1.0f, convert_policy, round_policy, act_info);
Sheri Zhang16dddd22020-05-27 15:03:48 +0100728 }
thecha01f8e35842020-07-28 17:28:17 +0100729 else if(eltwise_op == EltwiseOperation::Max)
730 {
731 return EltwiseLayerFunctions::ElementwiseMax::validate(input1, input2, output, act_info);
732 }
Alessandro Navone6413e492021-02-02 11:39:05 +0000733 else if(eltwise_op == EltwiseOperation::Div)
734 {
735 return EltwiseLayerFunctions::ArithmeticDivision::validate(input1, input2, output, act_info);
736 }
Sheri Zhang16dddd22020-05-27 15:03:48 +0100737 else
738 {
739 ARM_COMPUTE_ERROR("Unsupported element-wise operation!");
740 }
741 return Status{};
742}
743/** Validates a unary element-wise layer node
744 *
745 * @param[in] node Node to validate
746 *
747 * @return Status
748 */
749template <typename UnaryEltwiseLayerFunctions>
750Status validate_unary_eltwise_layer(UnaryEltwiseLayerNode &node)
751{
752 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
753 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
754 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
755
756 // Extract input and output
757 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
758 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
759 const UnaryEltwiseOperation eltwise_op = node.eltwise_descriptor().op;
760
761 // Validate function
762 if(eltwise_op == UnaryEltwiseOperation::Exp)
763 {
764 return UnaryEltwiseLayerFunctions::ExpLayer::validate(input, output);
765 }
766 else
767 {
768 ARM_COMPUTE_ERROR("Unsupported unary element-wise operation!");
769 }
770
771 return Status{};
772}
Georgios Pinitas28705162018-03-21 20:10:53 +0000773} // namespace detail
774} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100775} // namespace graph
Georgios Pinitas28705162018-03-21 20:10:53 +0000776} // namespace arm_compute
777
Michalis Spyrouf4643372019-11-29 16:17:13 +0000778#endif /* ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H */