blob: a83c1a3506d964ed5fd4d5e269419d90163bb224 [file] [log] [blame]
Georgios Pinitasfbb80542018-03-27 17:15:49 +01001/*
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +01002 * Copyright (c) 2018-2020 Arm Limited.
Georgios Pinitasfbb80542018-03-27 17:15:49 +01003 *
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 Pinitasd9eb2752018-04-03 13:44:29 +010024#include "arm_compute/graph/backends/GLES/GCNodeValidator.h"
Georgios Pinitasfbb80542018-03-27 17:15:49 +010025
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010026#include "arm_compute/graph/backends/ValidateHelpers.h"
27#include "arm_compute/graph/nodes/Nodes.h"
Georgios Pinitasfbb80542018-03-27 17:15:49 +010028
Georgios Pinitasfbb80542018-03-27 17:15:49 +010029#include "arm_compute/runtime/GLES_COMPUTE/GCFunctions.h"
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010030#include "support/Cast.h"
Georgios Pinitasfbb80542018-03-27 17:15:49 +010031
32using namespace arm_compute::utils::cast;
33
34namespace arm_compute
35{
Georgios Pinitasd9eb2752018-04-03 13:44:29 +010036namespace graph
Georgios Pinitasfbb80542018-03-27 17:15:49 +010037{
38namespace backends
39{
40namespace
41{
42/** Validates a Depthwise Convolution layer node
43 *
44 * @param[in] node Node to validate
45 *
46 * @return Status
47 */
48Status 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 Pinitasfbb80542018-03-27 17:15:49 +010061
62 return Status{};
63}
64/** Validates a Convolution layer node
65 *
66 * @param[in] node Node to validate
67 *
68 * @return Status
69 */
70Status 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 Pinitas2a2db592018-08-15 12:14:46 +010082 ARM_COMPUTE_RETURN_ERROR_ON_MSG(node.num_groups() != 1, "Grouping is not supported by ConvolutionLayer!");
Georgios Pinitase2220552018-07-20 13:23:44 +010083 if(conv_algorithm == ConvolutionMethod::Direct)
Georgios Pinitasfbb80542018-03-27 17:15:49 +010084 {
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 Pinitas2a2db592018-08-15 12:14:46 +010088 ARM_COMPUTE_RETURN_ERROR_ON_MSG(!(is_square && is_direct && is_correct_stride), "Direct convolution is not supported for given configuration");
Georgios Pinitasfbb80542018-03-27 17:15:49 +010089 }
90
91 return Status{};
92}
93} // namespace
94
95Status 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 Bottinid2048ce2018-10-23 17:00:42 +0100105 case NodeType::BoundingBoxTransformLayer:
106 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : BoundingBoxTransformLayer");
Georgios Pinitas57c48242018-08-02 13:41:49 +0100107 case NodeType::ChannelShuffleLayer:
108 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ChannelShuffleLayer");
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100109 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 Gottardicd4e9ab2019-11-05 17:50:27 +0000113 case NodeType::DequantizationLayer:
114 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : DequantizationLayer");
Isabella Gottardi7234ed82018-11-27 08:51:10 +0000115 case NodeType::DetectionOutputLayer:
116 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : DetectionOutputLayer");
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000117 case NodeType::DetectionPostProcessLayer:
118 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : DetectionPostProcessLayer");
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100119 case NodeType::FlattenLayer:
Georgios Pinitasdce7bef2018-07-02 18:20:40 +0100120 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : FlattenLayer");
Manuel Bottini5209be52019-02-13 16:34:56 +0000121 case NodeType::GenerateProposalsLayer:
122 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : GenerateProposalsLayer");
Michele Di Giorgio555d1102018-09-12 13:51:59 +0100123 case NodeType::NormalizePlanarYUVLayer:
124 return detail::validate_normalize_planar_yuv_layer<GCNormalizePlanarYUVLayer>(*polymorphic_downcast<NormalizePlanarYUVLayerNode *>(node));
Michele Di Giorgio4bb17332018-09-26 13:56:51 +0100125 case NodeType::PadLayer:
126 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : PadLayer");
Georgios Pinitas57c48242018-08-02 13:41:49 +0100127 case NodeType::PermuteLayer:
128 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : PermuteLayer");
Pablo Tello32521432018-11-15 14:43:10 +0000129 case NodeType::PriorBoxLayer:
130 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : PriorBoxLayer");
Isabella Gottardi3db1ba92019-05-17 12:35:20 +0100131 case NodeType::QuantizationLayer:
132 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : QuantizationLayer");
Michele Di Giorgio555d1102018-09-12 13:51:59 +0100133 case NodeType::ReorgLayer:
134 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ReorgLayer");
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100135 case NodeType::ReshapeLayer:
Georgios Pinitasdce7bef2018-07-02 18:20:40 +0100136 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ReshapeLayer");
Manuel Bottini3f9d4d72018-10-19 14:04:42 +0100137 case NodeType::ROIAlignLayer:
138 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : ROIAlignLayer");
Michele Di Giorgioc30b6682018-09-12 17:44:08 +0100139 case NodeType::SliceLayer:
140 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation : SliceLayer");
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100141 default:
142 return Status{};
143 }
144}
145} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100146} // namespace graph
Michele Di Giorgio555d1102018-09-12 13:51:59 +0100147} // namespace arm_compute