Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 3 | * |
| 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 Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H |
| 25 | #define ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 26 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 27 | #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 Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 31 | |
| 32 | #include "arm_compute/core/Error.h" |
Georgios Pinitas | cac13b1 | 2018-04-27 19:07:19 +0100 | [diff] [blame] | 33 | #include "arm_compute/core/Helpers.h" |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 34 | #include "arm_compute/core/ITensorInfo.h" |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 38 | namespace graph |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 39 | { |
| 40 | namespace backends |
| 41 | { |
| 42 | namespace 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 Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 50 | inline arm_compute::ITensorInfo *get_backing_tensor_info(arm_compute::graph::Tensor *tensor) |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 51 | { |
| 52 | return ((tensor == nullptr) || (tensor->handle() == nullptr)) ? nullptr : tensor->handle()->tensor().info(); |
| 53 | } |
| 54 | |
Manuel Bottini | d2048ce | 2018-10-23 17:00:42 +0100 | [diff] [blame] | 55 | /** Validates a Bounding Box Transform layer node |
| 56 | * |
| 57 | * @tparam BoundingBoxTransformLayer Bounding Box Transform layer function type |
| 58 | * |
| 59 | * @param[in] node Node to validate |
| 60 | * |
| 61 | * @return Status |
| 62 | */ |
| 63 | template <typename BoundingBoxTransformLayer> |
| 64 | Status validate_bounding_box_transform_layer(BoundingBoxTransformLayerNode &node) |
| 65 | { |
| 66 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating BoundingBoxTransformLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 67 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2); |
| 68 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 69 | |
| 70 | // Extract IO and info |
| 71 | arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); |
| 72 | arm_compute::ITensorInfo *deltas = get_backing_tensor_info(node.input(1)); |
| 73 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 74 | const BoundingBoxTransformInfo bbox_info = node.info(); |
| 75 | |
| 76 | return BoundingBoxTransformLayer::validate(input, output, deltas, bbox_info); |
| 77 | } |
| 78 | |
Georgios Pinitas | 087eaf6 | 2018-05-16 15:52:35 +0100 | [diff] [blame] | 79 | /** Validates a Channel Shuffle layer node |
| 80 | * |
| 81 | * @tparam ChannelShuffleLayer Channel Shuffle layer function type |
| 82 | * |
| 83 | * @param[in] node Node to validate |
| 84 | * |
| 85 | * @return Status |
| 86 | */ |
| 87 | template <typename ChannelShuffleLayer> |
| 88 | Status validate_channel_shuffle_layer(ChannelShuffleLayerNode &node) |
| 89 | { |
| 90 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ChannelShuffle node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 91 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 92 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 93 | |
| 94 | // Extract IO and info |
| 95 | arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); |
| 96 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 97 | const unsigned int num_groups = node.num_groups(); |
| 98 | |
| 99 | return ChannelShuffleLayer::validate(input, output, num_groups); |
| 100 | } |
| 101 | |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 102 | /** Validates a Convolution layer node |
| 103 | * |
| 104 | * @tparam ConvolutionLayer Default Convolution layer function type |
| 105 | * @tparam DirectConvolutionLayer Direct Convolution layer function type |
| 106 | * @tparam GEMMConvolutionLayer GEMM Convolution layer function type |
| 107 | * @tparam WinogradConvolutionLayer Winograd Convolution layer function type |
| 108 | * |
| 109 | * @param[in] node Node to validate |
| 110 | * |
| 111 | * @return Status |
| 112 | */ |
| 113 | template <typename ConvolutionLayer, typename DirectConvolutionLayer, typename GEMMConvolutionLayer, typename WinogradConvolutionLayer> |
| 114 | Status validate_convolution_layer(ConvolutionLayerNode &node) |
| 115 | { |
| 116 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 117 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3); |
| 118 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 119 | |
| 120 | // Extract IO and info |
Giorgio Arena | bb54e4e | 2018-04-05 17:20:34 +0100 | [diff] [blame] | 121 | arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); |
| 122 | arm_compute::ITensorInfo *weights = get_backing_tensor_info(node.input(1)); |
| 123 | arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2)); |
| 124 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 125 | |
| 126 | if(is_data_type_quantized_asymmetric(input->data_type())) |
| 127 | { |
| 128 | biases->set_data_type(DataType::S32); |
| 129 | } |
| 130 | |
| 131 | const PadStrideInfo conv_info = node.convolution_info(); |
| 132 | const ConvolutionMethod conv_algorithm = node.convolution_method(); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 133 | const bool fast_math = node.fast_math_hint() == FastMathHint::Enabled; |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 134 | const unsigned int num_groups = node.num_groups(); |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 135 | |
| 136 | // Validate function |
| 137 | Status status{}; |
| 138 | switch(conv_algorithm) |
| 139 | { |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 140 | case ConvolutionMethod::Direct: |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 141 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(num_groups != 1, "DirectConvolutionLayer does not support grouping!"); |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 142 | status = DirectConvolutionLayer::validate(input, weights, biases, output, conv_info); |
| 143 | break; |
| 144 | case ConvolutionMethod::GEMM: |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 145 | status = GEMMConvolutionLayer::validate(input, weights, biases, output, conv_info, |
| 146 | WeightsInfo(), Size2D(1, 1), ActivationLayerInfo(), num_groups); |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 147 | break; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 148 | case ConvolutionMethod::Winograd: |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 149 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(num_groups != 1, "WinogradConvolutionLayer does not support grouping!"); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 150 | status = WinogradConvolutionLayer::validate(input, weights, biases, output, conv_info, ActivationLayerInfo(), fast_math); |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 151 | break; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 152 | case ConvolutionMethod::Default: |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 153 | status = ConvolutionLayer::validate(input, weights, biases, output, conv_info, |
| 154 | WeightsInfo(), Size2D(1, 1), ActivationLayerInfo(), fast_math, num_groups); |
Georgios Pinitas | 54d6fae | 2018-05-10 15:50:14 +0100 | [diff] [blame] | 155 | break; |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 156 | default: |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 157 | ARM_COMPUTE_RETURN_ERROR_MSG("Unsupported convolution method"); |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | return status; |
| 161 | } |
| 162 | |
| 163 | /** Validates a Depthwise Convolution layer node |
| 164 | * |
| 165 | * @tparam DepthwiseConvolutionLayer Default Depthwise Convolution layer type |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 166 | * |
| 167 | * @param[in] node Node to validate |
| 168 | * |
| 169 | * @return Status |
| 170 | */ |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 171 | template <typename DepthwiseConvolutionLayer> |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 172 | Status validate_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node) |
| 173 | { |
| 174 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DepthwiseConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 175 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3); |
| 176 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 177 | |
| 178 | // Extract IO and info |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 179 | arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0)); |
| 180 | arm_compute::ITensorInfo *weights = detail::get_backing_tensor_info(node.input(1)); |
| 181 | arm_compute::ITensorInfo *biases = get_backing_tensor_info(node.input(2)); |
| 182 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 183 | |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 184 | const PadStrideInfo conv_info = node.convolution_info(); |
| 185 | const DepthwiseConvolutionMethod dwc_algorithm = node.depthwise_convolution_method(); |
| 186 | const int depth_multiplier = node.depth_multiplier(); |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 187 | |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 188 | // Validate function |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 189 | Status status{}; |
| 190 | switch(dwc_algorithm) |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 191 | { |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 192 | case DepthwiseConvolutionMethod::Default: |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 193 | case DepthwiseConvolutionMethod::Optimized3x3: |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame] | 194 | status = DepthwiseConvolutionLayer::validate(input, weights, biases, output, conv_info, depth_multiplier); |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 195 | break; |
| 196 | default: |
| 197 | ARM_COMPUTE_RETURN_ERROR_MSG("Unsupported depthwise convolution method"); |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 200 | return status; |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 201 | } |
Isabella Gottardi | cd4e9ab | 2019-11-05 17:50:27 +0000 | [diff] [blame] | 202 | /** Validates a dequantize layer node |
| 203 | * |
| 204 | * @tparam DequantizationLayer Dequantize layer type |
| 205 | * |
| 206 | * @param[in] node Node to validate |
| 207 | * |
| 208 | * @return Status |
| 209 | */ |
| 210 | template <typename DequantizationLayer> |
| 211 | Status validate_dequantization_layer(DequantizationLayerNode &node) |
| 212 | { |
| 213 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 214 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 215 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 216 | |
Isabella Gottardi | cd4e9ab | 2019-11-05 17:50:27 +0000 | [diff] [blame] | 217 | // Extract IO and info |
| 218 | arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); |
| 219 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 220 | |
| 221 | return DequantizationLayer::validate(input, output); |
| 222 | } |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 223 | /** Validates a detection output layer node |
| 224 | * |
| 225 | * @tparam DetectionOutputLayer DetectionOutput layer type |
| 226 | * |
| 227 | * @param[in] node Node to validate |
| 228 | * |
| 229 | * @return Status |
| 230 | */ |
| 231 | template <typename DetectionOutputLayer> |
| 232 | Status validate_detection_output_layer(DetectionOutputLayerNode &node) |
| 233 | { |
| 234 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionOutputLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 235 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3); |
| 236 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 237 | |
| 238 | // Extract IO and info |
| 239 | arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0)); |
| 240 | arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1)); |
| 241 | arm_compute::ITensorInfo *input2 = get_backing_tensor_info(node.input(2)); |
| 242 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 243 | const DetectionOutputLayerInfo detect_info = node.detection_output_info(); |
| 244 | |
| 245 | return DetectionOutputLayer::validate(input0, input1, input2, output, detect_info); |
| 246 | } |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 247 | /** Validates a detection post process layer node |
| 248 | * |
| 249 | * @tparam DetectionPostProcessLayer DetectionOutput layer type |
| 250 | * |
| 251 | * @param[in] node Node to validate |
| 252 | * |
| 253 | * @return Status |
| 254 | */ |
| 255 | template <typename DetectionPostProcessLayer> |
| 256 | Status validate_detection_post_process_layer(DetectionPostProcessLayerNode &node) |
| 257 | { |
| 258 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating DetectionPostProcessLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 259 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3); |
| 260 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 4); |
| 261 | |
| 262 | // Extract IO and info |
| 263 | arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0)); |
| 264 | arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1)); |
| 265 | arm_compute::ITensorInfo *input2 = get_backing_tensor_info(node.input(2)); |
| 266 | arm_compute::ITensorInfo *output0 = get_backing_tensor_info(node.output(0)); |
| 267 | arm_compute::ITensorInfo *output1 = get_backing_tensor_info(node.output(1)); |
| 268 | arm_compute::ITensorInfo *output2 = get_backing_tensor_info(node.output(2)); |
| 269 | arm_compute::ITensorInfo *output3 = get_backing_tensor_info(node.output(3)); |
| 270 | const DetectionPostProcessLayerInfo detect_info = node.detection_post_process_info(); |
| 271 | |
| 272 | return DetectionPostProcessLayer::validate(input0, input1, input2, output0, output1, output2, output3, detect_info); |
| 273 | } |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 274 | |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 275 | /** Validates a Generate Proposals layer node |
| 276 | * |
| 277 | * @tparam GenerateProposalsLayer Generate Proposals layer type |
| 278 | * |
| 279 | * @param[in] node Node to validate |
| 280 | * |
| 281 | * @return Status |
| 282 | */ |
| 283 | template <typename GenerateProposalsLayer> |
| 284 | Status validate_generate_proposals_layer(GenerateProposalsLayerNode &node) |
| 285 | { |
| 286 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating GenerateProposalsLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 287 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3); |
| 288 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 3); |
| 289 | |
| 290 | // Extract IO and info |
| 291 | arm_compute::ITensorInfo *scores = detail::get_backing_tensor_info(node.input(0)); |
| 292 | arm_compute::ITensorInfo *deltas = detail::get_backing_tensor_info(node.input(1)); |
| 293 | arm_compute::ITensorInfo *anchors = detail::get_backing_tensor_info(node.input(2)); |
| 294 | arm_compute::ITensorInfo *proposals = get_backing_tensor_info(node.output(0)); |
| 295 | arm_compute::ITensorInfo *scores_out = get_backing_tensor_info(node.output(1)); |
| 296 | arm_compute::ITensorInfo *num_valid_proposals = get_backing_tensor_info(node.output(2)); |
| 297 | const GenerateProposalsInfo info = node.info(); |
| 298 | |
| 299 | return GenerateProposalsLayer::validate(scores, deltas, anchors, proposals, scores_out, num_valid_proposals, info); |
| 300 | } |
| 301 | |
Michele Di Giorgio | 555d110 | 2018-09-12 13:51:59 +0100 | [diff] [blame] | 302 | /** Validates a NormalizePlanarYUV layer node |
| 303 | * |
| 304 | * @tparam NormalizePlanarYUVLayer layer type |
| 305 | * |
| 306 | * @param[in] node Node to validate |
| 307 | * |
| 308 | * @return Status |
| 309 | */ |
| 310 | template <typename NormalizePlanarYUVLayer> |
| 311 | Status validate_normalize_planar_yuv_layer(NormalizePlanarYUVLayerNode &node) |
| 312 | { |
| 313 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating NormalizePlanarYUVLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 314 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3); |
| 315 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 316 | |
| 317 | // Extract IO and info |
| 318 | arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0)); |
| 319 | arm_compute::ITensorInfo *mean = detail::get_backing_tensor_info(node.input(1)); |
| 320 | arm_compute::ITensorInfo *std = detail::get_backing_tensor_info(node.input(2)); |
| 321 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 322 | |
| 323 | // Validate function |
| 324 | return NormalizePlanarYUVLayer::validate(input, output, mean, std); |
| 325 | } |
Michele Di Giorgio | 4bb1733 | 2018-09-26 13:56:51 +0100 | [diff] [blame] | 326 | |
| 327 | /** Validates a pad layer node |
| 328 | * |
| 329 | * @tparam PadLayer Pad layer type |
| 330 | * |
| 331 | * @param[in] node Node to validate |
| 332 | * |
| 333 | * @return Status |
| 334 | */ |
| 335 | template <typename PadLayer> |
| 336 | Status validate_pad_layer(PadLayerNode &node) |
| 337 | { |
| 338 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PadLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 339 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 340 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 341 | |
| 342 | // Extract IO and info |
| 343 | arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); |
| 344 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 345 | const PaddingList &padding = node.padding(); |
| 346 | |
| 347 | return PadLayer::validate(input, output, padding); |
| 348 | } |
| 349 | |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 350 | /** Validates a permute layer node |
| 351 | * |
| 352 | * @tparam PermuteLayer Permute layer type |
| 353 | * |
| 354 | * @param[in] node Node to validate |
| 355 | * |
| 356 | * @return Status |
| 357 | */ |
| 358 | template <typename PermuteLayer> |
| 359 | Status validate_permute_layer(PermuteLayerNode &node) |
| 360 | { |
| 361 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PermuteLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 362 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 363 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 364 | |
| 365 | // Extract IO and info |
| 366 | arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); |
| 367 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 368 | const PermutationVector &perm = node.permutation_vector(); |
| 369 | |
| 370 | return PermuteLayer::validate(input, output, perm); |
| 371 | } |
Georgios Pinitas | f8c4749 | 2020-02-04 17:39:59 +0000 | [diff] [blame] | 372 | |
| 373 | /** Validates a PRelu layer node |
| 374 | * |
| 375 | * @tparam PReluLayer PRelu layer type |
| 376 | * |
| 377 | * @param[in] node Node to validate |
| 378 | * |
| 379 | * @return Status |
| 380 | */ |
| 381 | template <typename PReluLayer> |
| 382 | Status validate_prelu_layer(PReluLayerNode &node) |
| 383 | { |
| 384 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PRelu node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 385 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2); |
| 386 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 387 | |
| 388 | // Extract IO and info |
| 389 | arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); |
| 390 | arm_compute::ITensorInfo *alpha = get_backing_tensor_info(node.input(1)); |
| 391 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 392 | |
| 393 | return PReluLayer::validate(input, alpha, output); |
| 394 | } |
| 395 | |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 396 | /** Validates a priorbox layer node |
| 397 | * |
| 398 | * @tparam PriorBoxLayer PriorBox layer type |
| 399 | * |
| 400 | * @param[in] node Node to validate |
| 401 | * |
| 402 | * @return Status |
| 403 | */ |
| 404 | template <typename PriorBoxLayer> |
| 405 | Status validate_priorbox_layer(PriorBoxLayerNode &node) |
| 406 | { |
| 407 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating PriorBoxLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 408 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2); |
| 409 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 410 | |
| 411 | // Extract IO and info |
| 412 | arm_compute::ITensorInfo *input0 = get_backing_tensor_info(node.input(0)); |
| 413 | arm_compute::ITensorInfo *input1 = get_backing_tensor_info(node.input(1)); |
| 414 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 415 | const PriorBoxLayerInfo prior_info = node.priorbox_info(); |
| 416 | |
| 417 | return PriorBoxLayer::validate(input0, input1, output, prior_info); |
| 418 | } |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 419 | |
Isabella Gottardi | 3db1ba9 | 2019-05-17 12:35:20 +0100 | [diff] [blame] | 420 | /** Validates a Quantization layer node |
| 421 | * |
| 422 | * @tparam QuantizationLayer Quantization layer type |
| 423 | * |
| 424 | * @param[in] node Node to validate |
| 425 | * |
| 426 | * @return Status |
| 427 | */ |
| 428 | template <typename QuantizationLayer> |
| 429 | Status validate_quantization_layer(QuantizationLayerNode &node) |
| 430 | { |
| 431 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating QuantizationLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 432 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 433 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 434 | |
| 435 | // Extract input and output |
| 436 | arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0)); |
| 437 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 438 | |
| 439 | // Validate function |
| 440 | return QuantizationLayer::validate(input, output); |
| 441 | } |
| 442 | |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 443 | /** Validates a Reorg layer node |
| 444 | * |
| 445 | * @tparam ReorgLayer Reorg layer type |
| 446 | * |
| 447 | * @param[in] node Node to validate |
| 448 | * |
| 449 | * @return Status |
| 450 | */ |
| 451 | template <typename ReorgLayer> |
| 452 | Status validate_reorg_layer(ReorgLayerNode &node) |
| 453 | { |
| 454 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReorgLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 455 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 456 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 457 | |
| 458 | // Extract input and output |
| 459 | arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0)); |
| 460 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 461 | |
| 462 | // Validate function |
| 463 | return ReorgLayer::validate(input, output, node.stride()); |
| 464 | } |
Michalis Spyrou | 96f6769 | 2018-09-13 11:39:28 +0100 | [diff] [blame] | 465 | |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 466 | /** Validates a Reshape layer node |
| 467 | * |
| 468 | * @tparam ReshapeLayer Reshape layer type |
| 469 | * |
| 470 | * @param[in] node Node to validate |
| 471 | * |
| 472 | * @return Status |
| 473 | */ |
| 474 | template <typename ReshapeLayer> |
| 475 | Status validate_reshape_layer(ReshapeLayerNode &node) |
| 476 | { |
| 477 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ReshapeLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 478 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 479 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 480 | |
| 481 | // Extract input and output |
| 482 | arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0)); |
| 483 | arm_compute::ITensorInfo *output = detail::get_backing_tensor_info(node.output(0)); |
| 484 | |
| 485 | // Validate function |
| 486 | return ReshapeLayer::validate(input, output); |
| 487 | } |
| 488 | |
Manuel Bottini | 3f9d4d7 | 2018-10-19 14:04:42 +0100 | [diff] [blame] | 489 | /** Validates a ROI Align layer node |
| 490 | * |
| 491 | * @tparam ROIAlignLayer ROIAlign layer type |
| 492 | * |
| 493 | * @param[in] node Node to validate |
| 494 | * |
| 495 | * @return Status |
| 496 | */ |
| 497 | template <typename ROIAlignLayer> |
| 498 | Status validate_roi_align_layer(ROIAlignLayerNode &node) |
| 499 | { |
| 500 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ROIAlignLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 501 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2); |
| 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 *rois = detail::get_backing_tensor_info(node.input(1)); |
| 507 | arm_compute::ITensorInfo *output = detail::get_backing_tensor_info(node.output(0)); |
| 508 | const ROIPoolingLayerInfo &pool_info = node.pooling_info(); |
| 509 | |
| 510 | // Validate function |
| 511 | return ROIAlignLayer::validate(input, rois, output, pool_info); |
| 512 | } |
| 513 | |
Michele Di Giorgio | c30b668 | 2018-09-12 17:44:08 +0100 | [diff] [blame] | 514 | /** Validates a Slice layer node |
| 515 | * |
| 516 | * @tparam SliceLayer Slice layer function type |
| 517 | * |
| 518 | * @param[in] node Node to validate |
| 519 | * |
| 520 | * @return Status |
| 521 | */ |
| 522 | template <typename SliceLayer> |
| 523 | Status validate_slice_layer(SliceLayerNode &node) |
| 524 | { |
| 525 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating Slice node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 526 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 527 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 528 | |
| 529 | // Extract IO and info |
| 530 | arm_compute::ITensorInfo *input = get_backing_tensor_info(node.input(0)); |
| 531 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 532 | const Coordinates starts = node.starts(); |
| 533 | const Coordinates ends = node.ends(); |
| 534 | |
| 535 | return SliceLayer::validate(input, output, starts, ends); |
| 536 | } |
| 537 | |
Michalis Spyrou | 4e1c3f3 | 2018-09-20 17:14:03 +0100 | [diff] [blame] | 538 | /** Validates a Upsample layer node |
| 539 | * |
| 540 | * @tparam UpsampleLayer Upsample layer type |
| 541 | * |
| 542 | * @param[in] node Node to validate |
| 543 | * |
| 544 | * @return Status |
| 545 | */ |
| 546 | template <typename UpsampleLayer> |
| 547 | Status validate_upsample_layer(UpsampleLayerNode &node) |
| 548 | { |
| 549 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating UpsampleLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 550 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 551 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 552 | |
| 553 | // Extract input and output |
| 554 | arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0)); |
| 555 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 556 | |
| 557 | // Validate function |
| 558 | return UpsampleLayer::validate(input, output, node.info(), node.upsampling_policy()); |
| 559 | } |
Michalis Spyrou | 96f6769 | 2018-09-13 11:39:28 +0100 | [diff] [blame] | 560 | /** Validates a YOLO layer node |
| 561 | * |
| 562 | * @tparam YOLOLayer YOLO layer type |
| 563 | * |
| 564 | * @param[in] node Node to validate |
| 565 | * |
| 566 | * @return Status |
| 567 | */ |
| 568 | template <typename YOLOLayer> |
| 569 | Status validate_yolo_layer(YOLOLayerNode &node) |
| 570 | { |
| 571 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating YOLOLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 572 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 573 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 574 | |
| 575 | // Extract input and output |
| 576 | arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0)); |
| 577 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 578 | |
| 579 | // Validate function |
| 580 | return YOLOLayer::validate(input, output, node.activation_info(), node.num_classes()); |
| 581 | } |
Sheri Zhang | 16dddd2 | 2020-05-27 15:03:48 +0100 | [diff] [blame] | 582 | /** Validates a element-wise layer node |
| 583 | * |
| 584 | * @param[in] node Node to validate |
| 585 | * |
| 586 | * @return Status |
| 587 | */ |
| 588 | template <typename EltwiseLayerFunctions> |
| 589 | Status validate_eltwise_Layer(EltwiseLayerNode &node) |
| 590 | { |
| 591 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 592 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 2); |
| 593 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 594 | |
| 595 | // Extract input and output |
| 596 | const arm_compute::ITensorInfo *input1 = detail::get_backing_tensor_info(node.input(0)); |
| 597 | const arm_compute::ITensorInfo *input2 = detail::get_backing_tensor_info(node.input(1)); |
| 598 | const arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 599 | const EltwiseOperation eltwise_op = node.eltwise_operation(); |
| 600 | const ConvertPolicy convert_policy = node.convert_policy(); |
| 601 | const RoundingPolicy round_policy = node.rounding_policy(); |
| 602 | const ActivationLayerInfo act_info = node.fused_activation(); |
| 603 | const QuantizationInfo quant_info = node.output_quant_info(); |
| 604 | const float scale = (quant_info.scale().empty()) ? 1.0f : quant_info.scale()[0]; |
| 605 | |
| 606 | // Validate function |
| 607 | if(eltwise_op == EltwiseOperation::Add) |
| 608 | { |
| 609 | return EltwiseLayerFunctions::ArithmeticAddition::validate(input1, input2, output, convert_policy, act_info); |
| 610 | } |
| 611 | else if(eltwise_op == EltwiseOperation::Sub) |
| 612 | { |
| 613 | return EltwiseLayerFunctions::ArithmeticSubtraction::validate(input1, input2, output, convert_policy, act_info); |
| 614 | } |
| 615 | else if(eltwise_op == EltwiseOperation::Mul) |
| 616 | { |
| 617 | return EltwiseLayerFunctions::PixelWiseMultiplication::validate(input1, input2, output, scale, convert_policy, round_policy, act_info); |
| 618 | } |
| 619 | else |
| 620 | { |
| 621 | ARM_COMPUTE_ERROR("Unsupported element-wise operation!"); |
| 622 | } |
| 623 | return Status{}; |
| 624 | } |
| 625 | /** Validates a unary element-wise layer node |
| 626 | * |
| 627 | * @param[in] node Node to validate |
| 628 | * |
| 629 | * @return Status |
| 630 | */ |
| 631 | template <typename UnaryEltwiseLayerFunctions> |
| 632 | Status validate_unary_eltwise_layer(UnaryEltwiseLayerNode &node) |
| 633 | { |
| 634 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 635 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 1); |
| 636 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 637 | |
| 638 | // Extract input and output |
| 639 | arm_compute::ITensorInfo *input = detail::get_backing_tensor_info(node.input(0)); |
| 640 | arm_compute::ITensorInfo *output = get_backing_tensor_info(node.output(0)); |
| 641 | const UnaryEltwiseOperation eltwise_op = node.eltwise_descriptor().op; |
| 642 | |
| 643 | // Validate function |
| 644 | if(eltwise_op == UnaryEltwiseOperation::Exp) |
| 645 | { |
| 646 | return UnaryEltwiseLayerFunctions::ExpLayer::validate(input, output); |
| 647 | } |
| 648 | else |
| 649 | { |
| 650 | ARM_COMPUTE_ERROR("Unsupported unary element-wise operation!"); |
| 651 | } |
| 652 | |
| 653 | return Status{}; |
| 654 | } |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 655 | } // namespace detail |
| 656 | } // namespace backends |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 657 | } // namespace graph |
Georgios Pinitas | 2870516 | 2018-03-21 20:10:53 +0000 | [diff] [blame] | 658 | } // namespace arm_compute |
| 659 | |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 660 | #endif /* ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_VALIDATE_HELPERS_H */ |