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