Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 1 | /* |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [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 | */ |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 24 | #include "arm_compute/graph/backends/GLES/GCNodeValidator.h" |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 25 | |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 26 | #include "arm_compute/graph/backends/ValidateHelpers.h" |
| 27 | #include "arm_compute/graph/nodes/Nodes.h" |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 28 | |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/GLES_COMPUTE/GCFunctions.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 30 | #include "support/Cast.h" |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 31 | |
| 32 | using namespace arm_compute::utils::cast; |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 36 | namespace graph |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 37 | { |
| 38 | namespace backends |
| 39 | { |
| 40 | namespace |
| 41 | { |
| 42 | /** Validates a Depthwise Convolution layer node |
| 43 | * |
| 44 | * @param[in] node Node to validate |
| 45 | * |
| 46 | * @return Status |
| 47 | */ |
| 48 | Status validate_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node) |
| 49 | { |
| 50 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating GCDepthwiseConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 51 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3); |
| 52 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 53 | |
| 54 | // Extract IO and info |
| 55 | arm_compute::ITensorInfo *weights = detail::get_backing_tensor_info(node.input(1)); |
| 56 | ARM_COMPUTE_ERROR_ON(weights == nullptr); |
| 57 | |
| 58 | // TODO (geopin01) : Switch when validation is implemented |
| 59 | // Validate function |
| 60 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->tensor_shape().x() != 3 && weights->tensor_shape().y() != 3, "Unsupported depthwise convolution"); |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 61 | |
| 62 | return Status{}; |
| 63 | } |
| 64 | /** Validates a Convolution layer node |
| 65 | * |
| 66 | * @param[in] node Node to validate |
| 67 | * |
| 68 | * @return Status |
| 69 | */ |
| 70 | Status validate_convolution_layer(ConvolutionLayerNode &node) |
| 71 | { |
| 72 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 73 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3); |
| 74 | ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1); |
| 75 | |
| 76 | // Extract IO and info |
| 77 | arm_compute::ITensorInfo *weights = detail::get_backing_tensor_info(node.input(1)); |
| 78 | const PadStrideInfo conv_info = node.convolution_info(); |
| 79 | const ConvolutionMethod conv_algorithm = node.convolution_method(); |
| 80 | |
| 81 | // Validate function |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 82 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(node.num_groups() != 1, "Grouping is not supported by ConvolutionLayer!"); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 83 | if(conv_algorithm == ConvolutionMethod::Direct) |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 84 | { |
| 85 | bool is_square = weights->tensor_shape().x() == weights->tensor_shape().y(); |
| 86 | bool is_direct = (weights->tensor_shape().x() == 1) || (weights->tensor_shape().x() == 3) || (weights->tensor_shape().x() == 5); |
| 87 | bool is_correct_stride = (conv_info.stride().first) <= 2 && (conv_info.stride().second <= 2); |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 88 | ARM_COMPUTE_RETURN_ERROR_ON_MSG(!(is_square && is_direct && is_correct_stride), "Direct convolution is not supported for given configuration"); |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | return Status{}; |
| 92 | } |
| 93 | } // namespace |
| 94 | |
| 95 | Status GCNodeValidator::validate(INode *node) |
| 96 | { |
| 97 | if(node == nullptr) |
| 98 | { |
| 99 | return Status{}; |
| 100 | } |
| 101 | |
| 102 | NodeType type = node->type(); |
| 103 | switch(type) |
| 104 | { |
Manuel Bottini | d2048ce | 2018-10-23 17:00:42 +0100 | [diff] [blame] | 105 | case NodeType::BoundingBoxTransformLayer: |
| 106 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : BoundingBoxTransformLayer"); |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 107 | case NodeType::ChannelShuffleLayer: |
| 108 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ChannelShuffleLayer"); |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 109 | case NodeType::ConvolutionLayer: |
| 110 | return validate_convolution_layer(*polymorphic_downcast<ConvolutionLayerNode *>(node)); |
| 111 | case NodeType::DepthwiseConvolutionLayer: |
| 112 | return validate_depthwise_convolution_layer(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node)); |
Isabella Gottardi | cd4e9ab | 2019-11-05 17:50:27 +0000 | [diff] [blame] | 113 | case NodeType::DequantizationLayer: |
| 114 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : DequantizationLayer"); |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 115 | case NodeType::DetectionOutputLayer: |
| 116 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : DetectionOutputLayer"); |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 117 | case NodeType::DetectionPostProcessLayer: |
| 118 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : DetectionPostProcessLayer"); |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 119 | case NodeType::FlattenLayer: |
Georgios Pinitas | dce7bef | 2018-07-02 18:20:40 +0100 | [diff] [blame] | 120 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : FlattenLayer"); |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 121 | case NodeType::GenerateProposalsLayer: |
| 122 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : GenerateProposalsLayer"); |
Michele Di Giorgio | 555d110 | 2018-09-12 13:51:59 +0100 | [diff] [blame] | 123 | case NodeType::NormalizePlanarYUVLayer: |
| 124 | return detail::validate_normalize_planar_yuv_layer<GCNormalizePlanarYUVLayer>(*polymorphic_downcast<NormalizePlanarYUVLayerNode *>(node)); |
Michele Di Giorgio | 4bb1733 | 2018-09-26 13:56:51 +0100 | [diff] [blame] | 125 | case NodeType::PadLayer: |
| 126 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : PadLayer"); |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 127 | case NodeType::PermuteLayer: |
| 128 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : PermuteLayer"); |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 129 | case NodeType::PriorBoxLayer: |
| 130 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : PriorBoxLayer"); |
Isabella Gottardi | 3db1ba9 | 2019-05-17 12:35:20 +0100 | [diff] [blame] | 131 | case NodeType::QuantizationLayer: |
| 132 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : QuantizationLayer"); |
Michele Di Giorgio | 555d110 | 2018-09-12 13:51:59 +0100 | [diff] [blame] | 133 | case NodeType::ReorgLayer: |
| 134 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ReorgLayer"); |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 135 | case NodeType::ReshapeLayer: |
Georgios Pinitas | dce7bef | 2018-07-02 18:20:40 +0100 | [diff] [blame] | 136 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ReshapeLayer"); |
Manuel Bottini | 3f9d4d7 | 2018-10-19 14:04:42 +0100 | [diff] [blame] | 137 | case NodeType::ROIAlignLayer: |
| 138 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ROIAlignLayer"); |
Michele Di Giorgio | c30b668 | 2018-09-12 17:44:08 +0100 | [diff] [blame] | 139 | case NodeType::SliceLayer: |
| 140 | return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : SliceLayer"); |
Georgios Pinitas | fbb8054 | 2018-03-27 17:15:49 +0100 | [diff] [blame] | 141 | default: |
| 142 | return Status{}; |
| 143 | } |
| 144 | } |
| 145 | } // namespace backends |
Georgios Pinitas | d9eb275 | 2018-04-03 13:44:29 +0100 | [diff] [blame] | 146 | } // namespace graph |
Michele Di Giorgio | 555d110 | 2018-09-12 13:51:59 +0100 | [diff] [blame] | 147 | } // namespace arm_compute |