Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 1 | /* |
Giuseppe Rossini | bb365de | 2019-02-15 10:24:47 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +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 | */ |
| 24 | #ifndef __ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_FUNCTION_HELPERS_H__ |
| 25 | #define __ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_FUNCTION_HELPERS_H__ |
| 26 | |
| 27 | #include "arm_compute/graph/Logger.h" |
| 28 | #include "arm_compute/graph/Tensor.h" |
| 29 | #include "arm_compute/graph/TypePrinter.h" |
| 30 | #include "arm_compute/graph/Types.h" |
Georgios Pinitas | 9e4824c | 2019-04-12 13:15:58 +0100 | [diff] [blame] | 31 | #include "arm_compute/graph/Utils.h" |
giuros01 | acce504 | 2019-02-21 17:32:34 +0000 | [diff] [blame] | 32 | #include "arm_compute/graph/backends/FusedConvolutionBatchNormalizationFunction.h" |
Manuel Bottini | bffb41e | 2019-06-20 16:00:27 +0100 | [diff] [blame] | 33 | #include "arm_compute/graph/backends/FusedDepthwiseConvolutionBatchNormalizationFunction.h" |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 34 | #include "arm_compute/graph/backends/Utils.h" |
| 35 | #include "arm_compute/graph/nodes/Nodes.h" |
| 36 | |
| 37 | #include "arm_compute/core/Error.h" |
| 38 | #include "arm_compute/core/Helpers.h" |
| 39 | #include "arm_compute/core/ITensorInfo.h" |
| 40 | #include "arm_compute/core/utils/misc/Cast.h" |
| 41 | |
| 42 | namespace arm_compute |
| 43 | { |
| 44 | namespace graph |
| 45 | { |
| 46 | namespace backends |
| 47 | { |
| 48 | namespace detail |
| 49 | { |
| 50 | /** Returns backing tensor of a given tensor |
| 51 | * |
| 52 | * @tparam TargetInfo Target information |
| 53 | * |
| 54 | * @param[in] tensor Tensor to extract the backing tensor from |
| 55 | * |
| 56 | * @return Backing tensor if present else nullptr |
| 57 | */ |
| 58 | template <typename TargetInfo> |
| 59 | typename TargetInfo::TensorType *get_backing_tensor(arm_compute::graph::Tensor *tensor) |
| 60 | { |
| 61 | typename TargetInfo::TensorType *backing_tensor = nullptr; |
| 62 | if(tensor != nullptr) |
| 63 | { |
| 64 | ARM_COMPUTE_ERROR_ON(tensor->desc().target != TargetInfo::TargetType); |
| 65 | // Get backing tensor handle |
| 66 | ITensorHandle *tensor_handle = tensor->handle(); |
| 67 | // Get backing tensor |
| 68 | backing_tensor = (tensor_handle != nullptr) ? arm_compute::utils::cast::polymorphic_cast<typename TargetInfo::TensorType *>(&tensor_handle->tensor()) : nullptr; |
| 69 | } |
| 70 | |
| 71 | return backing_tensor; |
| 72 | } |
| 73 | |
| 74 | template <typename TargetInfo> |
| 75 | void validate_node(const INode &node, size_t num_expected_inputs, size_t num_expected_outputs) |
| 76 | { |
| 77 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating " << node.type() |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 78 | << " Target: " << TargetInfo::TargetType |
| 79 | << " ID: " << node.id() |
| 80 | << node.name() |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 81 | << std::endl); |
| 82 | |
| 83 | ARM_COMPUTE_ERROR_ON(TargetInfo::TargetType != node.assigned_target()); |
| 84 | ARM_COMPUTE_ERROR_ON(node.num_inputs() != num_expected_inputs); |
| 85 | ARM_COMPUTE_ERROR_ON(node.num_outputs() != num_expected_outputs); |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 86 | ARM_COMPUTE_UNUSED(node, num_expected_inputs, num_expected_outputs); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** Creates a backend activation layer function |
| 90 | * |
| 91 | * @tparam ActivationLayerFunction Backend activation function |
| 92 | * @tparam TargetInfo Target-specific information |
| 93 | * |
| 94 | * @param[in] node Node to create the backend function for |
| 95 | * |
| 96 | * @return Backend activation layer function |
| 97 | */ |
| 98 | template <typename ActivationLayerFunction, typename TargetInfo> |
| 99 | std::unique_ptr<IFunction> create_activation_layer(ActivationLayerNode &node) |
| 100 | { |
| 101 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 102 | |
| 103 | // Extract IO and info |
| 104 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 105 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 106 | const ActivationLayerInfo act_info = node.activation_info(); |
| 107 | |
| 108 | // Create function |
| 109 | auto func = support::cpp14::make_unique<ActivationLayerFunction>(); |
| 110 | func->configure(input, output, act_info); |
| 111 | |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 112 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 113 | << node.name() |
| 114 | << " Type: " << node.type() |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 115 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 116 | << " Data Type: " << input->info()->data_type() |
| 117 | << " Shape: " << input->info()->tensor_shape() |
| 118 | << " Activation function: " << act_info.activation() |
| 119 | << " a: " << act_info.a() |
| 120 | << " b: " << act_info.b() |
| 121 | << " InPlace : " << is_in_place_operation(input, output) |
| 122 | << std::endl); |
| 123 | |
| 124 | return std::move(func); |
| 125 | } |
| 126 | |
| 127 | /** Create a backend batch normalization layer function |
| 128 | * |
| 129 | * @tparam BatchNormalizationLayerFunction Backend batch normalization function |
| 130 | * @tparam TargetInfo Target-specific information |
| 131 | * |
| 132 | * @param[in] node Node to create the backend function for |
| 133 | * |
| 134 | * @return Backend batch normalization layer function |
| 135 | */ |
| 136 | template <typename BatchNormalizationLayerFunction, typename TargetInfo> |
| 137 | std::unique_ptr<IFunction> create_batch_normalization_layer(BatchNormalizationLayerNode &node) |
| 138 | { |
| 139 | validate_node<TargetInfo>(node, 5 /* expected inputs */, 1 /* expected outputs */); |
| 140 | |
| 141 | // Extract IO and info |
giuros01 | acce504 | 2019-02-21 17:32:34 +0000 | [diff] [blame] | 142 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 143 | typename TargetInfo::TensorType *mean = get_backing_tensor<TargetInfo>(node.input(1)); |
| 144 | typename TargetInfo::TensorType *var = get_backing_tensor<TargetInfo>(node.input(2)); |
| 145 | typename TargetInfo::TensorType *beta = get_backing_tensor<TargetInfo>(node.input(3)); |
| 146 | typename TargetInfo::TensorType *gamma = get_backing_tensor<TargetInfo>(node.input(4)); |
| 147 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 148 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 149 | const float epsilon = node.epsilon(); |
| 150 | const ActivationLayerInfo fused_act = node.fused_activation(); |
| 151 | |
| 152 | // Create and configure function |
| 153 | auto func = support::cpp14::make_unique<BatchNormalizationLayerFunction>(); |
| 154 | func->configure(input, output, mean, var, beta, gamma, epsilon, fused_act); |
| 155 | |
| 156 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 157 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 158 | << node.name() |
| 159 | << " Type: " << node.type() |
| 160 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 161 | << " Data Type: " << input->info()->data_type() |
| 162 | << " Shape: " << input->info()->tensor_shape() |
| 163 | << " Epsilon: " << epsilon << " " |
| 164 | << (fused_act.enabled() ? to_string(fused_act.activation()) : "") |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 165 | << " InPlace: " << is_in_place_operation(input, output) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 166 | << std::endl); |
| 167 | |
| 168 | return std::move(func); |
| 169 | } |
| 170 | |
giuros01 | acce504 | 2019-02-21 17:32:34 +0000 | [diff] [blame] | 171 | /** Create a backend batch normalization layer function |
| 172 | * |
| 173 | * @tparam BatchNormalizationLayerFunction Backend batch normalization function |
| 174 | * @tparam TargetInfo Target-specific information |
| 175 | * |
| 176 | * @param[in] node Node to create the backend function for |
| 177 | * |
| 178 | * @return Backend batch normalization layer function |
| 179 | */ |
| 180 | template <typename FusedLayerTypes, typename TargetInfo> |
| 181 | std::unique_ptr<IFunction> create_fused_convolution_batch_normalization_layer(FusedConvolutionBatchNormalizationNode &node) |
| 182 | { |
| 183 | validate_node<TargetInfo>(node, 7 /* expected inputs */, 1 /* expected outputs */); |
| 184 | |
| 185 | // Extract IO and info |
| 186 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 187 | typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1)); |
| 188 | typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2)); |
| 189 | typename TargetInfo::TensorType *mean = get_backing_tensor<TargetInfo>(node.input(3)); |
| 190 | typename TargetInfo::TensorType *var = get_backing_tensor<TargetInfo>(node.input(4)); |
| 191 | typename TargetInfo::TensorType *beta = get_backing_tensor<TargetInfo>(node.input(5)); |
| 192 | typename TargetInfo::TensorType *gamma = get_backing_tensor<TargetInfo>(node.input(6)); |
| 193 | |
| 194 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 195 | |
| 196 | const PadStrideInfo conv_info = node.convolution_info(); |
| 197 | const unsigned int num_groups = node.num_groups(); |
| 198 | const bool fast_math = node.fast_math_hint() == FastMathHint::Enabled; |
| 199 | const ActivationLayerInfo fused_act = node.fused_activation(); |
| 200 | const float epsilon = node.epsilon(); |
| 201 | |
giuros01 | acce504 | 2019-02-21 17:32:34 +0000 | [diff] [blame] | 202 | // Create and configure function |
| 203 | auto func = support::cpp14::make_unique<FusedConvolutionBatchNormalizationFunction<TargetInfo, FusedLayerTypes>>(); |
| 204 | func->configure(input, weights, biases, output, mean, var, beta, gamma, epsilon, conv_info, num_groups, fast_math, fused_act); |
| 205 | |
| 206 | // Log info |
| 207 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 208 | << node.name() |
Manuel Bottini | bffb41e | 2019-06-20 16:00:27 +0100 | [diff] [blame] | 209 | << " Type: " << node.type() |
| 210 | << " Target: " << TargetInfo::TargetType |
| 211 | << " Data Type: " << input->info()->data_type() |
| 212 | << " Input shape: " << input->info()->tensor_shape() |
| 213 | << " Weights shape: " << weights->info()->tensor_shape() |
| 214 | << " Output shape: " << output->info()->tensor_shape() |
| 215 | << (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "") |
| 216 | << std::endl); |
| 217 | return std::move(func); |
| 218 | } |
| 219 | |
| 220 | /** Create a backend fused depthwise convolution batch normalization layer function |
| 221 | * |
| 222 | * @tparam FusedLayerTypes Fused layer types |
| 223 | * @tparam TargetInfo Target-specific information |
| 224 | * |
| 225 | * @param[in] node Node to create the backend function for |
| 226 | * |
| 227 | * @return Backend fused depthwise convolution batch normalization layer function |
| 228 | */ |
| 229 | template <typename FusedLayerTypes, typename TargetInfo> |
| 230 | std::unique_ptr<IFunction> create_fused_depthwise_convolution_batch_normalization_layer(FusedDepthwiseConvolutionBatchNormalizationNode &node) |
| 231 | { |
| 232 | validate_node<TargetInfo>(node, 7 /* expected inputs */, 1 /* expected outputs */); |
| 233 | |
| 234 | // Extract IO and info |
| 235 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 236 | typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1)); |
| 237 | typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2)); |
| 238 | typename TargetInfo::TensorType *mean = get_backing_tensor<TargetInfo>(node.input(3)); |
| 239 | typename TargetInfo::TensorType *var = get_backing_tensor<TargetInfo>(node.input(4)); |
| 240 | typename TargetInfo::TensorType *beta = get_backing_tensor<TargetInfo>(node.input(5)); |
| 241 | typename TargetInfo::TensorType *gamma = get_backing_tensor<TargetInfo>(node.input(6)); |
| 242 | |
| 243 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 244 | |
| 245 | const PadStrideInfo conv_info = node.convolution_info(); |
| 246 | const unsigned int depth_multiplier = node.depth_multiplier(); |
| 247 | const ActivationLayerInfo fused_act = node.fused_activation(); |
| 248 | const float epsilon = node.epsilon(); |
| 249 | |
| 250 | // Create and configure function |
| 251 | auto func = support::cpp14::make_unique<FusedDepthwiseConvolutionBatchNormalizationFunction<TargetInfo, FusedLayerTypes>>(); |
| 252 | func->configure(input, weights, biases, output, mean, var, beta, gamma, epsilon, conv_info, depth_multiplier, fused_act); |
| 253 | |
| 254 | // Log info |
| 255 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 256 | << node.name() |
| 257 | << " Type: " << node.type() |
giuros01 | acce504 | 2019-02-21 17:32:34 +0000 | [diff] [blame] | 258 | << " Target: " << TargetInfo::TargetType |
| 259 | << " Data Type: " << input->info()->data_type() |
| 260 | << " Input shape: " << input->info()->tensor_shape() |
| 261 | << " Weights shape: " << weights->info()->tensor_shape() |
| 262 | << " Output shape: " << output->info()->tensor_shape() |
| 263 | << (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "") |
| 264 | << std::endl); |
| 265 | return std::move(func); |
| 266 | } |
| 267 | |
Manuel Bottini | d2048ce | 2018-10-23 17:00:42 +0100 | [diff] [blame] | 268 | /** Create a backend bounding box transform layer function |
| 269 | * |
| 270 | * @tparam BoundingBoxTransformLayerFunction Backend bounding box transform function |
| 271 | * @tparam TargetInfo Target-specific information |
| 272 | * |
| 273 | * @param[in] node Node to create the backend function for |
| 274 | * |
| 275 | * @return Backend bounding box transform layer function |
| 276 | */ |
| 277 | template <typename BoundingBoxTransformLayerFunction, typename TargetInfo> |
| 278 | std::unique_ptr<IFunction> create_bounding_box_transform_layer(BoundingBoxTransformLayerNode &node) |
| 279 | { |
| 280 | validate_node<TargetInfo>(node, 2 /* expected inputs */, 1 /* expected outputs */); |
| 281 | |
| 282 | // Extract IO and info |
| 283 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 284 | typename TargetInfo::TensorType *deltas = get_backing_tensor<TargetInfo>(node.input(1)); |
| 285 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 286 | const BoundingBoxTransformInfo bbox_info = node.info(); |
| 287 | |
| 288 | // Create and configure function |
| 289 | auto func = support::cpp14::make_unique<BoundingBoxTransformLayerFunction>(); |
| 290 | func->configure(input, output, deltas, bbox_info); |
| 291 | |
| 292 | // Log info |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 293 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 294 | << node.name() |
| 295 | << " Type: " << node.type() |
| 296 | << " Target: " << TargetInfo::TargetType |
Manuel Bottini | d2048ce | 2018-10-23 17:00:42 +0100 | [diff] [blame] | 297 | << " Data Type: " << input->info()->data_type() |
| 298 | << " Shape: " << input->info()->tensor_shape() |
| 299 | << " BoundingBox Info img W: " << bbox_info.img_width() << " " |
| 300 | << " BoundingBox Info img H: " << bbox_info.img_height() << " " |
| 301 | << std::endl); |
| 302 | |
| 303 | return std::move(func); |
| 304 | } |
| 305 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 306 | /** Create a backend channel shuffle layer function |
| 307 | * |
| 308 | * @tparam ChannelShuffleLayerFunction Backend channel shuffle function |
| 309 | * @tparam TargetInfo Target-specific information |
| 310 | * |
| 311 | * @param[in] node Node to create the backend function for |
| 312 | * |
| 313 | * @return Backend channel shuffle layer function |
| 314 | */ |
| 315 | template <typename ChannelShuffleLayerFunction, typename TargetInfo> |
| 316 | std::unique_ptr<IFunction> create_channel_shuffle_layer(ChannelShuffleLayerNode &node) |
| 317 | { |
| 318 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 319 | |
| 320 | // Extract IO and info |
| 321 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 322 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 323 | const unsigned int num_groups = node.num_groups(); |
| 324 | |
| 325 | // Create function |
| 326 | auto func = support::cpp14::make_unique<ChannelShuffleLayerFunction>(); |
| 327 | func->configure(input, output, num_groups); |
| 328 | |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 329 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 330 | << node.name() |
| 331 | << " Type: " << node.type() |
| 332 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 333 | << " Data Type: " << input->info()->data_type() |
| 334 | << " Shape: " << input->info()->tensor_shape() |
| 335 | << " Num groups: " << num_groups |
| 336 | << std::endl); |
| 337 | |
| 338 | return std::move(func); |
| 339 | } |
| 340 | |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 341 | /** Create a backend layer concatenate function |
| 342 | * |
| 343 | * @tparam ConcatenateLayerFunction Backend concatenate function |
| 344 | * @tparam TargetInfo Target-specific information |
| 345 | * |
| 346 | * @param[in] node Node to create the backend function for |
| 347 | * |
| 348 | * @return Backend concatenate layer function |
| 349 | */ |
| 350 | template <typename ConcatenateLayerFunction, typename TargetInfo> |
| 351 | std::unique_ptr<arm_compute::IFunction> create_concatenate_layer(ConcatenateLayerNode &node) |
| 352 | { |
| 353 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating Concatenate node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 354 | ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1); |
| 355 | |
| 356 | // Return nullptr if depth concatenate is switched off |
| 357 | if(!node.is_enabled()) |
| 358 | { |
| 359 | return nullptr; |
| 360 | } |
| 361 | |
| 362 | // Extract IO and info |
| 363 | std::vector<typename TargetInfo::TensorType *> inputs; |
| 364 | for(unsigned int i = 0; i < node.num_inputs(); ++i) |
| 365 | { |
| 366 | inputs.push_back(get_backing_tensor<TargetInfo>(node.input(i))); |
| 367 | } |
| 368 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
Georgios Pinitas | 9e4824c | 2019-04-12 13:15:58 +0100 | [diff] [blame] | 369 | const DataLayout data_layout = node.output(0) != nullptr ? node.output(0)->desc().layout : DataLayout::UNKNOWN; |
| 370 | const size_t concat_axis = get_dimension_idx(data_layout, node.concatenation_axis()); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 371 | |
| 372 | // Create and configure function |
| 373 | auto func = support::cpp14::make_unique<ConcatenateLayerFunction>(); |
| 374 | func->configure(inputs, output, concat_axis); |
| 375 | |
| 376 | // Log info |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 377 | const bool is_quantized = is_data_type_quantized_asymmetric(output->info()->data_type()); |
| 378 | std::ostringstream qss; |
| 379 | if(is_quantized) |
| 380 | { |
| 381 | qss << " Output QuantInfo: " << output->info()->quantization_info(); |
| 382 | } |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 383 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 384 | << node.name() |
| 385 | << " Type: " << node.type() |
| 386 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 387 | << " Data Type: " << output->info()->data_type() |
| 388 | << " Shape: " << output->info()->tensor_shape() |
| 389 | << " Num Inputs: " << inputs.size() |
| 390 | << " Axis: " << concat_axis |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 391 | << qss.str() |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 392 | << std::endl); |
| 393 | |
| 394 | return std::move(func); |
| 395 | } |
| 396 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 397 | /** Create a backend convolution layer function |
| 398 | * |
| 399 | * @tparam ConvolutionLayerFunctions Backend convolution functions |
| 400 | * @tparam TargetInfo Target-specific information |
| 401 | * |
| 402 | * @param[in] node Node to create the backend function for |
| 403 | * @param[in] ctx Graph context |
| 404 | * |
| 405 | * @return Backend convolution layer function |
| 406 | */ |
| 407 | template <typename ConvolutionLayerFunctions, typename TargetInfo> |
| 408 | std::unique_ptr<IFunction> create_convolution_layer(ConvolutionLayerNode &node, GraphContext &ctx) |
| 409 | { |
| 410 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 411 | |
| 412 | // Extract IO and info |
| 413 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 414 | typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1)); |
| 415 | typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2)); |
| 416 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 417 | |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 418 | const bool is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 419 | |
| 420 | if(is_quantized) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 421 | { |
| 422 | biases->info()->set_data_type(DataType::S32); |
| 423 | } |
| 424 | |
Georgios Pinitas | 08346e9 | 2018-10-16 19:10:46 +0100 | [diff] [blame] | 425 | const PadStrideInfo conv_info = node.convolution_info(); |
| 426 | const unsigned int num_groups = node.num_groups(); |
| 427 | const ConvolutionMethod conv_algorithm = node.convolution_method(); |
| 428 | const bool fast_math = node.fast_math_hint() == FastMathHint::Enabled; |
| 429 | const ActivationLayerInfo fused_act = node.fused_activation(); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 430 | |
| 431 | // Create and configure function (we assume that functions have been validated before creation) |
| 432 | std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, TargetInfo::TargetType); |
| 433 | std::unique_ptr<IFunction> func; |
| 434 | std::string func_name; |
| 435 | |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 436 | if(conv_algorithm == ConvolutionMethod::Winograd) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 437 | { |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 438 | ARM_COMPUTE_ERROR_ON_MSG(num_groups != 1, "WinogradConvolutionLayer does not support grouping!"); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 439 | std::tie(func, func_name) = create_named_memory_managed_function<typename ConvolutionLayerFunctions::WinogradConvolutionLayer>( |
| 440 | std::string("WinogradConvolutionLayer"), mm, |
Georgios Pinitas | 08346e9 | 2018-10-16 19:10:46 +0100 | [diff] [blame] | 441 | input, weights, biases, output, conv_info, fused_act, fast_math); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 442 | } |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 443 | else if(conv_algorithm == ConvolutionMethod::Direct) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 444 | { |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 445 | ARM_COMPUTE_ERROR_ON_MSG(num_groups != 1, "DirectConvolutionLayer does not support grouping!"); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 446 | std::tie(func, func_name) = create_named_function<typename ConvolutionLayerFunctions::DirectConvolutionLayer>( |
| 447 | std::string("DirectConvolutionLayer"), |
Georgios Pinitas | 08346e9 | 2018-10-16 19:10:46 +0100 | [diff] [blame] | 448 | input, weights, biases, output, conv_info, fused_act); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 449 | } |
| 450 | else if(conv_algorithm == ConvolutionMethod::GEMM) |
| 451 | { |
| 452 | std::tie(func, func_name) = create_named_memory_managed_function<typename ConvolutionLayerFunctions::GEMMConvolutionLayer>( |
| 453 | std::string("GEMMConvolutionLayer"), mm, |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 454 | input, weights, biases, output, conv_info, |
Georgios Pinitas | 08346e9 | 2018-10-16 19:10:46 +0100 | [diff] [blame] | 455 | WeightsInfo(), Size2D(1U, 1U), fused_act, num_groups); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 456 | } |
| 457 | else |
| 458 | { |
| 459 | std::tie(func, func_name) = create_named_memory_managed_function<typename ConvolutionLayerFunctions::GenericConvolutionLayer>( |
| 460 | std::string("GenericConvolutionLayer"), mm, |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 461 | input, weights, biases, output, conv_info, |
Georgios Pinitas | 08346e9 | 2018-10-16 19:10:46 +0100 | [diff] [blame] | 462 | WeightsInfo(), Size2D(1U, 1U), fused_act, fast_math, num_groups); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | // Log info |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 466 | std::ostringstream qss; |
| 467 | if(is_quantized) |
| 468 | { |
| 469 | qss << " Input QuantInfo: " << input->info()->quantization_info() |
| 470 | << " Weights QuantInfo: " << weights->info()->quantization_info() |
| 471 | << " Output QuantInfo: " << output->info()->quantization_info(); |
| 472 | } |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 473 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 474 | << node.name() |
| 475 | << " Type: " << func_name |
| 476 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 477 | << " Data Type: " << input->info()->data_type() |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 478 | << " Groups: " << num_groups |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 479 | << " Input shape: " << input->info()->tensor_shape() |
| 480 | << " Weights shape: " << weights->info()->tensor_shape() |
| 481 | << " Output shape: " << output->info()->tensor_shape() |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 482 | << qss.str() |
Georgios Pinitas | 08346e9 | 2018-10-16 19:10:46 +0100 | [diff] [blame] | 483 | << (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "") |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 484 | << std::endl); |
| 485 | return func; |
| 486 | } |
| 487 | |
| 488 | /** Create a backend deconvolution layer function |
| 489 | * |
| 490 | * @tparam DeconvolutionLayerFunction Backend deconvolution function |
| 491 | * @tparam TargetInfo Target-specific information |
| 492 | * |
| 493 | * @param[in] node Node to create the backend function for |
| 494 | * @param[in] ctx Graph context |
| 495 | * |
| 496 | * @return Backend deconvolution layer function |
| 497 | */ |
| 498 | template <typename DeconvolutionLayerFunction, typename TargetInfo> |
| 499 | std::unique_ptr<IFunction> create_deconvolution_layer(DeconvolutionLayerNode &node, GraphContext &ctx) |
| 500 | { |
| 501 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 502 | |
| 503 | // Extract IO and info |
| 504 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 505 | typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1)); |
| 506 | typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2)); |
| 507 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 508 | |
Manuel Bottini | c1b76fa | 2019-06-17 12:04:40 +0100 | [diff] [blame] | 509 | const PadStrideInfo deconv_info = node.deconvolution_info(); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 510 | |
| 511 | // Create and configure function (we assume that functions have been validated before creation) |
| 512 | std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, TargetInfo::TargetType); |
| 513 | std::unique_ptr<IFunction> func; |
| 514 | |
| 515 | std::tie(func, std::ignore) = create_named_memory_managed_function<DeconvolutionLayerFunction>( |
| 516 | std::string(), mm, |
Manuel Bottini | c1b76fa | 2019-06-17 12:04:40 +0100 | [diff] [blame] | 517 | input, weights, biases, output, deconv_info); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 518 | |
| 519 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 520 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 521 | << node.name() |
| 522 | << " Type: " << node.type() |
| 523 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 524 | << " Data Type: " << input->info()->data_type() |
| 525 | << " Input shape: " << input->info()->tensor_shape() |
| 526 | << " Weights shape: " << weights->info()->tensor_shape() |
| 527 | << " Output shape: " << output->info()->tensor_shape() |
| 528 | << std::endl); |
| 529 | return func; |
| 530 | } |
| 531 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 532 | /** Create a backend layer depth-wise convolution function |
| 533 | * |
| 534 | * @tparam DepthwiseConvolutionLayerFunctions Backend depthwise convolution function |
| 535 | * @tparam TargetInfo Target-specific information |
| 536 | * |
| 537 | * @param[in] node Node to create the backend function for |
| 538 | * |
| 539 | * @return Backend depth-wise convolution layer function |
| 540 | */ |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame^] | 541 | template <typename DepthwiseConvolutionLayer, typename TargetInfo> |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 542 | std::unique_ptr<IFunction> create_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node) |
| 543 | { |
| 544 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 545 | |
| 546 | // Extract IO and info |
| 547 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 548 | typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1)); |
| 549 | typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2)); |
| 550 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 551 | |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 552 | const bool is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 553 | |
| 554 | if(is_quantized) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 555 | { |
| 556 | biases->info()->set_data_type(DataType::S32); |
| 557 | } |
| 558 | |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame^] | 559 | const PadStrideInfo conv_info = node.convolution_info(); |
| 560 | const unsigned int depth_multiplier = node.depth_multiplier(); |
| 561 | const ActivationLayerInfo fused_act = node.fused_activation(); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 562 | |
| 563 | // Create and configure function (we assume that functions have been validated before creation) |
| 564 | std::unique_ptr<IFunction> func; |
| 565 | std::string func_name; |
Manuel Bottini | 05069f0 | 2019-09-26 17:18:26 +0100 | [diff] [blame^] | 566 | |
| 567 | std::tie(func, func_name) = create_named_function<DepthwiseConvolutionLayer>( |
| 568 | std::string("DepthwiseConvolutionLayer"), |
| 569 | input, weights, biases, output, conv_info, depth_multiplier, fused_act); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 570 | |
| 571 | // Log info |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 572 | std::ostringstream qss; |
| 573 | if(is_quantized) |
| 574 | { |
| 575 | qss << " Input QuantInfo: " << input->info()->quantization_info() |
| 576 | << " Weights QuantInfo: " << weights->info()->quantization_info() |
| 577 | << " Output QuantInfo: " << output->info()->quantization_info(); |
| 578 | } |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 579 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 580 | << node.name() |
| 581 | << " Type: " << func_name |
| 582 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 583 | << " Data Type: " << input->info()->data_type() |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 584 | << " Input shape: " << input->info()->tensor_shape() |
| 585 | << " Weights shape: " << weights->info()->tensor_shape() |
| 586 | << " Output shape: " << output->info()->tensor_shape() |
Georgios Pinitas | 05045c1 | 2018-12-07 18:31:47 +0000 | [diff] [blame] | 587 | << " Depth multiplier: " << depth_multiplier |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 588 | << qss.str() |
Georgios Pinitas | 60e9825 | 2018-10-22 16:17:20 +0100 | [diff] [blame] | 589 | << (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "") |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 590 | << std::endl); |
| 591 | return func; |
| 592 | } |
| 593 | |
Isabella Gottardi | 7234ed8 | 2018-11-27 08:51:10 +0000 | [diff] [blame] | 594 | /** Create a backend detection output layer function |
| 595 | * |
| 596 | * @tparam DetectionOutputLayer Function Backend detection output function |
| 597 | * @tparam TargetInfo Target-specific information |
| 598 | * |
| 599 | * @param[in] node Node to create the backend function for |
| 600 | * |
| 601 | * @return Backend detection output layer function |
| 602 | */ |
| 603 | template <typename DetectionOutputLayerFunction, typename TargetInfo> |
| 604 | std::unique_ptr<IFunction> create_detection_output_layer(DetectionOutputLayerNode &node) |
| 605 | { |
| 606 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 607 | |
| 608 | // Extract IO and info |
| 609 | typename TargetInfo::TensorType *input0 = get_backing_tensor<TargetInfo>(node.input(0)); |
| 610 | typename TargetInfo::TensorType *input1 = get_backing_tensor<TargetInfo>(node.input(1)); |
| 611 | typename TargetInfo::TensorType *input2 = get_backing_tensor<TargetInfo>(node.input(2)); |
| 612 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 613 | const DetectionOutputLayerInfo detect_info = node.detection_output_info(); |
| 614 | |
| 615 | ARM_COMPUTE_ERROR_ON(input0 == nullptr); |
| 616 | ARM_COMPUTE_ERROR_ON(input1 == nullptr); |
| 617 | ARM_COMPUTE_ERROR_ON(input2 == nullptr); |
| 618 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 619 | |
| 620 | // Create and configure function |
| 621 | auto func = support::cpp14::make_unique<DetectionOutputLayerFunction>(); |
| 622 | func->configure(input0, input1, input2, output, detect_info); |
| 623 | |
| 624 | // Log info |
| 625 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 626 | << node.name() |
| 627 | << " Type: " << node.type() |
| 628 | << " Target: " << TargetInfo::TargetType |
| 629 | << " Data Type: " << input0->info()->data_type() |
| 630 | << " Input0 shape: " << input0->info()->tensor_shape() |
| 631 | << " Input1 shape: " << input1->info()->tensor_shape() |
| 632 | << " Input2 shape: " << input2->info()->tensor_shape() |
| 633 | << " Output shape: " << output->info()->tensor_shape() |
| 634 | << " DetectionOutputLayer info: " << detect_info |
| 635 | << std::endl); |
| 636 | |
| 637 | return std::move(func); |
| 638 | } |
Isabella Gottardi | a7acb3c | 2019-01-08 13:48:44 +0000 | [diff] [blame] | 639 | |
| 640 | /** Create a backend detection post process layer function |
| 641 | * |
| 642 | * @tparam DetectionPostProcessLayerFunction Backend detection output function |
| 643 | * @tparam TargetInfo Target-specific information |
| 644 | * |
| 645 | * @param[in] node Node to create the backend function for |
| 646 | * |
| 647 | * @return Backend detection post process layer function |
| 648 | */ |
| 649 | template <typename DetectionPostProcessLayerFunction, typename TargetInfo> |
| 650 | std::unique_ptr<IFunction> create_detection_post_process_layer(DetectionPostProcessLayerNode &node) |
| 651 | { |
| 652 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 4 /* expected outputs */); |
| 653 | |
| 654 | // Extract IO and info |
| 655 | typename TargetInfo::TensorType *input0 = get_backing_tensor<TargetInfo>(node.input(0)); |
| 656 | typename TargetInfo::TensorType *input1 = get_backing_tensor<TargetInfo>(node.input(1)); |
| 657 | typename TargetInfo::TensorType *input2 = get_backing_tensor<TargetInfo>(node.input(2)); |
| 658 | typename TargetInfo::TensorType *output0 = get_backing_tensor<TargetInfo>(node.output(0)); |
| 659 | typename TargetInfo::TensorType *output1 = get_backing_tensor<TargetInfo>(node.output(1)); |
| 660 | typename TargetInfo::TensorType *output2 = get_backing_tensor<TargetInfo>(node.output(2)); |
| 661 | typename TargetInfo::TensorType *output3 = get_backing_tensor<TargetInfo>(node.output(3)); |
| 662 | const DetectionPostProcessLayerInfo detect_info = node.detection_post_process_info(); |
| 663 | |
| 664 | ARM_COMPUTE_ERROR_ON(input0 == nullptr); |
| 665 | ARM_COMPUTE_ERROR_ON(input1 == nullptr); |
| 666 | ARM_COMPUTE_ERROR_ON(input2 == nullptr); |
| 667 | ARM_COMPUTE_ERROR_ON(output0 == nullptr); |
| 668 | ARM_COMPUTE_ERROR_ON(output1 == nullptr); |
| 669 | ARM_COMPUTE_ERROR_ON(output2 == nullptr); |
| 670 | ARM_COMPUTE_ERROR_ON(output3 == nullptr); |
| 671 | |
| 672 | // Create and configure function |
| 673 | auto func = support::cpp14::make_unique<DetectionPostProcessLayerFunction>(); |
| 674 | func->configure(input0, input1, input2, output0, output1, output2, output3, detect_info); |
| 675 | |
| 676 | // Log info |
| 677 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 678 | << node.name() |
| 679 | << " Type: " << node.type() |
| 680 | << " Target: " << TargetInfo::TargetType |
| 681 | << " Data Type: " << input0->info()->data_type() |
| 682 | << " Input0 shape: " << input0->info()->tensor_shape() |
| 683 | << " Input1 shape: " << input1->info()->tensor_shape() |
| 684 | << " Input2 shape: " << input2->info()->tensor_shape() |
| 685 | << " Output0 shape: " << output0->info()->tensor_shape() |
| 686 | << " Output1 shape: " << output1->info()->tensor_shape() |
| 687 | << " Output2 shape: " << output2->info()->tensor_shape() |
| 688 | << " Output3 shape: " << output3->info()->tensor_shape() |
| 689 | << " DetectionPostProcessLayer info: " << detect_info |
| 690 | << std::endl); |
| 691 | |
| 692 | return std::move(func); |
| 693 | } |
| 694 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 695 | /** Create a backend element-wise operation layer function |
| 696 | * |
| 697 | * @tparam EltwiseFunctions Backend element-wise function |
| 698 | * @tparam TargetInfo Target-specific information |
| 699 | * |
| 700 | * @param[in] node Node to create the backend function for |
| 701 | * |
| 702 | * @return Backend element-wise operation layer function |
| 703 | */ |
| 704 | template <typename EltwiseFunctions, typename TargetInfo> |
| 705 | std::unique_ptr<IFunction> create_eltwise_layer(EltwiseLayerNode &node) |
| 706 | { |
| 707 | validate_node<TargetInfo>(node, 2 /* expected inputs */, 1 /* expected outputs */); |
| 708 | |
| 709 | // Extract IO and info |
| 710 | typename TargetInfo::TensorType *input1 = get_backing_tensor<TargetInfo>(node.input(0)); |
| 711 | typename TargetInfo::TensorType *input2 = get_backing_tensor<TargetInfo>(node.input(1)); |
| 712 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 713 | const EltwiseOperation eltwise_op = node.eltwise_operation(); |
| 714 | const ConvertPolicy convert_policy = node.convert_policy(); |
| 715 | ARM_COMPUTE_ERROR_ON(input1 == nullptr); |
| 716 | ARM_COMPUTE_ERROR_ON(input2 == nullptr); |
| 717 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 718 | |
| 719 | std::unique_ptr<IFunction> func = nullptr; |
| 720 | std::string func_name; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 721 | if(eltwise_op == EltwiseOperation::Add) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 722 | { |
| 723 | std::tie(func, func_name) = create_named_function<typename EltwiseFunctions::Addition>( |
| 724 | std::string("ArithmeticAddition"), |
| 725 | input1, input2, output, convert_policy); |
| 726 | } |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 727 | else if(eltwise_op == EltwiseOperation::Sub) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 728 | { |
| 729 | std::tie(func, func_name) = create_named_function<typename EltwiseFunctions::Subtraction>( |
| 730 | std::string("ArithmeticSubtraction"), |
| 731 | input1, input2, output, convert_policy); |
| 732 | } |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 733 | else if(eltwise_op == EltwiseOperation::Mul) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 734 | { |
| 735 | std::tie(func, func_name) = create_named_function<typename EltwiseFunctions::Multiplication>( |
| 736 | std::string("PixelWiseMultiplication"), |
| 737 | input1, input2, output, 1.f, convert_policy, node.rounding_policy()); |
| 738 | } |
| 739 | else |
| 740 | { |
| 741 | ARM_COMPUTE_ERROR("Unsupported element-wise operation!"); |
| 742 | } |
| 743 | |
| 744 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 745 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 746 | << node.name() |
| 747 | << " Type: " << node.type() |
| 748 | << " Target: " << TargetInfo::TargetType |
| 749 | << " Operation: " << func_name |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 750 | << " Data Type: " << input1->info()->data_type() |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 751 | << " Shape: " << input1->info()->tensor_shape() |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 752 | << std::endl); |
| 753 | |
| 754 | return func; |
| 755 | } |
| 756 | |
| 757 | /** Create a backend flatten layer function |
| 758 | * |
| 759 | * @tparam FlattenLayerFunction Backend flatten function |
| 760 | * @tparam TargetInfo Target-specific information |
| 761 | * |
| 762 | * @param[in] node Node to create the backend function for |
| 763 | * |
| 764 | * @return Backend flatten layer function |
| 765 | */ |
| 766 | template <typename FlattenLayerFunction, typename TargetInfo> |
| 767 | std::unique_ptr<IFunction> create_flatten_layer(FlattenLayerNode &node) |
| 768 | { |
| 769 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 770 | |
| 771 | // Extract IO and info |
| 772 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 773 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 774 | |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 775 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 776 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 777 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 778 | // Create and configure function |
| 779 | auto func = support::cpp14::make_unique<FlattenLayerFunction>(); |
| 780 | func->configure(input, output); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 781 | |
| 782 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 783 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 784 | << node.name() |
| 785 | << " Type: " << node.type() |
| 786 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 787 | << " Data Type: " << input->info()->data_type() |
| 788 | << " Input shape: " << input->info()->tensor_shape() |
| 789 | << " Output shape: " << output->info()->tensor_shape() |
| 790 | << std::endl); |
| 791 | |
| 792 | return std::move(func); |
| 793 | } |
| 794 | |
| 795 | /** Create a backend fully connected layer function |
| 796 | * |
| 797 | * @tparam FullyConnectedLayerFunction Backend fully-connected function |
| 798 | * @tparam TargetInfo Target-specific information |
| 799 | * |
| 800 | * @param[in] node Node to create the backend function for |
| 801 | * @param[in] ctx Graph context |
| 802 | * |
| 803 | * @return Backend fully connected layer function |
| 804 | */ |
| 805 | template <typename FullyConnectedLayerFunction, typename TargetInfo> |
| 806 | std::unique_ptr<IFunction> create_fully_connected_layer(FullyConnectedLayerNode &node, GraphContext &ctx) |
| 807 | { |
| 808 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 809 | |
| 810 | // Extract IO and info |
| 811 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 812 | typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1)); |
| 813 | typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2)); |
| 814 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 815 | const FullyConnectedLayerInfo fc_info = node.info(); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 816 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 817 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 818 | ARM_COMPUTE_ERROR_ON(weights == nullptr); |
| 819 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 820 | |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 821 | // Create and configure function |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 822 | auto wm = get_weights_manager(ctx, TargetInfo::TargetType); |
| 823 | auto mm = get_memory_manager(ctx, TargetInfo::TargetType); |
| 824 | auto func = support::cpp14::make_unique<FullyConnectedLayerFunction>(mm, wm.get()); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 825 | func->configure(input, weights, biases, output, fc_info); |
| 826 | |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 827 | const bool is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 828 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 829 | // Log info |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 830 | std::ostringstream qss; |
| 831 | if(is_quantized) |
| 832 | { |
| 833 | qss << " Input QuantInfo: " << input->info()->quantization_info() |
| 834 | << " Weights QuantInfo: " << weights->info()->quantization_info() |
| 835 | << " Output QuantInfo: " << output->info()->quantization_info(); |
| 836 | } |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 837 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 838 | << node.name() |
| 839 | << " Type: " << node.type() |
| 840 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 841 | << " Data Type: " << input->info()->data_type() |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 842 | << qss.str() |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 843 | << " Input shape: " << input->info()->tensor_shape() |
| 844 | << " Weights shape: " << weights->info()->tensor_shape() |
| 845 | << " Output shape: " << output->info()->tensor_shape() |
| 846 | << std::endl); |
| 847 | |
| 848 | return std::move(func); |
| 849 | } |
| 850 | |
Manuel Bottini | 5209be5 | 2019-02-13 16:34:56 +0000 | [diff] [blame] | 851 | /** Create a backend generate proposals layer function |
| 852 | * |
| 853 | * @tparam GenerateProposalsLayerFunction Backend generate proposals function |
| 854 | * @tparam TargetInfo Target-specific information |
| 855 | * |
| 856 | * @param[in] node Node to create the backend function for |
| 857 | * @param[in] ctx Graph context |
| 858 | * |
| 859 | * @return Backend generate proposals layer function |
| 860 | */ |
| 861 | template <typename GenerateProposalsLayerFunction, typename TargetInfo> |
| 862 | std::unique_ptr<IFunction> create_generate_proposals_layer(GenerateProposalsLayerNode &node, GraphContext &ctx) |
| 863 | { |
| 864 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 3 /* expected outputs */); |
| 865 | |
| 866 | // Extract IO and info |
| 867 | typename TargetInfo::TensorType *scores = get_backing_tensor<TargetInfo>(node.input(0)); |
| 868 | typename TargetInfo::TensorType *deltas = get_backing_tensor<TargetInfo>(node.input(1)); |
| 869 | typename TargetInfo::TensorType *anchors = get_backing_tensor<TargetInfo>(node.input(2)); |
| 870 | typename TargetInfo::TensorType *proposals = get_backing_tensor<TargetInfo>(node.output(0)); |
| 871 | typename TargetInfo::TensorType *scores_out = get_backing_tensor<TargetInfo>(node.output(1)); |
| 872 | typename TargetInfo::TensorType *num_valid_proposals = get_backing_tensor<TargetInfo>(node.output(2)); |
| 873 | const GenerateProposalsInfo info = node.info(); |
| 874 | |
| 875 | ARM_COMPUTE_ERROR_ON(scores == nullptr); |
| 876 | ARM_COMPUTE_ERROR_ON(deltas == nullptr); |
| 877 | ARM_COMPUTE_ERROR_ON(anchors == nullptr); |
| 878 | ARM_COMPUTE_ERROR_ON(proposals == nullptr); |
| 879 | ARM_COMPUTE_ERROR_ON(scores_out == nullptr); |
| 880 | |
| 881 | // Create and configure function |
| 882 | auto func = support::cpp14::make_unique<GenerateProposalsLayerFunction>(get_memory_manager(ctx, TargetInfo::TargetType)); |
| 883 | func->configure(scores, deltas, anchors, proposals, scores_out, num_valid_proposals, info); |
| 884 | |
| 885 | // Log info |
| 886 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 887 | << " Target " << TargetInfo::TargetType |
| 888 | << " Data Type: " << scores->info()->data_type() |
| 889 | << " Scores shape: " << scores->info()->tensor_shape() |
| 890 | << " Deltas shape: " << deltas->info()->tensor_shape() |
| 891 | << " Anchors shape: " << anchors->info()->tensor_shape() |
| 892 | << " Proposals shape: " << proposals->info()->tensor_shape() |
| 893 | << " Num valid proposals shape: " << num_valid_proposals->info()->tensor_shape() |
| 894 | << " Scores Out shape: " << scores_out->info()->tensor_shape() |
| 895 | << std::endl); |
| 896 | |
| 897 | return std::move(func); |
| 898 | } |
| 899 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 900 | /** Create a backend normalization layer function |
| 901 | * |
| 902 | * @tparam NormalizationLayerFunction Backend normalization function |
| 903 | * @tparam TargetInfo Target-specific information |
| 904 | * |
| 905 | * @param[in] node Node to create the backend function for |
| 906 | * @param[in] ctx Graph context |
| 907 | * |
| 908 | * @return Backend normalization layer function |
| 909 | */ |
| 910 | template <typename NormalizationLayerFunction, typename TargetInfo> |
| 911 | std::unique_ptr<IFunction> create_normalization_layer(NormalizationLayerNode &node, GraphContext &ctx) |
| 912 | { |
| 913 | ARM_COMPUTE_UNUSED(ctx); |
| 914 | |
| 915 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 916 | |
| 917 | // Extract IO and info |
| 918 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 919 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 920 | const NormalizationLayerInfo norm_info = node.normalization_info(); |
| 921 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 922 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 923 | |
| 924 | // Create and configure function |
| 925 | auto func = support::cpp14::make_unique<NormalizationLayerFunction>(); |
| 926 | func->configure(input, output, norm_info); |
| 927 | |
| 928 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 929 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 930 | << node.name() |
| 931 | << " Type: " << node.type() |
| 932 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 933 | << " Data Type: " << input->info()->data_type() |
| 934 | << " Input shape: " << input->info()->tensor_shape() |
| 935 | << " Output shape: " << output->info()->tensor_shape() |
| 936 | << " Normalization info: " << norm_info.type() |
| 937 | << std::endl); |
| 938 | |
| 939 | return std::move(func); |
| 940 | } |
| 941 | |
Michele Di Giorgio | 555d110 | 2018-09-12 13:51:59 +0100 | [diff] [blame] | 942 | /** Create a backend normalize planar YUV layer function |
| 943 | * |
| 944 | * @tparam NormalizePlanarYUVLayerFunction Backend normalize planar YUV function |
| 945 | * @tparam TargetInfo Target-specific information |
| 946 | * |
| 947 | * @param[in] node Node to create the backend function for |
| 948 | * |
| 949 | * @return Backend normalize plnar YUV layer function |
| 950 | */ |
| 951 | template <typename NormalizePlanarYUVLayerFunction, typename TargetInfo> |
| 952 | std::unique_ptr<IFunction> create_normalize_planar_yuv_layer(NormalizePlanarYUVLayerNode &node) |
| 953 | { |
| 954 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 955 | |
| 956 | // Extract IO and info |
| 957 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 958 | typename TargetInfo::TensorType *mean = get_backing_tensor<TargetInfo>(node.input(1)); |
| 959 | typename TargetInfo::TensorType *std = get_backing_tensor<TargetInfo>(node.input(2)); |
| 960 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 961 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 962 | ARM_COMPUTE_ERROR_ON(mean == nullptr); |
| 963 | ARM_COMPUTE_ERROR_ON(std == nullptr); |
| 964 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 965 | |
| 966 | // Create and configure function |
| 967 | auto func = support::cpp14::make_unique<NormalizePlanarYUVLayerFunction>(); |
| 968 | func->configure(input, output, mean, std); |
| 969 | |
| 970 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 971 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 972 | << node.name() |
| 973 | << " Type: " << node.type() |
| 974 | << " Target: " << TargetInfo::TargetType |
Michele Di Giorgio | 555d110 | 2018-09-12 13:51:59 +0100 | [diff] [blame] | 975 | << " Data Type: " << input->info()->data_type() |
| 976 | << " Shape: " << input->info()->tensor_shape() |
| 977 | << std::endl); |
| 978 | |
| 979 | return std::move(func); |
| 980 | } |
| 981 | |
Michele Di Giorgio | 4bb1733 | 2018-09-26 13:56:51 +0100 | [diff] [blame] | 982 | /** Create a backend pad layer function |
| 983 | * |
| 984 | * @tparam PadLayerFunction Backend pad function |
| 985 | * @tparam TargetInfo Target-specific information |
| 986 | * |
| 987 | * @param[in] node Node to create the backend function for |
| 988 | * |
| 989 | * @return Backend pad layer function |
| 990 | */ |
| 991 | template <typename PadLayerFunction, typename TargetInfo> |
| 992 | std::unique_ptr<IFunction> create_pad_layer(PadLayerNode &node) |
| 993 | { |
| 994 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 995 | |
| 996 | // Extract IO and info |
| 997 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 998 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 999 | const PaddingList &padding = node.padding(); |
| 1000 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1001 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1002 | |
| 1003 | // Create and configure function |
| 1004 | auto func = support::cpp14::make_unique<PadLayerFunction>(); |
| 1005 | func->configure(input, output, padding); |
| 1006 | |
| 1007 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1008 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1009 | << node.name() |
| 1010 | << " Type: " << node.type() |
| 1011 | << " Target: " << TargetInfo::TargetType |
Michele Di Giorgio | 4bb1733 | 2018-09-26 13:56:51 +0100 | [diff] [blame] | 1012 | << " Data Type: " << input->info()->data_type() |
| 1013 | << " Input shape: " << input->info()->tensor_shape() |
| 1014 | << " Output shape: " << output->info()->tensor_shape() |
| 1015 | << std::endl); |
| 1016 | |
| 1017 | return std::move(func); |
| 1018 | } |
| 1019 | |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 1020 | /** Create a backend permute layer function |
| 1021 | * |
| 1022 | * @tparam PermuteLayerFunction Backend permute function |
| 1023 | * @tparam TargetInfo Target-specific information |
| 1024 | * |
| 1025 | * @param[in] node Node to create the backend function for |
| 1026 | * |
| 1027 | * @return Backend permute layer function |
| 1028 | */ |
| 1029 | template <typename PermuteLayerFunction, typename TargetInfo> |
| 1030 | std::unique_ptr<IFunction> create_permute_layer(PermuteLayerNode &node) |
| 1031 | { |
| 1032 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 1033 | |
| 1034 | // Extract IO and info |
| 1035 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1036 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1037 | const PermutationVector &perm = node.permutation_vector(); |
| 1038 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1039 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1040 | |
| 1041 | // Create and configure function |
| 1042 | auto func = support::cpp14::make_unique<PermuteLayerFunction>(); |
| 1043 | func->configure(input, output, perm); |
| 1044 | |
| 1045 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1046 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1047 | << node.name() |
| 1048 | << " Type: " << node.type() |
| 1049 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 1050 | << " Data Type: " << input->info()->data_type() |
| 1051 | << " Input shape: " << input->info()->tensor_shape() |
| 1052 | << " Output shape: " << output->info()->tensor_shape() |
| 1053 | << " Permutation vector: " << perm |
| 1054 | << std::endl); |
| 1055 | |
| 1056 | return std::move(func); |
| 1057 | } |
| 1058 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 1059 | /** Create a backend pooling layer function |
| 1060 | * |
| 1061 | * @tparam PoolingLayerFunction Backend pooling function |
| 1062 | * @tparam TargetInfo Target-specific information |
| 1063 | * |
| 1064 | * @param[in] node Node to create the backend function for |
| 1065 | * |
| 1066 | * @return Backend pooling layer function |
| 1067 | */ |
| 1068 | template <typename PoolingLayerFunction, typename TargetInfo> |
| 1069 | std::unique_ptr<IFunction> create_pooling_layer(PoolingLayerNode &node) |
| 1070 | { |
| 1071 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 1072 | |
| 1073 | // Extract IO and info |
| 1074 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1075 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1076 | const PoolingLayerInfo pool_info = node.pooling_info(); |
| 1077 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1078 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1079 | |
| 1080 | // Create and configure function |
| 1081 | auto func = support::cpp14::make_unique<PoolingLayerFunction>(); |
| 1082 | func->configure(input, output, pool_info); |
| 1083 | |
| 1084 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1085 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1086 | << node.name() |
| 1087 | << " Type: " << node.type() |
| 1088 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 1089 | << " Data Type: " << input->info()->data_type() |
| 1090 | << " Input shape: " << input->info()->tensor_shape() |
| 1091 | << " Output shape: " << output->info()->tensor_shape() |
| 1092 | << " Pooling info: " << pool_info.pool_type() |
| 1093 | << std::endl); |
| 1094 | |
| 1095 | return std::move(func); |
| 1096 | } |
| 1097 | |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1098 | /** Create a backend priorbox layer function |
| 1099 | * |
| 1100 | * @tparam PriorBoxLayerFunction Backend priorbox function |
| 1101 | * @tparam TargetInfo Target-specific information |
| 1102 | * |
| 1103 | * @param[in] node Node to create the backend function for |
| 1104 | * |
| 1105 | * @return Backend priorbox layer function |
| 1106 | */ |
| 1107 | template <typename PriorBoxLayerFunction, typename TargetInfo> |
| 1108 | std::unique_ptr<IFunction> create_priorbox_layer(PriorBoxLayerNode &node) |
| 1109 | { |
| 1110 | validate_node<TargetInfo>(node, 2 /* expected inputs */, 1 /* expected outputs */); |
| 1111 | |
| 1112 | // Extract IO and info |
| 1113 | typename TargetInfo::TensorType *input0 = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1114 | typename TargetInfo::TensorType *input1 = get_backing_tensor<TargetInfo>(node.input(1)); |
| 1115 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1116 | const PriorBoxLayerInfo prior_info = node.priorbox_info(); |
| 1117 | ARM_COMPUTE_ERROR_ON(input0 == nullptr); |
| 1118 | ARM_COMPUTE_ERROR_ON(input1 == nullptr); |
| 1119 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1120 | |
| 1121 | // Create and configure function |
| 1122 | auto func = support::cpp14::make_unique<PriorBoxLayerFunction>(); |
| 1123 | func->configure(input0, input1, output, prior_info); |
| 1124 | |
| 1125 | // Log info |
| 1126 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1127 | << node.name() |
| 1128 | << " Type: " << node.type() |
| 1129 | << " Target: " << TargetInfo::TargetType |
| 1130 | << " Data Type: " << input0->info()->data_type() |
| 1131 | << " Input0 shape: " << input0->info()->tensor_shape() |
| 1132 | << " Input1 shape: " << input1->info()->tensor_shape() |
| 1133 | << " Output shape: " << output->info()->tensor_shape() |
| 1134 | << " PriorBoxLayer info: " << prior_info |
| 1135 | << std::endl); |
| 1136 | |
| 1137 | return std::move(func); |
| 1138 | } |
| 1139 | |
Isabella Gottardi | 3db1ba9 | 2019-05-17 12:35:20 +0100 | [diff] [blame] | 1140 | /** Create a backend quantization layer function |
| 1141 | * |
| 1142 | * @tparam QuantizationLayerFunction Backend quantization function |
| 1143 | * @tparam TargetInfo Target-specific information |
| 1144 | * |
| 1145 | * @param[in] node Node to create the backend function for |
| 1146 | * |
| 1147 | * @return Backend quantization layer function |
| 1148 | */ |
| 1149 | template <typename QuantizationLayerFunction, typename TargetInfo> |
| 1150 | std::unique_ptr<IFunction> create_quantization_layer(QuantizationLayerNode &node) |
| 1151 | { |
| 1152 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 1153 | |
| 1154 | // Extract IO and info |
| 1155 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1156 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1157 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1158 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1159 | |
| 1160 | // Create and configure function |
| 1161 | auto func = support::cpp14::make_unique<QuantizationLayerFunction>(); |
| 1162 | func->configure(input, output); |
| 1163 | |
| 1164 | // Log info |
| 1165 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1166 | << node.name() |
| 1167 | << " Type: " << node.type() |
| 1168 | << " Target: " << TargetInfo::TargetType |
| 1169 | << " Data Type: " << input->info()->data_type() |
| 1170 | << " Input shape: " << input->info()->tensor_shape() |
| 1171 | << " Output shape: " << output->info()->tensor_shape() |
| 1172 | << std::endl); |
| 1173 | |
| 1174 | return std::move(func); |
| 1175 | } |
| 1176 | |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 1177 | /** Create a backend reorg layer function |
| 1178 | * |
Michele Di Giorgio | c30b668 | 2018-09-12 17:44:08 +0100 | [diff] [blame] | 1179 | * @tparam ReorgLayerFunction Backend reorg function |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 1180 | * @tparam TargetInfo Target-specific information |
| 1181 | * |
| 1182 | * @param[in] node Node to create the backend function for |
| 1183 | * |
| 1184 | * @return Backend reshape layer function |
| 1185 | */ |
| 1186 | template <typename ReorgLayerFunction, typename TargetInfo> |
| 1187 | std::unique_ptr<IFunction> create_reorg_layer(ReorgLayerNode &node) |
| 1188 | { |
| 1189 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 1190 | |
| 1191 | // Extract IO and info |
| 1192 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1193 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1194 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1195 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1196 | |
| 1197 | // Create and configure function |
| 1198 | auto func = support::cpp14::make_unique<ReorgLayerFunction>(); |
| 1199 | func->configure(input, output, node.stride()); |
| 1200 | |
| 1201 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1202 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1203 | << node.name() |
| 1204 | << " Type: " << node.type() |
| 1205 | << " Target: " << TargetInfo::TargetType |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 1206 | << " Data Type: " << input->info()->data_type() |
| 1207 | << " Input shape: " << input->info()->tensor_shape() |
| 1208 | << " Output shape: " << output->info()->tensor_shape() |
| 1209 | << std::endl); |
| 1210 | |
| 1211 | return std::move(func); |
| 1212 | } |
| 1213 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 1214 | /** Create a backend reshape layer function |
| 1215 | * |
| 1216 | * @tparam ReshapeLayerFunction Backend reshape function |
| 1217 | * @tparam TargetInfo Target-specific information |
| 1218 | * |
| 1219 | * @param[in] node Node to create the backend function for |
| 1220 | * |
| 1221 | * @return Backend reshape layer function |
| 1222 | */ |
| 1223 | template <typename ReshapeLayerFunction, typename TargetInfo> |
| 1224 | std::unique_ptr<IFunction> create_reshape_layer(ReshapeLayerNode &node) |
| 1225 | { |
| 1226 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 1227 | |
| 1228 | // Extract IO and info |
| 1229 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1230 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1231 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1232 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1233 | |
| 1234 | // Create and configure function |
| 1235 | auto func = support::cpp14::make_unique<ReshapeLayerFunction>(); |
| 1236 | func->configure(input, output); |
| 1237 | |
| 1238 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1239 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1240 | << node.name() |
| 1241 | << " Type: " << node.type() |
| 1242 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 1243 | << " Data Type: " << input->info()->data_type() |
| 1244 | << " Input shape: " << input->info()->tensor_shape() |
| 1245 | << " Output shape: " << output->info()->tensor_shape() |
| 1246 | << std::endl); |
| 1247 | |
| 1248 | return std::move(func); |
| 1249 | } |
| 1250 | |
| 1251 | /** Create a backend resize layer function |
| 1252 | * |
| 1253 | * @tparam ResizeLayerFunction Backend resize function |
| 1254 | * @tparam TargetInfo Target-specific information |
| 1255 | * |
| 1256 | * @param[in] node Node to create the backend function for |
| 1257 | * |
| 1258 | * @return Backend resize layer function |
| 1259 | */ |
| 1260 | template <typename ResizeLayerFunction, typename TargetInfo> |
| 1261 | std::unique_ptr<IFunction> create_resize_layer(ResizeLayerNode &node) |
| 1262 | { |
| 1263 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 1264 | |
| 1265 | // Extract IO and info |
| 1266 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1267 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1268 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1269 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1270 | const InterpolationPolicy policy = node.policy(); |
| 1271 | |
| 1272 | // Create and configure function |
| 1273 | auto func = support::cpp14::make_unique<ResizeLayerFunction>(); |
| 1274 | func->configure(input, output, policy, BorderMode::CONSTANT); |
| 1275 | |
| 1276 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1277 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1278 | << node.name() |
| 1279 | << " Type: " << node.type() |
| 1280 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 1281 | << " Data Type: " << input->info()->data_type() |
| 1282 | << " Input shape: " << input->info()->tensor_shape() |
| 1283 | << " Output shape: " << output->info()->tensor_shape() |
| 1284 | << " Interpolation: " << policy |
| 1285 | << std::endl); |
| 1286 | |
| 1287 | return std::move(func); |
| 1288 | } |
| 1289 | |
Manuel Bottini | 3f9d4d7 | 2018-10-19 14:04:42 +0100 | [diff] [blame] | 1290 | /** Create a backend ROI align layer function |
| 1291 | * |
| 1292 | * @tparam ROIAlignLayerFunction ROI Align function |
| 1293 | * @tparam TargetInfo Target-specific information |
| 1294 | * |
| 1295 | * @param[in] node Node to create the backend function for |
| 1296 | * |
| 1297 | * @return ROI Align layer function |
| 1298 | */ |
| 1299 | template <typename ROIAlignLayerFunction, typename TargetInfo> |
| 1300 | std::unique_ptr<IFunction> create_roi_align_layer(ROIAlignLayerNode &node) |
| 1301 | { |
| 1302 | validate_node<TargetInfo>(node, 2 /* expected inputs */, 1 /* expected outputs */); |
| 1303 | |
| 1304 | // Extract IO and info |
| 1305 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1306 | typename TargetInfo::TensorType *rois = get_backing_tensor<TargetInfo>(node.input(1)); |
| 1307 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1308 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1309 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1310 | ARM_COMPUTE_ERROR_ON(rois == nullptr); |
| 1311 | |
| 1312 | const ROIPoolingLayerInfo pool_info = node.pooling_info(); |
| 1313 | |
| 1314 | // Create and configure function |
| 1315 | auto func = support::cpp14::make_unique<ROIAlignLayerFunction>(); |
| 1316 | |
| 1317 | func->configure(input, rois, output, pool_info); |
| 1318 | |
| 1319 | // Log info |
Isabella Gottardi | 0ae5de9 | 2019-03-14 10:32:11 +0000 | [diff] [blame] | 1320 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1321 | << node.name() |
| 1322 | << " Type: " << node.type() |
| 1323 | << " Target: " << TargetInfo::TargetType |
Manuel Bottini | 3f9d4d7 | 2018-10-19 14:04:42 +0100 | [diff] [blame] | 1324 | << " Data Type: " << input->info()->data_type() |
| 1325 | << " Input shape: " << input->info()->tensor_shape() |
| 1326 | << " Output shape: " << output->info()->tensor_shape() |
| 1327 | << " ROIs shape: " << rois->info()->tensor_shape() |
| 1328 | << " ROIPooling width: " << pool_info.pooled_width() |
| 1329 | << " ROIPooling height: " << pool_info.pooled_height() |
| 1330 | << std::endl); |
| 1331 | |
| 1332 | return std::move(func); |
| 1333 | } |
| 1334 | |
Michele Di Giorgio | c30b668 | 2018-09-12 17:44:08 +0100 | [diff] [blame] | 1335 | /** Create a backend slice layer function |
| 1336 | * |
| 1337 | * @tparam SliceLayerFunction Backend slice function |
| 1338 | * @tparam TargetInfo Target-specific information |
| 1339 | * |
| 1340 | * @param[in] node Node to create the backend function for |
| 1341 | * |
| 1342 | * @return Backend slice layer function |
| 1343 | */ |
| 1344 | template <typename SliceLayerFunction, typename TargetInfo> |
| 1345 | std::unique_ptr<IFunction> create_slice_layer(SliceLayerNode &node) |
| 1346 | { |
| 1347 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 1348 | |
| 1349 | // Extract IO and info |
| 1350 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1351 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1352 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1353 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1354 | |
| 1355 | // Create and configure function |
| 1356 | auto func = support::cpp14::make_unique<SliceLayerFunction>(); |
| 1357 | func->configure(input, output, node.starts(), node.ends()); |
| 1358 | |
| 1359 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1360 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1361 | << node.name() |
| 1362 | << " Type: " << node.type() |
| 1363 | << " Target: " << TargetInfo::TargetType |
Michele Di Giorgio | c30b668 | 2018-09-12 17:44:08 +0100 | [diff] [blame] | 1364 | << " Data Type: " << input->info()->data_type() |
| 1365 | << " Input shape: " << input->info()->tensor_shape() |
| 1366 | << " Output shape: " << output->info()->tensor_shape() |
| 1367 | << std::endl); |
| 1368 | |
| 1369 | return std::move(func); |
| 1370 | } |
| 1371 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 1372 | /** Create a backend softmax layer function |
| 1373 | * |
| 1374 | * @tparam SoftmaxLayerFunction Backend softmax function |
| 1375 | * @tparam TargetInfo Target-specific information |
| 1376 | * |
| 1377 | * @param[in] node Node to create the backend function for |
| 1378 | * @param[in] ctx Graph context |
| 1379 | * |
| 1380 | * @return Backend softmax layer function |
| 1381 | */ |
| 1382 | template <typename SoftmaxLayerFunction, typename TargetInfo> |
| 1383 | std::unique_ptr<IFunction> create_softmax_layer(SoftmaxLayerNode &node, GraphContext &ctx) |
| 1384 | { |
| 1385 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 1386 | |
| 1387 | // Extract IO and info |
| 1388 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1389 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1390 | const float beta = node.beta(); |
| 1391 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1392 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1393 | |
| 1394 | // Create and configure function |
| 1395 | auto func = support::cpp14::make_unique<SoftmaxLayerFunction>(get_memory_manager(ctx, TargetInfo::TargetType)); |
| 1396 | func->configure(input, output, beta); |
| 1397 | |
| 1398 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1399 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1400 | << node.name() |
| 1401 | << " Type: " << node.type() |
| 1402 | << " Target: " << TargetInfo::TargetType |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 1403 | << " Data Type: " << input->info()->data_type() |
| 1404 | << " Input shape: " << input->info()->tensor_shape() |
| 1405 | << " Output shape: " << output->info()->tensor_shape() |
| 1406 | << std::endl); |
| 1407 | |
| 1408 | return std::move(func); |
| 1409 | } |
Michele Di Giorgio | ec69975 | 2019-03-22 15:25:32 +0000 | [diff] [blame] | 1410 | |
| 1411 | /** Create a backend layer stack function |
| 1412 | * |
| 1413 | * @tparam StackLayerFunction Backend stack function |
| 1414 | * @tparam TargetInfo Target-specific information |
| 1415 | * |
| 1416 | * @param[in] node Node to create the backend function for |
| 1417 | * |
| 1418 | * @return Backend stack layer function |
| 1419 | */ |
| 1420 | template <typename StackLayerFunction, typename TargetInfo> |
| 1421 | std::unique_ptr<arm_compute::IFunction> create_stack_layer(StackLayerNode &node) |
| 1422 | { |
| 1423 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating Stack node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 1424 | ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1); |
| 1425 | |
| 1426 | // Extract IO and info |
| 1427 | std::vector<typename TargetInfo::TensorType *> inputs; |
| 1428 | for(unsigned int i = 0; i < node.num_inputs(); ++i) |
| 1429 | { |
| 1430 | inputs.push_back(get_backing_tensor<TargetInfo>(node.input(i))); |
| 1431 | } |
| 1432 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1433 | const int axis = node.axis(); |
| 1434 | |
| 1435 | // Create and configure function |
| 1436 | auto func = support::cpp14::make_unique<StackLayerFunction>(); |
| 1437 | func->configure(inputs, axis, output); |
| 1438 | |
| 1439 | // Log info |
| 1440 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1441 | << node.name() |
| 1442 | << " Type: " << node.type() |
| 1443 | << " Target: " << TargetInfo::TargetType |
| 1444 | << " Data Type: " << output->info()->data_type() |
| 1445 | << " Inputs shape: " << inputs[0]->info()->tensor_shape() |
| 1446 | << " Output shape: " << output->info()->tensor_shape() |
| 1447 | << " Num Inputs: " << inputs.size() |
| 1448 | << " Axis: " << axis |
| 1449 | << std::endl); |
| 1450 | |
| 1451 | return std::move(func); |
| 1452 | } |
Michalis Spyrou | 4e1c3f3 | 2018-09-20 17:14:03 +0100 | [diff] [blame] | 1453 | /** Create a backend Upsample layer function |
| 1454 | * |
| 1455 | * @tparam UpsampleLayerFunction Backend Upsample function |
| 1456 | * @tparam TargetInfo Target-specific information |
| 1457 | * |
| 1458 | * @param[in] node Node to create the backend function for |
| 1459 | * @param[in] ctx Graph context |
| 1460 | * |
| 1461 | * @return Backend Upsample layer function |
| 1462 | */ |
| 1463 | template <typename UpsampleLayerFunction, typename TargetInfo> |
| 1464 | std::unique_ptr<IFunction> create_upsample_layer(UpsampleLayerNode &node, GraphContext &ctx) |
| 1465 | { |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 1466 | ARM_COMPUTE_UNUSED(ctx); |
Michalis Spyrou | 4e1c3f3 | 2018-09-20 17:14:03 +0100 | [diff] [blame] | 1467 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 1468 | |
| 1469 | // Extract IO and info |
| 1470 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1471 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1472 | const Size2D info = node.info(); |
| 1473 | const InterpolationPolicy upsampling_policy = node.upsampling_policy(); |
| 1474 | ARM_COMPUTE_ERROR_ON(upsampling_policy != InterpolationPolicy::NEAREST_NEIGHBOR); |
| 1475 | ARM_COMPUTE_ERROR_ON(info.x() != 2 || info.y() != 2); |
| 1476 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1477 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1478 | |
| 1479 | // Create and configure function |
| 1480 | auto func = support::cpp14::make_unique<UpsampleLayerFunction>(); |
| 1481 | func->configure(input, output, info, upsampling_policy); |
| 1482 | |
| 1483 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1484 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1485 | << node.name() |
| 1486 | << " Type: " << node.type() |
| 1487 | << " Target: " << TargetInfo::TargetType |
Michalis Spyrou | 4e1c3f3 | 2018-09-20 17:14:03 +0100 | [diff] [blame] | 1488 | << " Data Type: " << input->info()->data_type() |
| 1489 | << " Input shape: " << input->info()->tensor_shape() |
| 1490 | << " Output shape: " << output->info()->tensor_shape() |
| 1491 | << " Strides: " << info |
| 1492 | << " Upsampling policy: " << upsampling_policy |
| 1493 | << std::endl); |
| 1494 | |
| 1495 | return std::move(func); |
| 1496 | } |
Michalis Spyrou | 96f6769 | 2018-09-13 11:39:28 +0100 | [diff] [blame] | 1497 | /** Create a backend YOLO layer function |
| 1498 | * |
| 1499 | * @tparam YoloLayerFunction Backend YOLO function |
| 1500 | * @tparam TargetInfo Target-specific information |
| 1501 | * |
| 1502 | * @param[in] node Node to create the backend function for |
| 1503 | * @param[in] ctx Graph context |
| 1504 | * |
| 1505 | * @return Backend YOLO layer function |
| 1506 | */ |
| 1507 | template <typename YOLOlayerFunction, typename TargetInfo> |
| 1508 | std::unique_ptr<IFunction> create_yolo_layer(YOLOLayerNode &node, GraphContext &ctx) |
| 1509 | { |
Michalis Spyrou | 6bff195 | 2019-10-02 17:22:11 +0100 | [diff] [blame] | 1510 | ARM_COMPUTE_UNUSED(ctx); |
Michalis Spyrou | 96f6769 | 2018-09-13 11:39:28 +0100 | [diff] [blame] | 1511 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 1512 | |
| 1513 | // Extract IO and info |
| 1514 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 1515 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 1516 | const ActivationLayerInfo act_info = node.activation_info(); |
| 1517 | const int32_t num_classes = node.num_classes(); |
| 1518 | ARM_COMPUTE_ERROR_ON(num_classes <= 0); |
| 1519 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 1520 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 1521 | |
| 1522 | // Create and configure function |
| 1523 | auto func = support::cpp14::make_unique<YOLOlayerFunction>(); |
| 1524 | func->configure(input, output, act_info, num_classes); |
| 1525 | |
| 1526 | // Log info |
Pablo Tello | 3252143 | 2018-11-15 14:43:10 +0000 | [diff] [blame] | 1527 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " |
| 1528 | << node.name() |
| 1529 | << " Type: " << node.type() |
| 1530 | << " Target: " << TargetInfo::TargetType |
Michalis Spyrou | 96f6769 | 2018-09-13 11:39:28 +0100 | [diff] [blame] | 1531 | << " Data Type: " << input->info()->data_type() |
| 1532 | << " Input shape: " << input->info()->tensor_shape() |
| 1533 | << " Output shape: " << output->info()->tensor_shape() |
| 1534 | << " Activation function: " << act_info.activation() |
| 1535 | << " Num classes: " << num_classes |
| 1536 | << std::endl); |
| 1537 | |
| 1538 | return std::move(func); |
| 1539 | } |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 1540 | } // namespace detail |
| 1541 | } // namespace backends |
| 1542 | } // namespace graph |
| 1543 | } // namespace arm_compute |
| 1544 | |
| 1545 | #endif /* __ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_FUNCTION_HELPERS_H__ */ |