blob: 1e89265382793c4db241e80465e728c388599fc8 [file] [log] [blame]
Georgios Pinitasfbb80542018-03-27 17:15:49 +01001/*
2 * Copyright (c) 2018 ARM Limited.
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 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
29#include "arm_compute/core/utils/misc/Cast.h"
30#include "arm_compute/runtime/GLES_COMPUTE/GCFunctions.h"
31
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");
61 node.set_depthwise_convolution_method(DepthwiseConvolutionMethod::OPTIMIZED_3x3);
62
63 return Status{};
64}
65/** Validates a Convolution layer node
66 *
67 * @param[in] node Node to validate
68 *
69 * @return Status
70 */
71Status validate_convolution_layer(ConvolutionLayerNode &node)
72{
73 ARM_COMPUTE_LOG_GRAPH_VERBOSE("Validating ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
74 ARM_COMPUTE_RETURN_ERROR_ON(node.num_inputs() != 3);
75 ARM_COMPUTE_RETURN_ERROR_ON(node.num_outputs() != 1);
76
77 // Extract IO and info
78 arm_compute::ITensorInfo *weights = detail::get_backing_tensor_info(node.input(1));
79 const PadStrideInfo conv_info = node.convolution_info();
80 const ConvolutionMethod conv_algorithm = node.convolution_method();
81
82 // Validate function
83 if(conv_algorithm == ConvolutionMethod::DIRECT)
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);
88 if(!(is_square && is_direct && is_correct_stride))
89 {
90 node.set_convolution_method(ConvolutionMethod::DEFAULT);
91 }
92 }
93
94 return Status{};
95}
96} // namespace
97
98Status GCNodeValidator::validate(INode *node)
99{
100 if(node == nullptr)
101 {
102 return Status{};
103 }
104
105 NodeType type = node->type();
106 switch(type)
107 {
108 case NodeType::ConvolutionLayer:
109 return validate_convolution_layer(*polymorphic_downcast<ConvolutionLayerNode *>(node));
110 case NodeType::DepthwiseConvolutionLayer:
111 return validate_depthwise_convolution_layer(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
112 case NodeType::FlattenLayer:
113 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation");
114 case NodeType::ReshapeLayer:
115 return ARM_COMPUTE_CREATE_ERROR(arm_compute::ErrorCode::RUNTIME_ERROR, "Unsupported operation");
116 default:
117 return Status{};
118 }
119}
120} // namespace backends
Georgios Pinitasd9eb2752018-04-03 13:44:29 +0100121} // namespace graph
Georgios Pinitasfbb80542018-03-27 17:15:49 +0100122} // namespace arm_compute