blob: 23f6cc5627888fc8bf8fe5325cd8ec1e07a85d73 [file] [log] [blame]
Georgios Pinitas28705162018-03-21 20:10:53 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 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
186/** Validates a Depthwise Convolution layer node
187 *
188 * @tparam DepthwiseConvolutionLayer Default Depthwise Convolution layer type
Georgios Pinitas28705162018-03-21 20:10:53 +0000189 *
190 * @param[in] node Node to validate
191 *
192 * @return Status
193 */
Manuel Bottini05069f02019-09-26 17:18:26 +0100194template <typename DepthwiseConvolutionLayer>
Georgios Pinitas28705162018-03-21 20:10:53 +0000195Status validate_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node)
196{
197 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DepthwiseConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
198 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
199 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
200
201 // Extract IO and info
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100202 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
203 arm_compute::ITensorInfo *weights = detail::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));
Georgios Pinitas28705162018-03-21 20:10:53 +0000206
Georgios Pinitas05045c12018-12-07 18:31:47 +0000207 const PadStrideInfo conv_info = node.convolution_info();
208 const DepthwiseConvolutionMethod dwc_algorithm = node.depthwise_convolution_method();
209 const int depth_multiplier = node.depth_multiplier();
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100210
Georgios Pinitas28705162018-03-21 20:10:53 +0000211 // Validate function
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100212 Status status{};
213 switch(dwc_algorithm)
Georgios Pinitas28705162018-03-21 20:10:53 +0000214 {
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100215 case DepthwiseConvolutionMethod::Default:
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100216 case DepthwiseConvolutionMethod::Optimized3x3:
Manuel Bottini05069f02019-09-26 17:18:26 +0100217 status = DepthwiseConvolutionLayer::validate(input, weights, biases, output, conv_info, depth_multiplier);
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100218 break;
219 default:
220 ARM_COMPUTE_RETURN_ERROR_MSG("Unsupported depthwise convolution method");
Georgios Pinitas28705162018-03-21 20:10:53 +0000221 }
222
Georgios Pinitas2a2db592018-08-15 12:14:46 +0100223 return status;
Georgios Pinitas28705162018-03-21 20:10:53 +0000224}
thecha010a05e6a2020-08-28 18:40:38 +0100225/** Validates a depth to space layer node
226 *
227 * @tparam DequantizationLayer Dequantize layer type
228 *
229 * @param[in] node Node to validate
230 *
231 * @return Status
232 */
233template <typename DepthToSpaceLayer>
234Status validate_depth_to_space_layer(DepthToSpaceLayerNode &node)
235{
236 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
237 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
238 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
239
240 // Extract IO and info
241 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
242 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
243
244 return DepthToSpaceLayer::validate(input, output, node.block_shape());
245}
Isabella Gottardicd4e9ab2019-11-05 17:50:27 +0000246/** Validates a dequantize layer node
247 *
248 * @tparam DequantizationLayer Dequantize layer type
249 *
250 * @param[in] node Node to validate
251 *
252 * @return Status
253 */
254template <typename DequantizationLayer>
255Status validate_dequantization_layer(DequantizationLayerNode &node)
256{
257 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
258 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
259 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
Isabella Gottardi0ae5de92019-03-14 10:32:11 +0000260
Isabella Gottardicd4e9ab2019-11-05 17:50:27 +0000261 // Extract IO and info
262 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
263 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
264
265 return DequantizationLayer::validate(input, output);
266}
Isabella Gottardi7234ed82018-11-27 08:51:10 +0000267/** Validates a detection output layer node
268 *
269 * @tparam DetectionOutputLayer DetectionOutput layer type
270 *
271 * @param[in] node Node to validate
272 *
273 * @return Status
274 */
275template <typename DetectionOutputLayer>
276Status validate_detection_output_layer(DetectionOutputLayerNode &node)
277{
278 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
279 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
280 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
281
282 // Extract IO and info
283 arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0));
284 arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1));
285 arm_compute::ITensorInfo *input2 = get_backing_tensor_info(node.input(2));
286 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
287 const DetectionOutputLayerInfo detect_info = node.detection_output_info();
288
289 return DetectionOutputLayer::validate(input0, input1, input2, output, detect_info);
290}
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000291/** Validates a detection post process layer node
292 *
293 * @tparam DetectionPostProcessLayer DetectionOutput layer type
294 *
295 * @param[in] node Node to validate
296 *
297 * @return Status
298 */
299template <typename DetectionPostProcessLayer>
300Status validate_detection_post_process_layer(DetectionPostProcessLayerNode &node)
301{
302 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionPostProcessLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
303 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
304 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 4);
305
306 // Extract IO and info
307 arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0));
308 arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1));
309 arm_compute::ITensorInfo *input2 = get_backing_tensor_info(node.input(2));
310 arm_compute::ITensorInfo *output0 = get_backing_tensor_info(node.output(0));
311 arm_compute::ITensorInfo *output1 = get_backing_tensor_info(node.output(1));
312 arm_compute::ITensorInfo *output2 = get_backing_tensor_info(node.output(2));
313 arm_compute::ITensorInfo *output3 = get_backing_tensor_info(node.output(3));
314 const DetectionPostProcessLayerInfo detect_info = node.detection_post_process_info();
315
316 return DetectionPostProcessLayer::validate(input0, input1, input2, output0, output1, output2, output3, detect_info);
317}
Georgios Pinitas57c48242018-08-02 13:41:49 +0100318
Manuel Bottini5209be52019-02-13 16:34:56 +0000319/** Validates a Generate Proposals layer node
320 *
321 * @tparam GenerateProposalsLayer Generate Proposals layer type
322 *
323 * @param[in] node Node to validate
324 *
325 * @return Status
326 */
327template <typename GenerateProposalsLayer>
328Status validate_generate_proposals_layer(GenerateProposalsLayerNode &node)
329{
330 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating GenerateProposalsLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
331 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
332 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 3);
333
334 // Extract IO and info
335 arm_compute::ITensorInfo *scores = detail::get_backing_tensor_info(node.input(0));
336 arm_compute::ITensorInfo *deltas = detail::get_backing_tensor_info(node.input(1));
337 arm_compute::ITensorInfo *anchors = detail::get_backing_tensor_info(node.input(2));
338 arm_compute::ITensorInfo *proposals = get_backing_tensor_info(node.output(0));
339 arm_compute::ITensorInfo *scores_out = get_backing_tensor_info(node.output(1));
340 arm_compute::ITensorInfo *num_valid_proposals = get_backing_tensor_info(node.output(2));
341 const GenerateProposalsInfo info = node.info();
342
343 return GenerateProposalsLayer::validate(scores, deltas, anchors, proposals, scores_out, num_valid_proposals, info);
344}
345
Michele Di Giorgio555d1102018-09-12 13:51:59 +0100346/** Validates a NormalizePlanarYUV layer node
347 *
348 * @tparam NormalizePlanarYUVLayer layer type
349 *
350 * @param[in] node Node to validate
351 *
352 * @return Status
353 */
354template <typename NormalizePlanarYUVLayer>
355Status validate_normalize_planar_yuv_layer(NormalizePlanarYUVLayerNode &node)
356{
357 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating NormalizePlanarYUVLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
358 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
359 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
360
361 // Extract IO and info
362 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
363 arm_compute::ITensorInfo *mean = detail::get_backing_tensor_info(node.input(1));
364 arm_compute::ITensorInfo *std = detail::get_backing_tensor_info(node.input(2));
365 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
366
367 // Validate function
368 return NormalizePlanarYUVLayer::validate(input, output, mean, std);
369}
Michele Di Giorgio4bb17332018-09-26 13:56:51 +0100370
371/** Validates a pad layer node
372 *
373 * @tparam PadLayer Pad layer type
374 *
375 * @param[in] node Node to validate
376 *
377 * @return Status
378 */
379template <typename PadLayer>
380Status validate_pad_layer(PadLayerNode &node)
381{
382 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PadLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
383 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
384 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
385
386 // Extract IO and info
387 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
388 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
389 const PaddingList &padding = node.padding();
390
391 return PadLayer::validate(input, output, padding);
392}
393
Georgios Pinitas57c48242018-08-02 13:41:49 +0100394/** Validates a permute layer node
395 *
396 * @tparam PermuteLayer Permute layer type
397 *
398 * @param[in] node Node to validate
399 *
400 * @return Status
401 */
402template <typename PermuteLayer>
403Status validate_permute_layer(PermuteLayerNode &node)
404{
405 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PermuteLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
406 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
407 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
408
409 // Extract IO and info
410 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
411 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
412 const PermutationVector &perm = node.permutation_vector();
413
414 return PermuteLayer::validate(input, output, perm);
415}
Georgios Pinitasf8c47492020-02-04 17:39:59 +0000416
417/** Validates a PRelu layer node
418 *
419 * @tparam PReluLayer PRelu layer type
420 *
421 * @param[in] node Node to validate
422 *
423 * @return Status
424 */
425template <typename PReluLayer>
426Status validate_prelu_layer(PReluLayerNode &node)
427{
428 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PRelu node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
429 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
430 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
431
432 // Extract IO and info
433 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
434 arm_compute::ITensorInfo *alpha = get_backing_tensor_info(node.input(1));
435 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
436
437 return PReluLayer::validate(input, alpha, output);
438}
439
Pablo Tello32521432018-11-15 14:43:10 +0000440/** Validates a priorbox layer node
441 *
442 * @tparam PriorBoxLayer PriorBox layer type
443 *
444 * @param[in] node Node to validate
445 *
446 * @return Status
447 */
448template <typename PriorBoxLayer>
449Status validate_priorbox_layer(PriorBoxLayerNode &node)
450{
451 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PriorBoxLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
452 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
453 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
454
455 // Extract IO and info
456 arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0));
457 arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1));
458 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
459 const PriorBoxLayerInfo prior_info = node.priorbox_info();
460
461 return PriorBoxLayer::validate(input0, input1, output, prior_info);
462}
Gian Marco Iodice23e24792018-09-07 15:32:14 +0100463
Isabella Gottardi3db1ba92019-05-17 12:35:20 +0100464/** Validates a Quantization layer node
465 *
466 * @tparam QuantizationLayer Quantization layer type
467 *
468 * @param[in] node Node to validate
469 *
470 * @return Status
471 */
472template <typename QuantizationLayer>
473Status validate_quantization_layer(QuantizationLayerNode &node)
474{
475 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating QuantizationLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
476 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
477 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
478
479 // Extract input and output
480 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
481 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
482
483 // Validate function
484 return QuantizationLayer::validate(input, output);
485}
486
Gian Marco Iodice23e24792018-09-07 15:32:14 +0100487/** Validates a Reorg layer node
488 *
489 * @tparam ReorgLayer Reorg layer type
490 *
491 * @param[in] node Node to validate
492 *
493 * @return Status
494 */
495template <typename ReorgLayer>
496Status validate_reorg_layer(ReorgLayerNode &node)
497{
498 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReorgLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
499 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
500 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
501
502 // Extract input and output
503 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
504 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
505
506 // Validate function
507 return ReorgLayer::validate(input, output, node.stride());
508}
Michalis Spyrou96f67692018-09-13 11:39:28 +0100509
Isabella Gottardi0ae5de92019-03-14 10:32:11 +0000510/** Validates a Reshape layer node
511 *
512 * @tparam ReshapeLayer Reshape layer type
513 *
514 * @param[in] node Node to validate
515 *
516 * @return Status
517 */
518template <typename ReshapeLayer>
519Status validate_reshape_layer(ReshapeLayerNode &node)
520{
521 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReshapeLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
522 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
523 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
524
525 // Extract input and output
526 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
527 arm_compute::ITensorInfo *output = detail::get_backing_tensor_info(node.output(0));
528
529 // Validate function
530 return ReshapeLayer::validate(input, output);
531}
532
Manuel Bottini3f9d4d72018-10-19 14:04:42 +0100533/** Validates a ROI Align layer node
534 *
535 * @tparam ROIAlignLayer ROIAlign layer type
536 *
537 * @param[in] node Node to validate
538 *
539 * @return Status
540 */
541template <typename ROIAlignLayer>
542Status validate_roi_align_layer(ROIAlignLayerNode &node)
543{
544 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ROIAlignLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
545 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
546 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
547
548 // Extract input and output
549 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
550 arm_compute::ITensorInfo *rois = detail::get_backing_tensor_info(node.input(1));
551 arm_compute::ITensorInfo *output = detail::get_backing_tensor_info(node.output(0));
552 const ROIPoolingLayerInfo &pool_info = node.pooling_info();
553
554 // Validate function
555 return ROIAlignLayer::validate(input, rois, output, pool_info);
556}
557
Michele Di Giorgioc30b6682018-09-12 17:44:08 +0100558/** Validates a Slice layer node
559 *
560 * @tparam SliceLayer Slice layer function type
561 *
562 * @param[in] node Node to validate
563 *
564 * @return Status
565 */
566template <typename SliceLayer>
567Status validate_slice_layer(SliceLayerNode &node)
568{
569 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating Slice node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
570 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
571 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
572
573 // Extract IO and info
574 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
575 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
576 const Coordinates starts = node.starts();
577 const Coordinates ends = node.ends();
578
579 return SliceLayer::validate(input, output, starts, ends);
580}
581
thecha012bfadd92020-08-12 17:25:51 +0100582/** Validates a Strided Slice layer node
583 *
584 * @tparam StridedSliceLayer Strided Slice layer function type
585 *
586 * @param[in] node Node to validate
587 *
588 * @return Status
589 */
590template <typename StridedSliceLayer>
591Status validate_strided_slice_layer(StridedSliceLayerNode &node)
592{
593 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating StridedSlice node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
594 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
595 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
596
597 // Extract IO and info
598 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
599 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
600 const Coordinates starts = node.starts();
601 const Coordinates ends = node.ends();
602 const BiStrides strides = node.strides();
603 const StridedSliceLayerInfo info = node.strided_slice_info();
604
605 return StridedSliceLayer::validate(input, output, starts, ends, strides, info.begin_mask(), info.end_mask(), info.shrink_axis_mask());
606}
607
Michalis Spyrou4e1c3f32018-09-20 17:14:03 +0100608/** Validates a Upsample layer node
609 *
610 * @tparam UpsampleLayer Upsample layer type
611 *
612 * @param[in] node Node to validate
613 *
614 * @return Status
615 */
616template <typename UpsampleLayer>
617Status validate_upsample_layer(UpsampleLayerNode &node)
618{
619 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating UpsampleLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
620 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
621 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
622
623 // Extract input and output
624 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
625 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
626
627 // Validate function
628 return UpsampleLayer::validate(input, output, node.info(), node.upsampling_policy());
629}
Michalis Spyrou96f67692018-09-13 11:39:28 +0100630/** Validates a YOLO layer node
631 *
632 * @tparam YOLOLayer YOLO layer type
633 *
634 * @param[in] node Node to validate
635 *
636 * @return Status
637 */
638template <typename YOLOLayer>
639Status validate_yolo_layer(YOLOLayerNode &node)
640{
641 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating YOLOLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
642 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
643 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
644
645 // Extract input and output
646 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
647 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
648
649 // Validate function
650 return YOLOLayer::validate(input, output, node.activation_info(), node.num_classes());
651}
Sheri Zhang16dddd22020-05-27 15:03:48 +0100652/** Validates a element-wise layer node
653 *
654 * @param[in] node Node to validate
655 *
656 * @return Status
657 */
658template <typename EltwiseLayerFunctions>
659Status validate_eltwise_Layer(EltwiseLayerNode &node)
660{
661 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
662 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
663 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
664
665 // Extract input and output
666 const arm_compute::ITensorInfo *input1 = detail::get_backing_tensor_info(node.input(0));
667 const arm_compute::ITensorInfo *input2 = detail::get_backing_tensor_info(node.input(1));
668 const arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
669 const EltwiseOperation eltwise_op = node.eltwise_operation();
670 const ConvertPolicy convert_policy = node.convert_policy();
671 const RoundingPolicy round_policy = node.rounding_policy();
672 const ActivationLayerInfo act_info = node.fused_activation();
673 const QuantizationInfo quant_info = node.output_quant_info();
Sheri Zhang16dddd22020-05-27 15:03:48 +0100674
675 // Validate function
676 if(eltwise_op == EltwiseOperation::Add)
677 {
678 return EltwiseLayerFunctions::ArithmeticAddition::validate(input1, input2, output, convert_policy, act_info);
679 }
680 else if(eltwise_op == EltwiseOperation::Sub)
681 {
682 return EltwiseLayerFunctions::ArithmeticSubtraction::validate(input1, input2, output, convert_policy, act_info);
683 }
684 else if(eltwise_op == EltwiseOperation::Mul)
685 {
Manuel Bottini7e725cf2020-08-12 16:05:16 +0100686 return EltwiseLayerFunctions::PixelWiseMultiplication::validate(input1, input2, output, 1.0f, convert_policy, round_policy, act_info);
Sheri Zhang16dddd22020-05-27 15:03:48 +0100687 }
thecha01f8e35842020-07-28 17:28:17 +0100688 else if(eltwise_op == EltwiseOperation::Max)
689 {
690 return EltwiseLayerFunctions::ElementwiseMax::validate(input1, input2, output, act_info);
691 }
Sheri Zhang16dddd22020-05-27 15:03:48 +0100692 else
693 {
694 ARM_COMPUTE_ERROR("Unsupported element-wise operation!");
695 }
696 return Status{};
697}
698/** Validates a unary element-wise layer node
699 *
700 * @param[in] node Node to validate
701 *
702 * @return Status
703 */
704template <typename UnaryEltwiseLayerFunctions>
705Status validate_unary_eltwise_layer(UnaryEltwiseLayerNode &node)
706{
707 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
708 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
709 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
710
711 // Extract input and output
712 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
713 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
714 const UnaryEltwiseOperation eltwise_op = node.eltwise_descriptor().op;
715
716 // Validate function
717 if(eltwise_op == UnaryEltwiseOperation::Exp)
718 {
719 return UnaryEltwiseLayerFunctions::ExpLayer::validate(input, output);
720 }
721 else
722 {
723 ARM_COMPUTE_ERROR("Unsupported unary element-wise operation!");
724 }
725
726 return Status{};
727}
Georgios Pinitas28705162018-03-21 20:10:53 +0000728} // namespace detail
729} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100730} // namespace graph
Georgios Pinitas28705162018-03-21 20:10:53 +0000731} // namespace arm_compute
732
Michalis Spyrouf4643372019-11-29 16:17:13 +0000733#endif /* ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H */