1*c217d954SCole Faust /*
2*c217d954SCole Faust * Copyright (c) 2018-2021 Arm Limited.
3*c217d954SCole Faust *
4*c217d954SCole Faust * SPDX-License-Identifier: MIT
5*c217d954SCole Faust *
6*c217d954SCole Faust * Permission is hereby granted, free of charge, to any person obtaining a copy
7*c217d954SCole Faust * of this software and associated documentation files (the "Software"), to
8*c217d954SCole Faust * deal in the Software without restriction, including without limitation the
9*c217d954SCole Faust * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10*c217d954SCole Faust * sell copies of the Software, and to permit persons to whom the Software is
11*c217d954SCole Faust * furnished to do so, subject to the following conditions:
12*c217d954SCole Faust *
13*c217d954SCole Faust * The above copyright notice and this permission notice shall be included in all
14*c217d954SCole Faust * copies or substantial portions of the Software.
15*c217d954SCole Faust *
16*c217d954SCole Faust * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*c217d954SCole Faust * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*c217d954SCole Faust * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*c217d954SCole Faust * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*c217d954SCole Faust * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21*c217d954SCole Faust * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22*c217d954SCole Faust * SOFTWARE.
23*c217d954SCole Faust */
24*c217d954SCole Faust #ifndef ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H
25*c217d954SCole Faust #define ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H
26*c217d954SCole Faust
27*c217d954SCole Faust #include "arm_compute/graph/Logger.h"
28*c217d954SCole Faust #include "arm_compute/graph/Tensor.h"
29*c217d954SCole Faust #include "arm_compute/graph/Types.h"
30*c217d954SCole Faust #include "arm_compute/graph/nodes/Nodes.h"
31*c217d954SCole Faust
32*c217d954SCole Faust #include "arm_compute/core/Error.h"
33*c217d954SCole Faust #include "arm_compute/core/Helpers.h"
34*c217d954SCole Faust #include "arm_compute/core/ITensorInfo.h"
35*c217d954SCole Faust
36*c217d954SCole Faust namespace arm_compute
37*c217d954SCole Faust {
38*c217d954SCole Faust namespace graph
39*c217d954SCole Faust {
40*c217d954SCole Faust namespace backends
41*c217d954SCole Faust {
42*c217d954SCole Faust namespace detail
43*c217d954SCole Faust {
44*c217d954SCole Faust /** Returns backing tensor info of a given tensor
45*c217d954SCole Faust *
46*c217d954SCole Faust * @param[in] tensor Tensor to extract the backing tensor from
47*c217d954SCole Faust *
48*c217d954SCole Faust * @return Backing tensor tensor info if present else nullptr
49*c217d954SCole Faust */
get_backing_tensor_info(arm_compute::graph::Tensor * tensor)50*c217d954SCole Faust inline arm_compute::ITensorInfo *get_backing_tensor_info(arm_compute::graph::Tensor *tensor)
51*c217d954SCole Faust {
52*c217d954SCole Faust return ((tensor == nullptr) || (tensor->handle() == nullptr)) ? nullptr : tensor->handle()->tensor().info();
53*c217d954SCole Faust }
54*c217d954SCole Faust
55*c217d954SCole Faust /** Validates a ArgMinMax layer node
56*c217d954SCole Faust *
57*c217d954SCole Faust * @tparam ArgMinMax layer function type
58*c217d954SCole Faust *
59*c217d954SCole Faust * @param[in] node Node to validate
60*c217d954SCole Faust *
61*c217d954SCole Faust * @return Status
62*c217d954SCole Faust */
63*c217d954SCole Faust template <typename ArgMinMaxLayer>
validate_arg_min_max_layer(ArgMinMaxLayerNode & node)64*c217d954SCole Faust Status validate_arg_min_max_layer(ArgMinMaxLayerNode &node)
65*c217d954SCole Faust {
66*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ArgMinMaxLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
67*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
68*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
69*c217d954SCole Faust
70*c217d954SCole Faust // Extract IO and info
71*c217d954SCole Faust arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
72*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
73*c217d954SCole Faust
74*c217d954SCole Faust // Validate function
75*c217d954SCole Faust return ArgMinMaxLayer::validate(input, node.axis(), output, node.reduction_operation());
76*c217d954SCole Faust }
77*c217d954SCole Faust
78*c217d954SCole Faust /** Validates a Bounding Box Transform layer node
79*c217d954SCole Faust *
80*c217d954SCole Faust * @tparam BoundingBoxTransformLayer Bounding Box Transform layer function type
81*c217d954SCole Faust *
82*c217d954SCole Faust * @param[in] node Node to validate
83*c217d954SCole Faust *
84*c217d954SCole Faust * @return Status
85*c217d954SCole Faust */
86*c217d954SCole Faust template <typename BoundingBoxTransformLayer>
validate_bounding_box_transform_layer(BoundingBoxTransformLayerNode & node)87*c217d954SCole Faust Status validate_bounding_box_transform_layer(BoundingBoxTransformLayerNode &node)
88*c217d954SCole Faust {
89*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating BoundingBoxTransformLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
90*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
91*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
92*c217d954SCole Faust
93*c217d954SCole Faust // Extract IO and info
94*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
95*c217d954SCole Faust arm_compute::ITensorInfo *deltas = get_backing_tensor_info(node.input(1));
96*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
97*c217d954SCole Faust const BoundingBoxTransformInfo bbox_info = node.info();
98*c217d954SCole Faust
99*c217d954SCole Faust return BoundingBoxTransformLayer::validate(input, output, deltas, bbox_info);
100*c217d954SCole Faust }
101*c217d954SCole Faust
102*c217d954SCole Faust /** Validates a Channel Shuffle layer node
103*c217d954SCole Faust *
104*c217d954SCole Faust * @tparam ChannelShuffleLayer Channel Shuffle layer function type
105*c217d954SCole Faust *
106*c217d954SCole Faust * @param[in] node Node to validate
107*c217d954SCole Faust *
108*c217d954SCole Faust * @return Status
109*c217d954SCole Faust */
110*c217d954SCole Faust template <typename ChannelShuffleLayer>
validate_channel_shuffle_layer(ChannelShuffleLayerNode & node)111*c217d954SCole Faust Status validate_channel_shuffle_layer(ChannelShuffleLayerNode &node)
112*c217d954SCole Faust {
113*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ChannelShuffle node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
114*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
115*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
116*c217d954SCole Faust
117*c217d954SCole Faust // Extract IO and info
118*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
119*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
120*c217d954SCole Faust const unsigned int num_groups = node.num_groups();
121*c217d954SCole Faust
122*c217d954SCole Faust return ChannelShuffleLayer::validate(input, output, num_groups);
123*c217d954SCole Faust }
124*c217d954SCole Faust
125*c217d954SCole Faust /** Validates a Convolution layer node
126*c217d954SCole Faust *
127*c217d954SCole Faust * @tparam ConvolutionLayer Default Convolution layer function type
128*c217d954SCole Faust * @tparam DirectConvolutionLayer Direct Convolution layer function type
129*c217d954SCole Faust * @tparam GEMMConvolutionLayer GEMM Convolution layer function type
130*c217d954SCole Faust * @tparam WinogradConvolutionLayer Winograd Convolution layer function type
131*c217d954SCole Faust *
132*c217d954SCole Faust * @param[in] node Node to validate
133*c217d954SCole Faust *
134*c217d954SCole Faust * @return Status
135*c217d954SCole Faust */
136*c217d954SCole Faust template <typename ConvolutionLayer, typename DirectConvolutionLayer, typename GEMMConvolutionLayer, typename WinogradConvolutionLayer>
validate_convolution_layer(ConvolutionLayerNode & node)137*c217d954SCole Faust Status validate_convolution_layer(ConvolutionLayerNode &node)
138*c217d954SCole Faust {
139*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
140*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
141*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
142*c217d954SCole Faust
143*c217d954SCole Faust // Extract IO and info
144*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
145*c217d954SCole Faust arm_compute::ITensorInfo *weights = get_backing_tensor_info(node.input(1));
146*c217d954SCole Faust arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2));
147*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
148*c217d954SCole Faust
149*c217d954SCole Faust if(is_data_type_quantized_asymmetric(input->data_type()))
150*c217d954SCole Faust {
151*c217d954SCole Faust biases->set_data_type(DataType::S32);
152*c217d954SCole Faust }
153*c217d954SCole Faust
154*c217d954SCole Faust const PadStrideInfo conv_info = node.convolution_info();
155*c217d954SCole Faust const ConvolutionMethod conv_algorithm = node.convolution_method();
156*c217d954SCole Faust const bool fast_math = node.fast_math_hint() == FastMathHint::Enabled;
157*c217d954SCole Faust const unsigned int num_groups = node.num_groups();
158*c217d954SCole Faust
159*c217d954SCole Faust // Validate function
160*c217d954SCole Faust Status status{};
161*c217d954SCole Faust switch(conv_algorithm)
162*c217d954SCole Faust {
163*c217d954SCole Faust case ConvolutionMethod::Direct:
164*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON_MSG(num_groups != 1, "DirectConvolutionLayer does not support grouping!");
165*c217d954SCole Faust status = DirectConvolutionLayer::validate(input, weights, biases, output, conv_info);
166*c217d954SCole Faust break;
167*c217d954SCole Faust case ConvolutionMethod::GEMM:
168*c217d954SCole Faust status = GEMMConvolutionLayer::validate(input, weights, biases, output, conv_info,
169*c217d954SCole Faust WeightsInfo(), Size2D(1, 1), ActivationLayerInfo(), num_groups);
170*c217d954SCole Faust break;
171*c217d954SCole Faust case ConvolutionMethod::Winograd:
172*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON_MSG(num_groups != 1, "WinogradConvolutionLayer does not support grouping!");
173*c217d954SCole Faust status = WinogradConvolutionLayer::validate(input, weights, biases, output, conv_info, ActivationLayerInfo(), fast_math);
174*c217d954SCole Faust break;
175*c217d954SCole Faust case ConvolutionMethod::Default:
176*c217d954SCole Faust status = ConvolutionLayer::validate(input, weights, biases, output, conv_info,
177*c217d954SCole Faust WeightsInfo(), Size2D(1, 1), ActivationLayerInfo(), fast_math, num_groups);
178*c217d954SCole Faust break;
179*c217d954SCole Faust default:
180*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_MSG("Unsupported convolution method");
181*c217d954SCole Faust }
182*c217d954SCole Faust
183*c217d954SCole Faust return status;
184*c217d954SCole Faust }
185*c217d954SCole Faust
186*c217d954SCole Faust /** Validates a Convolution layer node
187*c217d954SCole Faust *
188*c217d954SCole Faust * @tparam GEMMConvolutionLayer GEMM Convolution layer function type
189*c217d954SCole Faust *
190*c217d954SCole Faust * @param[in] node Node to validate
191*c217d954SCole Faust *
192*c217d954SCole Faust * @return Status
193*c217d954SCole Faust */
194*c217d954SCole Faust template <typename GEMMConvolutionLayer>
validate_fused_convolution_with_post_op(FusedConvolutionWithPostOpNode & node)195*c217d954SCole Faust Status validate_fused_convolution_with_post_op(FusedConvolutionWithPostOpNode &node)
196*c217d954SCole Faust {
197*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating fused ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
198*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 4);
199*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
200*c217d954SCole Faust
201*c217d954SCole Faust // Extract IO and info
202*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
203*c217d954SCole Faust arm_compute::ITensorInfo *weights = get_backing_tensor_info(node.input(1));
204*c217d954SCole Faust arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2));
205*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
206*c217d954SCole Faust
207*c217d954SCole Faust if(is_data_type_quantized_asymmetric(input->data_type()))
208*c217d954SCole Faust {
209*c217d954SCole Faust biases->set_data_type(DataType::S32);
210*c217d954SCole Faust }
211*c217d954SCole Faust
212*c217d954SCole Faust const PadStrideInfo conv_info = node.convolution_info();
213*c217d954SCole Faust //const ConvolutionMethod conv_algorithm = node.convolution_method();
214*c217d954SCole Faust //const bool fast_math = node.fast_math_hint() == FastMathHint::Enabled;
215*c217d954SCole Faust const unsigned int num_groups = node.num_groups();
216*c217d954SCole Faust
217*c217d954SCole Faust // Validate function
218*c217d954SCole Faust return GEMMConvolutionLayer::validate(input, weights, biases, output, conv_info,
219*c217d954SCole Faust WeightsInfo(), Size2D(1, 1), ActivationLayerInfo(), num_groups);
220*c217d954SCole Faust }
221*c217d954SCole Faust
222*c217d954SCole Faust /** Validates a Depthwise Convolution layer node
223*c217d954SCole Faust *
224*c217d954SCole Faust * @tparam DepthwiseConvolutionLayer Default Depthwise Convolution layer type
225*c217d954SCole Faust *
226*c217d954SCole Faust * @param[in] node Node to validate
227*c217d954SCole Faust *
228*c217d954SCole Faust * @return Status
229*c217d954SCole Faust */
230*c217d954SCole Faust template <typename DepthwiseConvolutionLayer>
validate_depthwise_convolution_layer(DepthwiseConvolutionLayerNode & node)231*c217d954SCole Faust Status validate_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node)
232*c217d954SCole Faust {
233*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DepthwiseConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
234*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
235*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
236*c217d954SCole Faust
237*c217d954SCole Faust // Extract IO and info
238*c217d954SCole Faust arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
239*c217d954SCole Faust arm_compute::ITensorInfo *weights = detail::get_backing_tensor_info(node.input(1));
240*c217d954SCole Faust arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2));
241*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
242*c217d954SCole Faust
243*c217d954SCole Faust const PadStrideInfo conv_info = node.convolution_info();
244*c217d954SCole Faust const DepthwiseConvolutionMethod dwc_algorithm = node.depthwise_convolution_method();
245*c217d954SCole Faust const int depth_multiplier = node.depth_multiplier();
246*c217d954SCole Faust
247*c217d954SCole Faust // Validate function
248*c217d954SCole Faust Status status{};
249*c217d954SCole Faust switch(dwc_algorithm)
250*c217d954SCole Faust {
251*c217d954SCole Faust case DepthwiseConvolutionMethod::Default:
252*c217d954SCole Faust case DepthwiseConvolutionMethod::Optimized3x3:
253*c217d954SCole Faust status = DepthwiseConvolutionLayer::validate(input, weights, biases, output, conv_info, depth_multiplier);
254*c217d954SCole Faust break;
255*c217d954SCole Faust default:
256*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_MSG("Unsupported depthwise convolution method");
257*c217d954SCole Faust }
258*c217d954SCole Faust
259*c217d954SCole Faust return status;
260*c217d954SCole Faust }
261*c217d954SCole Faust /** Validates a depth to space layer node
262*c217d954SCole Faust *
263*c217d954SCole Faust * @tparam DequantizationLayer Dequantize layer type
264*c217d954SCole Faust *
265*c217d954SCole Faust * @param[in] node Node to validate
266*c217d954SCole Faust *
267*c217d954SCole Faust * @return Status
268*c217d954SCole Faust */
269*c217d954SCole Faust template <typename DepthToSpaceLayer>
validate_depth_to_space_layer(DepthToSpaceLayerNode & node)270*c217d954SCole Faust Status validate_depth_to_space_layer(DepthToSpaceLayerNode &node)
271*c217d954SCole Faust {
272*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
273*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
274*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
275*c217d954SCole Faust
276*c217d954SCole Faust // Extract IO and info
277*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
278*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
279*c217d954SCole Faust
280*c217d954SCole Faust return DepthToSpaceLayer::validate(input, output, node.block_shape());
281*c217d954SCole Faust }
282*c217d954SCole Faust /** Validates a dequantize layer node
283*c217d954SCole Faust *
284*c217d954SCole Faust * @tparam DequantizationLayer Dequantize layer type
285*c217d954SCole Faust *
286*c217d954SCole Faust * @param[in] node Node to validate
287*c217d954SCole Faust *
288*c217d954SCole Faust * @return Status
289*c217d954SCole Faust */
290*c217d954SCole Faust template <typename DequantizationLayer>
validate_dequantization_layer(DequantizationLayerNode & node)291*c217d954SCole Faust Status validate_dequantization_layer(DequantizationLayerNode &node)
292*c217d954SCole Faust {
293*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
294*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
295*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
296*c217d954SCole Faust
297*c217d954SCole Faust // Extract IO and info
298*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
299*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
300*c217d954SCole Faust
301*c217d954SCole Faust return DequantizationLayer::validate(input, output);
302*c217d954SCole Faust }
303*c217d954SCole Faust /** Validates a detection output layer node
304*c217d954SCole Faust *
305*c217d954SCole Faust * @tparam DetectionOutputLayer DetectionOutput layer type
306*c217d954SCole Faust *
307*c217d954SCole Faust * @param[in] node Node to validate
308*c217d954SCole Faust *
309*c217d954SCole Faust * @return Status
310*c217d954SCole Faust */
311*c217d954SCole Faust template <typename DetectionOutputLayer>
validate_detection_output_layer(DetectionOutputLayerNode & node)312*c217d954SCole Faust Status validate_detection_output_layer(DetectionOutputLayerNode &node)
313*c217d954SCole Faust {
314*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
315*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
316*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
317*c217d954SCole Faust
318*c217d954SCole Faust // Extract IO and info
319*c217d954SCole Faust arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0));
320*c217d954SCole Faust arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1));
321*c217d954SCole Faust arm_compute::ITensorInfo *input2 = get_backing_tensor_info(node.input(2));
322*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
323*c217d954SCole Faust const DetectionOutputLayerInfo detect_info = node.detection_output_info();
324*c217d954SCole Faust
325*c217d954SCole Faust return DetectionOutputLayer::validate(input0, input1, input2, output, detect_info);
326*c217d954SCole Faust }
327*c217d954SCole Faust /** Validates a detection post process layer node
328*c217d954SCole Faust *
329*c217d954SCole Faust * @tparam DetectionPostProcessLayer DetectionOutput layer type
330*c217d954SCole Faust *
331*c217d954SCole Faust * @param[in] node Node to validate
332*c217d954SCole Faust *
333*c217d954SCole Faust * @return Status
334*c217d954SCole Faust */
335*c217d954SCole Faust template <typename DetectionPostProcessLayer>
validate_detection_post_process_layer(DetectionPostProcessLayerNode & node)336*c217d954SCole Faust Status validate_detection_post_process_layer(DetectionPostProcessLayerNode &node)
337*c217d954SCole Faust {
338*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionPostProcessLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
339*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
340*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 4);
341*c217d954SCole Faust
342*c217d954SCole Faust // Extract IO and info
343*c217d954SCole Faust arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0));
344*c217d954SCole Faust arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1));
345*c217d954SCole Faust arm_compute::ITensorInfo *input2 = get_backing_tensor_info(node.input(2));
346*c217d954SCole Faust arm_compute::ITensorInfo *output0 = get_backing_tensor_info(node.output(0));
347*c217d954SCole Faust arm_compute::ITensorInfo *output1 = get_backing_tensor_info(node.output(1));
348*c217d954SCole Faust arm_compute::ITensorInfo *output2 = get_backing_tensor_info(node.output(2));
349*c217d954SCole Faust arm_compute::ITensorInfo *output3 = get_backing_tensor_info(node.output(3));
350*c217d954SCole Faust const DetectionPostProcessLayerInfo detect_info = node.detection_post_process_info();
351*c217d954SCole Faust
352*c217d954SCole Faust return DetectionPostProcessLayer::validate(input0, input1, input2, output0, output1, output2, output3, detect_info);
353*c217d954SCole Faust }
354*c217d954SCole Faust
355*c217d954SCole Faust /** Validates a Generate Proposals layer node
356*c217d954SCole Faust *
357*c217d954SCole Faust * @tparam GenerateProposalsLayer Generate Proposals layer type
358*c217d954SCole Faust *
359*c217d954SCole Faust * @param[in] node Node to validate
360*c217d954SCole Faust *
361*c217d954SCole Faust * @return Status
362*c217d954SCole Faust */
363*c217d954SCole Faust template <typename GenerateProposalsLayer>
validate_generate_proposals_layer(GenerateProposalsLayerNode & node)364*c217d954SCole Faust Status validate_generate_proposals_layer(GenerateProposalsLayerNode &node)
365*c217d954SCole Faust {
366*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating GenerateProposalsLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
367*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
368*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 3);
369*c217d954SCole Faust
370*c217d954SCole Faust // Extract IO and info
371*c217d954SCole Faust arm_compute::ITensorInfo *scores = detail::get_backing_tensor_info(node.input(0));
372*c217d954SCole Faust arm_compute::ITensorInfo *deltas = detail::get_backing_tensor_info(node.input(1));
373*c217d954SCole Faust arm_compute::ITensorInfo *anchors = detail::get_backing_tensor_info(node.input(2));
374*c217d954SCole Faust arm_compute::ITensorInfo *proposals = get_backing_tensor_info(node.output(0));
375*c217d954SCole Faust arm_compute::ITensorInfo *scores_out = get_backing_tensor_info(node.output(1));
376*c217d954SCole Faust arm_compute::ITensorInfo *num_valid_proposals = get_backing_tensor_info(node.output(2));
377*c217d954SCole Faust const GenerateProposalsInfo info = node.info();
378*c217d954SCole Faust
379*c217d954SCole Faust return GenerateProposalsLayer::validate(scores, deltas, anchors, proposals, scores_out, num_valid_proposals, info);
380*c217d954SCole Faust }
381*c217d954SCole Faust
382*c217d954SCole Faust /** Validates a L2Normalization layer node
383*c217d954SCole Faust *
384*c217d954SCole Faust * @tparam L2Normalization layer type
385*c217d954SCole Faust *
386*c217d954SCole Faust * @param[in] node Node to validate
387*c217d954SCole Faust *
388*c217d954SCole Faust * @return Status
389*c217d954SCole Faust */
390*c217d954SCole Faust template <typename L2NormalizeLayer>
validate_l2_normalize_layer(L2NormalizeLayerNode & node)391*c217d954SCole Faust Status validate_l2_normalize_layer(L2NormalizeLayerNode &node)
392*c217d954SCole Faust {
393*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating L2NormalizeLayerNode node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
394*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
395*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
396*c217d954SCole Faust
397*c217d954SCole Faust // Extract IO and info
398*c217d954SCole Faust arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
399*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
400*c217d954SCole Faust int axis = node.axis();
401*c217d954SCole Faust float epsilon = node.epsilon();
402*c217d954SCole Faust
403*c217d954SCole Faust // Validate function
404*c217d954SCole Faust return L2NormalizeLayer::validate(input, output, axis, epsilon);
405*c217d954SCole Faust }
406*c217d954SCole Faust
407*c217d954SCole Faust /** Validates a NormalizePlanarYUV layer node
408*c217d954SCole Faust *
409*c217d954SCole Faust * @tparam NormalizePlanarYUVLayer layer type
410*c217d954SCole Faust *
411*c217d954SCole Faust * @param[in] node Node to validate
412*c217d954SCole Faust *
413*c217d954SCole Faust * @return Status
414*c217d954SCole Faust */
415*c217d954SCole Faust template <typename NormalizePlanarYUVLayer>
validate_normalize_planar_yuv_layer(NormalizePlanarYUVLayerNode & node)416*c217d954SCole Faust Status validate_normalize_planar_yuv_layer(NormalizePlanarYUVLayerNode &node)
417*c217d954SCole Faust {
418*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating NormalizePlanarYUVLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
419*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
420*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
421*c217d954SCole Faust
422*c217d954SCole Faust // Extract IO and info
423*c217d954SCole Faust arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
424*c217d954SCole Faust arm_compute::ITensorInfo *mean = detail::get_backing_tensor_info(node.input(1));
425*c217d954SCole Faust arm_compute::ITensorInfo *std = detail::get_backing_tensor_info(node.input(2));
426*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
427*c217d954SCole Faust
428*c217d954SCole Faust // Validate function
429*c217d954SCole Faust return NormalizePlanarYUVLayer::validate(input, output, mean, std);
430*c217d954SCole Faust }
431*c217d954SCole Faust
432*c217d954SCole Faust /** Validates a pad layer node
433*c217d954SCole Faust *
434*c217d954SCole Faust * @tparam PadLayer Pad layer type
435*c217d954SCole Faust *
436*c217d954SCole Faust * @param[in] node Node to validate
437*c217d954SCole Faust *
438*c217d954SCole Faust * @return Status
439*c217d954SCole Faust */
440*c217d954SCole Faust template <typename PadLayer>
validate_pad_layer(PadLayerNode & node)441*c217d954SCole Faust Status validate_pad_layer(PadLayerNode &node)
442*c217d954SCole Faust {
443*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PadLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
444*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
445*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
446*c217d954SCole Faust
447*c217d954SCole Faust // Extract IO and info
448*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
449*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
450*c217d954SCole Faust const PaddingList &padding = node.padding();
451*c217d954SCole Faust
452*c217d954SCole Faust return PadLayer::validate(input, output, padding);
453*c217d954SCole Faust }
454*c217d954SCole Faust
455*c217d954SCole Faust /** Validates a permute layer node
456*c217d954SCole Faust *
457*c217d954SCole Faust * @tparam PermuteLayer Permute layer type
458*c217d954SCole Faust *
459*c217d954SCole Faust * @param[in] node Node to validate
460*c217d954SCole Faust *
461*c217d954SCole Faust * @return Status
462*c217d954SCole Faust */
463*c217d954SCole Faust template <typename PermuteLayer>
validate_permute_layer(PermuteLayerNode & node)464*c217d954SCole Faust Status validate_permute_layer(PermuteLayerNode &node)
465*c217d954SCole Faust {
466*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PermuteLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
467*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
468*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
469*c217d954SCole Faust
470*c217d954SCole Faust // Extract IO and info
471*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
472*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
473*c217d954SCole Faust const PermutationVector &perm = node.permutation_vector();
474*c217d954SCole Faust
475*c217d954SCole Faust return PermuteLayer::validate(input, output, perm);
476*c217d954SCole Faust }
477*c217d954SCole Faust
478*c217d954SCole Faust /** Validates a PRelu layer node
479*c217d954SCole Faust *
480*c217d954SCole Faust * @tparam PReluLayer PRelu layer type
481*c217d954SCole Faust *
482*c217d954SCole Faust * @param[in] node Node to validate
483*c217d954SCole Faust *
484*c217d954SCole Faust * @return Status
485*c217d954SCole Faust */
486*c217d954SCole Faust template <typename PReluLayer>
validate_prelu_layer(PReluLayerNode & node)487*c217d954SCole Faust Status validate_prelu_layer(PReluLayerNode &node)
488*c217d954SCole Faust {
489*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PRelu node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
490*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
491*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
492*c217d954SCole Faust
493*c217d954SCole Faust // Extract IO and info
494*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
495*c217d954SCole Faust arm_compute::ITensorInfo *alpha = get_backing_tensor_info(node.input(1));
496*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
497*c217d954SCole Faust
498*c217d954SCole Faust return PReluLayer::validate(input, alpha, output);
499*c217d954SCole Faust }
500*c217d954SCole Faust
501*c217d954SCole Faust /** Validates a priorbox layer node
502*c217d954SCole Faust *
503*c217d954SCole Faust * @tparam PriorBoxLayer PriorBox layer type
504*c217d954SCole Faust *
505*c217d954SCole Faust * @param[in] node Node to validate
506*c217d954SCole Faust *
507*c217d954SCole Faust * @return Status
508*c217d954SCole Faust */
509*c217d954SCole Faust template <typename PriorBoxLayer>
validate_priorbox_layer(PriorBoxLayerNode & node)510*c217d954SCole Faust Status validate_priorbox_layer(PriorBoxLayerNode &node)
511*c217d954SCole Faust {
512*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PriorBoxLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
513*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
514*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
515*c217d954SCole Faust
516*c217d954SCole Faust // Extract IO and info
517*c217d954SCole Faust arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0));
518*c217d954SCole Faust arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1));
519*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
520*c217d954SCole Faust const PriorBoxLayerInfo prior_info = node.priorbox_info();
521*c217d954SCole Faust
522*c217d954SCole Faust return PriorBoxLayer::validate(input0, input1, output, prior_info);
523*c217d954SCole Faust }
524*c217d954SCole Faust
525*c217d954SCole Faust /** Validates a Quantization layer node
526*c217d954SCole Faust *
527*c217d954SCole Faust * @tparam QuantizationLayer Quantization layer type
528*c217d954SCole Faust *
529*c217d954SCole Faust * @param[in] node Node to validate
530*c217d954SCole Faust *
531*c217d954SCole Faust * @return Status
532*c217d954SCole Faust */
533*c217d954SCole Faust template <typename QuantizationLayer>
validate_quantization_layer(QuantizationLayerNode & node)534*c217d954SCole Faust Status validate_quantization_layer(QuantizationLayerNode &node)
535*c217d954SCole Faust {
536*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating QuantizationLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
537*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
538*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
539*c217d954SCole Faust
540*c217d954SCole Faust // Extract input and output
541*c217d954SCole Faust arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
542*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
543*c217d954SCole Faust
544*c217d954SCole Faust // Validate function
545*c217d954SCole Faust return QuantizationLayer::validate(input, output);
546*c217d954SCole Faust }
547*c217d954SCole Faust
548*c217d954SCole Faust /** Validates a Reduction operation layer node
549*c217d954SCole Faust *
550*c217d954SCole Faust * @tparam ReductionLayer Reduction layer type
551*c217d954SCole Faust *
552*c217d954SCole Faust * @param[in] node Node to validate
553*c217d954SCole Faust *
554*c217d954SCole Faust * @return Status
555*c217d954SCole Faust */
556*c217d954SCole Faust template <typename ReductionLayer>
validate_reduction_operation_layer(ReductionLayerNode & node)557*c217d954SCole Faust Status validate_reduction_operation_layer(ReductionLayerNode &node)
558*c217d954SCole Faust {
559*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReductionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
560*c217d954SCole Faust
561*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
562*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
563*c217d954SCole Faust
564*c217d954SCole Faust // Extract input and output
565*c217d954SCole Faust arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
566*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
567*c217d954SCole Faust
568*c217d954SCole Faust // Validate function
569*c217d954SCole Faust return ReductionLayer::validate(input, output, node.axis(), node.op(), node.keep_dims());
570*c217d954SCole Faust }
571*c217d954SCole Faust
572*c217d954SCole Faust /** Validates a Reorg layer node
573*c217d954SCole Faust *
574*c217d954SCole Faust * @tparam ReorgLayer Reorg layer type
575*c217d954SCole Faust *
576*c217d954SCole Faust * @param[in] node Node to validate
577*c217d954SCole Faust *
578*c217d954SCole Faust * @return Status
579*c217d954SCole Faust */
580*c217d954SCole Faust template <typename ReorgLayer>
validate_reorg_layer(ReorgLayerNode & node)581*c217d954SCole Faust Status validate_reorg_layer(ReorgLayerNode &node)
582*c217d954SCole Faust {
583*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReorgLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
584*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
585*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
586*c217d954SCole Faust
587*c217d954SCole Faust // Extract input and output
588*c217d954SCole Faust arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
589*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
590*c217d954SCole Faust
591*c217d954SCole Faust // Validate function
592*c217d954SCole Faust return ReorgLayer::validate(input, output, node.stride());
593*c217d954SCole Faust }
594*c217d954SCole Faust
595*c217d954SCole Faust /** Validates a Reshape layer node
596*c217d954SCole Faust *
597*c217d954SCole Faust * @tparam ReshapeLayer Reshape layer type
598*c217d954SCole Faust *
599*c217d954SCole Faust * @param[in] node Node to validate
600*c217d954SCole Faust *
601*c217d954SCole Faust * @return Status
602*c217d954SCole Faust */
603*c217d954SCole Faust template <typename ReshapeLayer>
validate_reshape_layer(ReshapeLayerNode & node)604*c217d954SCole Faust Status validate_reshape_layer(ReshapeLayerNode &node)
605*c217d954SCole Faust {
606*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReshapeLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
607*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
608*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
609*c217d954SCole Faust
610*c217d954SCole Faust // Extract input and output
611*c217d954SCole Faust arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
612*c217d954SCole Faust arm_compute::ITensorInfo *output = detail::get_backing_tensor_info(node.output(0));
613*c217d954SCole Faust
614*c217d954SCole Faust // Validate function
615*c217d954SCole Faust return ReshapeLayer::validate(input, output);
616*c217d954SCole Faust }
617*c217d954SCole Faust
618*c217d954SCole Faust /** Validates a ROI Align layer node
619*c217d954SCole Faust *
620*c217d954SCole Faust * @tparam ROIAlignLayer ROIAlign layer type
621*c217d954SCole Faust *
622*c217d954SCole Faust * @param[in] node Node to validate
623*c217d954SCole Faust *
624*c217d954SCole Faust * @return Status
625*c217d954SCole Faust */
626*c217d954SCole Faust template <typename ROIAlignLayer>
validate_roi_align_layer(ROIAlignLayerNode & node)627*c217d954SCole Faust Status validate_roi_align_layer(ROIAlignLayerNode &node)
628*c217d954SCole Faust {
629*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ROIAlignLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
630*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
631*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
632*c217d954SCole Faust
633*c217d954SCole Faust // Extract input and output
634*c217d954SCole Faust arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
635*c217d954SCole Faust arm_compute::ITensorInfo *rois = detail::get_backing_tensor_info(node.input(1));
636*c217d954SCole Faust arm_compute::ITensorInfo *output = detail::get_backing_tensor_info(node.output(0));
637*c217d954SCole Faust const ROIPoolingLayerInfo &pool_info = node.pooling_info();
638*c217d954SCole Faust
639*c217d954SCole Faust // Validate function
640*c217d954SCole Faust return ROIAlignLayer::validate(input, rois, output, pool_info);
641*c217d954SCole Faust }
642*c217d954SCole Faust
643*c217d954SCole Faust /** Validates a Slice layer node
644*c217d954SCole Faust *
645*c217d954SCole Faust * @tparam SliceLayer Slice layer function type
646*c217d954SCole Faust *
647*c217d954SCole Faust * @param[in] node Node to validate
648*c217d954SCole Faust *
649*c217d954SCole Faust * @return Status
650*c217d954SCole Faust */
651*c217d954SCole Faust template <typename SliceLayer>
validate_slice_layer(SliceLayerNode & node)652*c217d954SCole Faust Status validate_slice_layer(SliceLayerNode &node)
653*c217d954SCole Faust {
654*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating Slice node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
655*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
656*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
657*c217d954SCole Faust
658*c217d954SCole Faust // Extract IO and info
659*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
660*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
661*c217d954SCole Faust const Coordinates starts = node.starts();
662*c217d954SCole Faust const Coordinates ends = node.ends();
663*c217d954SCole Faust
664*c217d954SCole Faust return SliceLayer::validate(input, output, starts, ends);
665*c217d954SCole Faust }
666*c217d954SCole Faust
667*c217d954SCole Faust /** Validates a Strided Slice layer node
668*c217d954SCole Faust *
669*c217d954SCole Faust * @tparam StridedSliceLayer Strided Slice layer function type
670*c217d954SCole Faust *
671*c217d954SCole Faust * @param[in] node Node to validate
672*c217d954SCole Faust *
673*c217d954SCole Faust * @return Status
674*c217d954SCole Faust */
675*c217d954SCole Faust template <typename StridedSliceLayer>
validate_strided_slice_layer(StridedSliceLayerNode & node)676*c217d954SCole Faust Status validate_strided_slice_layer(StridedSliceLayerNode &node)
677*c217d954SCole Faust {
678*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating StridedSlice node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
679*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
680*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
681*c217d954SCole Faust
682*c217d954SCole Faust // Extract IO and info
683*c217d954SCole Faust arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0));
684*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
685*c217d954SCole Faust const Coordinates starts = node.starts();
686*c217d954SCole Faust const Coordinates ends = node.ends();
687*c217d954SCole Faust const BiStrides strides = node.strides();
688*c217d954SCole Faust const StridedSliceLayerInfo info = node.strided_slice_info();
689*c217d954SCole Faust
690*c217d954SCole Faust return StridedSliceLayer::validate(input, output, starts, ends, strides, info.begin_mask(), info.end_mask(), info.shrink_axis_mask());
691*c217d954SCole Faust }
692*c217d954SCole Faust
693*c217d954SCole Faust /** Validates a element-wise layer node
694*c217d954SCole Faust *
695*c217d954SCole Faust * @param[in] node Node to validate
696*c217d954SCole Faust *
697*c217d954SCole Faust * @return Status
698*c217d954SCole Faust */
699*c217d954SCole Faust template <typename EltwiseLayerFunctions>
validate_eltwise_Layer(EltwiseLayerNode & node)700*c217d954SCole Faust Status validate_eltwise_Layer(EltwiseLayerNode &node)
701*c217d954SCole Faust {
702*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
703*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2);
704*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
705*c217d954SCole Faust
706*c217d954SCole Faust // Extract input and output
707*c217d954SCole Faust const arm_compute::ITensorInfo *input1 = detail::get_backing_tensor_info(node.input(0));
708*c217d954SCole Faust const arm_compute::ITensorInfo *input2 = detail::get_backing_tensor_info(node.input(1));
709*c217d954SCole Faust const arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
710*c217d954SCole Faust const EltwiseOperation eltwise_op = node.eltwise_operation();
711*c217d954SCole Faust const ConvertPolicy convert_policy = node.convert_policy();
712*c217d954SCole Faust const RoundingPolicy round_policy = node.rounding_policy();
713*c217d954SCole Faust const ActivationLayerInfo act_info = node.fused_activation();
714*c217d954SCole Faust const QuantizationInfo quant_info = node.output_quant_info();
715*c217d954SCole Faust
716*c217d954SCole Faust // Validate function
717*c217d954SCole Faust if(eltwise_op == EltwiseOperation::Add)
718*c217d954SCole Faust {
719*c217d954SCole Faust return EltwiseLayerFunctions::ArithmeticAddition::validate(input1, input2, output, convert_policy, act_info);
720*c217d954SCole Faust }
721*c217d954SCole Faust else if(eltwise_op == EltwiseOperation::Sub)
722*c217d954SCole Faust {
723*c217d954SCole Faust return EltwiseLayerFunctions::ArithmeticSubtraction::validate(input1, input2, output, convert_policy, act_info);
724*c217d954SCole Faust }
725*c217d954SCole Faust else if(eltwise_op == EltwiseOperation::Mul)
726*c217d954SCole Faust {
727*c217d954SCole Faust return EltwiseLayerFunctions::PixelWiseMultiplication::validate(input1, input2, output, 1.0f, convert_policy, round_policy, act_info);
728*c217d954SCole Faust }
729*c217d954SCole Faust else if(eltwise_op == EltwiseOperation::Max)
730*c217d954SCole Faust {
731*c217d954SCole Faust return EltwiseLayerFunctions::ElementwiseMax::validate(input1, input2, output, act_info);
732*c217d954SCole Faust }
733*c217d954SCole Faust else if(eltwise_op == EltwiseOperation::Div)
734*c217d954SCole Faust {
735*c217d954SCole Faust return EltwiseLayerFunctions::ArithmeticDivision::validate(input1, input2, output, act_info);
736*c217d954SCole Faust }
737*c217d954SCole Faust else
738*c217d954SCole Faust {
739*c217d954SCole Faust ARM_COMPUTE_ERROR("Unsupported element-wise operation!");
740*c217d954SCole Faust }
741*c217d954SCole Faust return Status{};
742*c217d954SCole Faust }
743*c217d954SCole Faust /** Validates a unary element-wise layer node
744*c217d954SCole Faust *
745*c217d954SCole Faust * @param[in] node Node to validate
746*c217d954SCole Faust *
747*c217d954SCole Faust * @return Status
748*c217d954SCole Faust */
749*c217d954SCole Faust template <typename UnaryEltwiseLayerFunctions>
validate_unary_eltwise_layer(UnaryEltwiseLayerNode & node)750*c217d954SCole Faust Status validate_unary_eltwise_layer(UnaryEltwiseLayerNode &node)
751*c217d954SCole Faust {
752*c217d954SCole Faust ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
753*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1);
754*c217d954SCole Faust ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
755*c217d954SCole Faust
756*c217d954SCole Faust // Extract input and output
757*c217d954SCole Faust arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0));
758*c217d954SCole Faust arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0));
759*c217d954SCole Faust const UnaryEltwiseOperation eltwise_op = node.eltwise_descriptor().op;
760*c217d954SCole Faust
761*c217d954SCole Faust // Validate function
762*c217d954SCole Faust if(eltwise_op == UnaryEltwiseOperation::Exp)
763*c217d954SCole Faust {
764*c217d954SCole Faust return UnaryEltwiseLayerFunctions::ExpLayer::validate(input, output);
765*c217d954SCole Faust }
766*c217d954SCole Faust else
767*c217d954SCole Faust {
768*c217d954SCole Faust ARM_COMPUTE_ERROR("Unsupported unary element-wise operation!");
769*c217d954SCole Faust }
770*c217d954SCole Faust
771*c217d954SCole Faust return Status{};
772*c217d954SCole Faust }
773*c217d954SCole Faust } // namespace detail
774*c217d954SCole Faust } // namespace backends
775*c217d954SCole Faust } // namespace graph
776*c217d954SCole Faust } // namespace arm_compute
777*c217d954SCole Faust
778*c217d954SCole Faust #endif /* ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H */
779