blob: 1d5fd92838a9bfe1b1a076c1840e7cd2880b0045 [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
thecha013603aff2020-09-01 14:52:38 +0100346/** Validates a L2Normalization layer node
347 *
348 * @tparam L2Normalization layer type
349 *
350 * @param[in] node Node to validate
351 *
352 * @return Status
353 */
354template <typename L2NormalizeLayer>
355Status validate_l2_normalize_layer(L2NormalizeLayerNode &node)
356{
357 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating L2NormalizeLayerNode node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
358 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
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 *output = get_backing_tensor_info(node.output(0));
364 int axis = node.axis();
365 float epsilon = node.epsilon();
366
367 // Validate function
368 return L2NormalizeLayer::validate(input, output, axis, epsilon);
369}
370
Michele Di Giorgio555d1102018-09-12 13:51:59 +0100371/** Validates a NormalizePlanarYUV layer node
372 *
373 * @tparam NormalizePlanarYUVLayer layer type
374 *
375 * @param[in] node Node to validate
376 *
377 * @return Status
378 */
379template <typename NormalizePlanarYUVLayer>
380Status validate_normalize_planar_yuv_layer(NormalizePlanarYUVLayerNode &node)
381{
382 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating NormalizePlanarYUVLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
383 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
384 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
385
386 // Extract IO and info
387 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
388 arm_compute::ITensorInfo *mean = detail::get_backing_tensor_info(node.input(1));
389 arm_compute::ITensorInfo *std = detail::get_backing_tensor_info(node.input(2));
390 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
391
392 // Validate function
393 return NormalizePlanarYUVLayer::validate(input, output, mean, std);
394}
Michele Di Giorgio4bb17332018-09-26 13:56:51 +0100395
396/** Validates a pad layer node
397 *
398 * @tparam PadLayer Pad layer type
399 *
400 * @param[in] node Node to validate
401 *
402 * @return Status
403 */
404template <typename PadLayer>
405Status validate_pad_layer(PadLayerNode &node)
406{
407 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PadLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
408 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
409 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
410
411 // Extract IO and info
412 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
413 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
414 const PaddingList &padding = node.padding();
415
416 return PadLayer::validate(input, output, padding);
417}
418
Georgios Pinitas57c48242018-08-02 13:41:49 +0100419/** Validates a permute layer node
420 *
421 * @tparam PermuteLayer Permute layer type
422 *
423 * @param[in] node Node to validate
424 *
425 * @return Status
426 */
427template <typename PermuteLayer>
428Status validate_permute_layer(PermuteLayerNode &node)
429{
430 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PermuteLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
431 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
432 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
433
434 // Extract IO and info
435 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
436 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
437 const PermutationVector &perm = node.permutation_vector();
438
439 return PermuteLayer::validate(input, output, perm);
440}
Georgios Pinitasf8c47492020-02-04 17:39:59 +0000441
442/** Validates a PRelu layer node
443 *
444 * @tparam PReluLayer PRelu layer type
445 *
446 * @param[in] node Node to validate
447 *
448 * @return Status
449 */
450template <typename PReluLayer>
451Status validate_prelu_layer(PReluLayerNode &node)
452{
453 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PRelu node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
454 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
455 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
456
457 // Extract IO and info
458 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
459 arm_compute::ITensorInfo *alpha = get_backing_tensor_info(node.input(1));
460 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
461
462 return PReluLayer::validate(input, alpha, output);
463}
464
Pablo Tello32521432018-11-15 14:43:10 +0000465/** Validates a priorbox layer node
466 *
467 * @tparam PriorBoxLayer PriorBox layer type
468 *
469 * @param[in] node Node to validate
470 *
471 * @return Status
472 */
473template <typename PriorBoxLayer>
474Status validate_priorbox_layer(PriorBoxLayerNode &node)
475{
476 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PriorBoxLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
477 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
478 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
479
480 // Extract IO and info
481 arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0));
482 arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1));
483 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
484 const PriorBoxLayerInfo prior_info = node.priorbox_info();
485
486 return PriorBoxLayer::validate(input0, input1, output, prior_info);
487}
Gian Marco Iodice23e24792018-09-07 15:32:14 +0100488
Isabella Gottardi3db1ba92019-05-17 12:35:20 +0100489/** Validates a Quantization layer node
490 *
491 * @tparam QuantizationLayer Quantization layer type
492 *
493 * @param[in] node Node to validate
494 *
495 * @return Status
496 */
497template <typename QuantizationLayer>
498Status validate_quantization_layer(QuantizationLayerNode &node)
499{
500 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating QuantizationLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
501 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
502 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
503
504 // Extract input and output
505 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
506 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
507
508 // Validate function
509 return QuantizationLayer::validate(input, output);
510}
511
Gian Marco Iodice23e24792018-09-07 15:32:14 +0100512/** Validates a Reorg layer node
513 *
514 * @tparam ReorgLayer Reorg layer type
515 *
516 * @param[in] node Node to validate
517 *
518 * @return Status
519 */
520template <typename ReorgLayer>
521Status validate_reorg_layer(ReorgLayerNode &node)
522{
523 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReorgLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
524 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
525 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
526
527 // Extract input and output
528 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
529 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
530
531 // Validate function
532 return ReorgLayer::validate(input, output, node.stride());
533}
Michalis Spyrou96f67692018-09-13 11:39:28 +0100534
Isabella Gottardi0ae5de92019-03-14 10:32:11 +0000535/** Validates a Reshape layer node
536 *
537 * @tparam ReshapeLayer Reshape layer type
538 *
539 * @param[in] node Node to validate
540 *
541 * @return Status
542 */
543template <typename ReshapeLayer>
544Status validate_reshape_layer(ReshapeLayerNode &node)
545{
546 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReshapeLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
547 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
548 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
549
550 // Extract input and output
551 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
552 arm_compute::ITensorInfo *output = detail::get_backing_tensor_info(node.output(0));
553
554 // Validate function
555 return ReshapeLayer::validate(input, output);
556}
557
Manuel Bottini3f9d4d72018-10-19 14:04:42 +0100558/** Validates a ROI Align layer node
559 *
560 * @tparam ROIAlignLayer ROIAlign layer type
561 *
562 * @param[in] node Node to validate
563 *
564 * @return Status
565 */
566template <typename ROIAlignLayer>
567Status validate_roi_align_layer(ROIAlignLayerNode &node)
568{
569 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ROIAlignLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
570 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
571 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
572
573 // Extract input and output
574 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
575 arm_compute::ITensorInfo *rois = detail::get_backing_tensor_info(node.input(1));
576 arm_compute::ITensorInfo *output = detail::get_backing_tensor_info(node.output(0));
577 const ROIPoolingLayerInfo &pool_info = node.pooling_info();
578
579 // Validate function
580 return ROIAlignLayer::validate(input, rois, output, pool_info);
581}
582
Michele Di Giorgioc30b6682018-09-12 17:44:08 +0100583/** Validates a Slice layer node
584 *
585 * @tparam SliceLayer Slice layer function type
586 *
587 * @param[in] node Node to validate
588 *
589 * @return Status
590 */
591template <typename SliceLayer>
592Status validate_slice_layer(SliceLayerNode &node)
593{
594 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating Slice node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
595 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
596 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
597
598 // Extract IO and info
599 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
600 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
601 const Coordinates starts = node.starts();
602 const Coordinates ends = node.ends();
603
604 return SliceLayer::validate(input, output, starts, ends);
605}
606
thecha012bfadd92020-08-12 17:25:51 +0100607/** Validates a Strided Slice layer node
608 *
609 * @tparam StridedSliceLayer Strided Slice layer function type
610 *
611 * @param[in] node Node to validate
612 *
613 * @return Status
614 */
615template <typename StridedSliceLayer>
616Status validate_strided_slice_layer(StridedSliceLayerNode &node)
617{
618 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating StridedSlice node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
619 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
620 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
621
622 // Extract IO and info
623 arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
624 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
625 const Coordinates starts = node.starts();
626 const Coordinates ends = node.ends();
627 const BiStrides strides = node.strides();
628 const StridedSliceLayerInfo info = node.strided_slice_info();
629
630 return StridedSliceLayer::validate(input, output, starts, ends, strides, info.begin_mask(), info.end_mask(), info.shrink_axis_mask());
631}
632
Michalis Spyrou4e1c3f32018-09-20 17:14:03 +0100633/** Validates a Upsample layer node
634 *
635 * @tparam UpsampleLayer Upsample layer type
636 *
637 * @param[in] node Node to validate
638 *
639 * @return Status
640 */
641template <typename UpsampleLayer>
642Status validate_upsample_layer(UpsampleLayerNode &node)
643{
644 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating UpsampleLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
645 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
646 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
647
648 // Extract input and output
649 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
650 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
651
652 // Validate function
653 return UpsampleLayer::validate(input, output, node.info(), node.upsampling_policy());
654}
Michalis Spyrou96f67692018-09-13 11:39:28 +0100655/** Validates a YOLO layer node
656 *
657 * @tparam YOLOLayer YOLO layer type
658 *
659 * @param[in] node Node to validate
660 *
661 * @return Status
662 */
663template <typename YOLOLayer>
664Status validate_yolo_layer(YOLOLayerNode &node)
665{
666 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating YOLOLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
667 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
668 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
669
670 // Extract input and output
671 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
672 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
673
674 // Validate function
675 return YOLOLayer::validate(input, output, node.activation_info(), node.num_classes());
676}
Sheri Zhang16dddd22020-05-27 15:03:48 +0100677/** Validates a element-wise layer node
678 *
679 * @param[in] node Node to validate
680 *
681 * @return Status
682 */
683template <typename EltwiseLayerFunctions>
684Status validate_eltwise_Layer(EltwiseLayerNode &node)
685{
686 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
687 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
688 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
689
690 // Extract input and output
691 const arm_compute::ITensorInfo *input1 = detail::get_backing_tensor_info(node.input(0));
692 const arm_compute::ITensorInfo *input2 = detail::get_backing_tensor_info(node.input(1));
693 const arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
694 const EltwiseOperation eltwise_op = node.eltwise_operation();
695 const ConvertPolicy convert_policy = node.convert_policy();
696 const RoundingPolicy round_policy = node.rounding_policy();
697 const ActivationLayerInfo act_info = node.fused_activation();
698 const QuantizationInfo quant_info = node.output_quant_info();
Sheri Zhang16dddd22020-05-27 15:03:48 +0100699
700 // Validate function
701 if(eltwise_op == EltwiseOperation::Add)
702 {
703 return EltwiseLayerFunctions::ArithmeticAddition::validate(input1, input2, output, convert_policy, act_info);
704 }
705 else if(eltwise_op == EltwiseOperation::Sub)
706 {
707 return EltwiseLayerFunctions::ArithmeticSubtraction::validate(input1, input2, output, convert_policy, act_info);
708 }
709 else if(eltwise_op == EltwiseOperation::Mul)
710 {
Manuel Bottini7e725cf2020-08-12 16:05:16 +0100711 return EltwiseLayerFunctions::PixelWiseMultiplication::validate(input1, input2, output, 1.0f, convert_policy, round_policy, act_info);
Sheri Zhang16dddd22020-05-27 15:03:48 +0100712 }
thecha01f8e35842020-07-28 17:28:17 +0100713 else if(eltwise_op == EltwiseOperation::Max)
714 {
715 return EltwiseLayerFunctions::ElementwiseMax::validate(input1, input2, output, act_info);
716 }
Sheri Zhang16dddd22020-05-27 15:03:48 +0100717 else
718 {
719 ARM_COMPUTE_ERROR("Unsupported element-wise operation!");
720 }
721 return Status{};
722}
723/** Validates a unary element-wise layer node
724 *
725 * @param[in] node Node to validate
726 *
727 * @return Status
728 */
729template <typename UnaryEltwiseLayerFunctions>
730Status validate_unary_eltwise_layer(UnaryEltwiseLayerNode &node)
731{
732 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
733 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
734 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
735
736 // Extract input and output
737 arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
738 arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
739 const UnaryEltwiseOperation eltwise_op = node.eltwise_descriptor().op;
740
741 // Validate function
742 if(eltwise_op == UnaryEltwiseOperation::Exp)
743 {
744 return UnaryEltwiseLayerFunctions::ExpLayer::validate(input, output);
745 }
746 else
747 {
748 ARM_COMPUTE_ERROR("Unsupported unary element-wise operation!");
749 }
750
751 return Status{};
752}
Georgios Pinitas28705162018-03-21 20:10:53 +0000753} // namespace detail
754} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100755} // namespace graph
Georgios Pinitas28705162018-03-21 20:10:53 +0000756} // namespace arm_compute
757
Michalis Spyrouf4643372019-11-29 16:17:13 +0000758#endif /* ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H */