Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 ARM Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 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" |
| 31 | #include "arm_compute/graph/backends/Utils.h" |
| 32 | #include "arm_compute/graph/nodes/Nodes.h" |
| 33 | |
| 34 | #include "arm_compute/core/Error.h" |
| 35 | #include "arm_compute/core/Helpers.h" |
| 36 | #include "arm_compute/core/ITensorInfo.h" |
| 37 | #include "arm_compute/core/utils/misc/Cast.h" |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace graph |
| 42 | { |
| 43 | namespace backends |
| 44 | { |
| 45 | namespace detail |
| 46 | { |
| 47 | /** Returns backing tensor of a given tensor |
| 48 | * |
| 49 | * @tparam TargetInfo Target information |
| 50 | * |
| 51 | * @param[in] tensor Tensor to extract the backing tensor from |
| 52 | * |
| 53 | * @return Backing tensor if present else nullptr |
| 54 | */ |
| 55 | template <typename TargetInfo> |
| 56 | typename TargetInfo::TensorType *get_backing_tensor(arm_compute::graph::Tensor *tensor) |
| 57 | { |
| 58 | typename TargetInfo::TensorType *backing_tensor = nullptr; |
| 59 | if(tensor != nullptr) |
| 60 | { |
| 61 | ARM_COMPUTE_ERROR_ON(tensor->desc().target != TargetInfo::TargetType); |
| 62 | // Get backing tensor handle |
| 63 | ITensorHandle *tensor_handle = tensor->handle(); |
| 64 | // Get backing tensor |
| 65 | backing_tensor = (tensor_handle != nullptr) ? arm_compute::utils::cast::polymorphic_cast<typename TargetInfo::TensorType *>(&tensor_handle->tensor()) : nullptr; |
| 66 | } |
| 67 | |
| 68 | return backing_tensor; |
| 69 | } |
| 70 | |
| 71 | template <typename TargetInfo> |
| 72 | void validate_node(const INode &node, size_t num_expected_inputs, size_t num_expected_outputs) |
| 73 | { |
| 74 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating " << node.type() |
| 75 | << " Target : " << TargetInfo::TargetType |
| 76 | << " ID : " << node.id() |
| 77 | << " Name: " << node.name() |
| 78 | << std::endl); |
| 79 | |
| 80 | ARM_COMPUTE_ERROR_ON(TargetInfo::TargetType != node.assigned_target()); |
| 81 | ARM_COMPUTE_ERROR_ON(node.num_inputs() != num_expected_inputs); |
| 82 | ARM_COMPUTE_ERROR_ON(node.num_outputs() != num_expected_outputs); |
| 83 | } |
| 84 | |
| 85 | /** Creates a backend activation layer function |
| 86 | * |
| 87 | * @tparam ActivationLayerFunction Backend activation function |
| 88 | * @tparam TargetInfo Target-specific information |
| 89 | * |
| 90 | * @param[in] node Node to create the backend function for |
| 91 | * |
| 92 | * @return Backend activation layer function |
| 93 | */ |
| 94 | template <typename ActivationLayerFunction, typename TargetInfo> |
| 95 | std::unique_ptr<IFunction> create_activation_layer(ActivationLayerNode &node) |
| 96 | { |
| 97 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 98 | |
| 99 | // Extract IO and info |
| 100 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 101 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 102 | const ActivationLayerInfo act_info = node.activation_info(); |
| 103 | |
| 104 | // Create function |
| 105 | auto func = support::cpp14::make_unique<ActivationLayerFunction>(); |
| 106 | func->configure(input, output, act_info); |
| 107 | |
| 108 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 109 | << " Target " << TargetInfo::TargetType |
| 110 | << " Data Type: " << input->info()->data_type() |
| 111 | << " Shape: " << input->info()->tensor_shape() |
| 112 | << " Activation function: " << act_info.activation() |
| 113 | << " a: " << act_info.a() |
| 114 | << " b: " << act_info.b() |
| 115 | << " InPlace : " << is_in_place_operation(input, output) |
| 116 | << std::endl); |
| 117 | |
| 118 | return std::move(func); |
| 119 | } |
| 120 | |
| 121 | /** Create a backend batch normalization layer function |
| 122 | * |
| 123 | * @tparam BatchNormalizationLayerFunction Backend batch normalization function |
| 124 | * @tparam TargetInfo Target-specific information |
| 125 | * |
| 126 | * @param[in] node Node to create the backend function for |
| 127 | * |
| 128 | * @return Backend batch normalization layer function |
| 129 | */ |
| 130 | template <typename BatchNormalizationLayerFunction, typename TargetInfo> |
| 131 | std::unique_ptr<IFunction> create_batch_normalization_layer(BatchNormalizationLayerNode &node) |
| 132 | { |
| 133 | validate_node<TargetInfo>(node, 5 /* expected inputs */, 1 /* expected outputs */); |
| 134 | |
| 135 | // Extract IO and info |
| 136 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 137 | typename TargetInfo::TensorType *mean = get_backing_tensor<TargetInfo>(node.input(1)); |
| 138 | typename TargetInfo::TensorType *var = get_backing_tensor<TargetInfo>(node.input(2)); |
| 139 | typename TargetInfo::TensorType *beta = get_backing_tensor<TargetInfo>(node.input(3)); |
| 140 | typename TargetInfo::TensorType *gamma = get_backing_tensor<TargetInfo>(node.input(4)); |
| 141 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 142 | const float epsilon = node.epsilon(); |
| 143 | const ActivationLayerInfo fused_act = node.fused_activation(); |
| 144 | |
| 145 | // Create and configure function |
| 146 | auto func = support::cpp14::make_unique<BatchNormalizationLayerFunction>(); |
| 147 | func->configure(input, output, mean, var, beta, gamma, epsilon, fused_act); |
| 148 | |
| 149 | // Log info |
| 150 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 151 | << " Target " << TargetInfo::TargetType |
| 152 | << " Data Type: " << input->info()->data_type() |
| 153 | << " Shape: " << input->info()->tensor_shape() |
| 154 | << " Epsilon: " << epsilon << " " |
| 155 | << (fused_act.enabled() ? to_string(fused_act.activation()) : "") |
| 156 | << " InPlace : " << is_in_place_operation(input, output) |
| 157 | << std::endl); |
| 158 | |
| 159 | return std::move(func); |
| 160 | } |
| 161 | |
| 162 | /** Create a backend channel shuffle layer function |
| 163 | * |
| 164 | * @tparam ChannelShuffleLayerFunction Backend channel shuffle function |
| 165 | * @tparam TargetInfo Target-specific information |
| 166 | * |
| 167 | * @param[in] node Node to create the backend function for |
| 168 | * |
| 169 | * @return Backend channel shuffle layer function |
| 170 | */ |
| 171 | template <typename ChannelShuffleLayerFunction, typename TargetInfo> |
| 172 | std::unique_ptr<IFunction> create_channel_shuffle_layer(ChannelShuffleLayerNode &node) |
| 173 | { |
| 174 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 175 | |
| 176 | // Extract IO and info |
| 177 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 178 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 179 | const unsigned int num_groups = node.num_groups(); |
| 180 | |
| 181 | // Create function |
| 182 | auto func = support::cpp14::make_unique<ChannelShuffleLayerFunction>(); |
| 183 | func->configure(input, output, num_groups); |
| 184 | |
| 185 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 186 | << " Target " << TargetInfo::TargetType |
| 187 | << " Data Type: " << input->info()->data_type() |
| 188 | << " Shape: " << input->info()->tensor_shape() |
| 189 | << " Num groups: " << num_groups |
| 190 | << std::endl); |
| 191 | |
| 192 | return std::move(func); |
| 193 | } |
| 194 | |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 195 | /** Create a backend layer concatenate function |
| 196 | * |
| 197 | * @tparam ConcatenateLayerFunction Backend concatenate function |
| 198 | * @tparam TargetInfo Target-specific information |
| 199 | * |
| 200 | * @param[in] node Node to create the backend function for |
| 201 | * |
| 202 | * @return Backend concatenate layer function |
| 203 | */ |
| 204 | template <typename ConcatenateLayerFunction, typename TargetInfo> |
| 205 | std::unique_ptr<arm_compute::IFunction> create_concatenate_layer(ConcatenateLayerNode &node) |
| 206 | { |
| 207 | ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating Concatenate node with ID : " << node.id() << " and Name: " << node.name() << std::endl); |
| 208 | ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1); |
| 209 | |
| 210 | // Return nullptr if depth concatenate is switched off |
| 211 | if(!node.is_enabled()) |
| 212 | { |
| 213 | return nullptr; |
| 214 | } |
| 215 | |
| 216 | // Extract IO and info |
| 217 | std::vector<typename TargetInfo::TensorType *> inputs; |
| 218 | for(unsigned int i = 0; i < node.num_inputs(); ++i) |
| 219 | { |
| 220 | inputs.push_back(get_backing_tensor<TargetInfo>(node.input(i))); |
| 221 | } |
| 222 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 223 | const DataLayoutDimension concat_axis = node.concatenation_axis(); |
| 224 | |
| 225 | // Create and configure function |
| 226 | auto func = support::cpp14::make_unique<ConcatenateLayerFunction>(); |
| 227 | func->configure(inputs, output, concat_axis); |
| 228 | |
| 229 | // Log info |
| 230 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 231 | << " Target " << TargetInfo::TargetType |
| 232 | << " Data Type: " << output->info()->data_type() |
| 233 | << " Shape: " << output->info()->tensor_shape() |
| 234 | << " Num Inputs: " << inputs.size() |
| 235 | << " Axis: " << concat_axis |
| 236 | << std::endl); |
| 237 | |
| 238 | return std::move(func); |
| 239 | } |
| 240 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 241 | /** Create a backend convolution layer function |
| 242 | * |
| 243 | * @tparam ConvolutionLayerFunctions Backend convolution functions |
| 244 | * @tparam TargetInfo Target-specific information |
| 245 | * |
| 246 | * @param[in] node Node to create the backend function for |
| 247 | * @param[in] ctx Graph context |
| 248 | * |
| 249 | * @return Backend convolution layer function |
| 250 | */ |
| 251 | template <typename ConvolutionLayerFunctions, typename TargetInfo> |
| 252 | std::unique_ptr<IFunction> create_convolution_layer(ConvolutionLayerNode &node, GraphContext &ctx) |
| 253 | { |
| 254 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 255 | |
| 256 | // Extract IO and info |
| 257 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 258 | typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1)); |
| 259 | typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2)); |
| 260 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 261 | |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 262 | const bool is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 263 | |
| 264 | if(is_quantized) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 265 | { |
| 266 | biases->info()->set_data_type(DataType::S32); |
| 267 | } |
| 268 | |
| 269 | const PadStrideInfo conv_info = node.convolution_info(); |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 270 | const unsigned int num_groups = node.num_groups(); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 271 | const ConvolutionMethod conv_algorithm = node.convolution_method(); |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 272 | const bool fast_math = node.fast_math_hint() == FastMathHint::Enabled; |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 273 | |
| 274 | // Create and configure function (we assume that functions have been validated before creation) |
| 275 | std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, TargetInfo::TargetType); |
| 276 | std::unique_ptr<IFunction> func; |
| 277 | std::string func_name; |
| 278 | |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 279 | if(conv_algorithm == ConvolutionMethod::Winograd) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 280 | { |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 281 | 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] | 282 | std::tie(func, func_name) = create_named_memory_managed_function<typename ConvolutionLayerFunctions::WinogradConvolutionLayer>( |
| 283 | std::string("WinogradConvolutionLayer"), mm, |
| 284 | input, weights, biases, output, conv_info, ActivationLayerInfo(), fast_math); |
| 285 | } |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 286 | else if(conv_algorithm == ConvolutionMethod::Direct) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 287 | { |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 288 | 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] | 289 | std::tie(func, func_name) = create_named_function<typename ConvolutionLayerFunctions::DirectConvolutionLayer>( |
| 290 | std::string("DirectConvolutionLayer"), |
| 291 | input, weights, biases, output, conv_info); |
| 292 | } |
| 293 | else if(conv_algorithm == ConvolutionMethod::GEMM) |
| 294 | { |
| 295 | std::tie(func, func_name) = create_named_memory_managed_function<typename ConvolutionLayerFunctions::GEMMConvolutionLayer>( |
| 296 | std::string("GEMMConvolutionLayer"), mm, |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 297 | input, weights, biases, output, conv_info, |
| 298 | WeightsInfo(), Size2D(1U, 1U), ActivationLayerInfo(), num_groups); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 299 | } |
| 300 | else |
| 301 | { |
| 302 | std::tie(func, func_name) = create_named_memory_managed_function<typename ConvolutionLayerFunctions::GenericConvolutionLayer>( |
| 303 | std::string("GenericConvolutionLayer"), mm, |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 304 | input, weights, biases, output, conv_info, |
| 305 | WeightsInfo(), Size2D(1U, 1U), ActivationLayerInfo(), fast_math, num_groups); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | // Log info |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 309 | std::ostringstream qss; |
| 310 | if(is_quantized) |
| 311 | { |
| 312 | qss << " Input QuantInfo: " << input->info()->quantization_info() |
| 313 | << " Weights QuantInfo: " << weights->info()->quantization_info() |
| 314 | << " Output QuantInfo: " << output->info()->quantization_info(); |
| 315 | } |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 316 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name |
| 317 | << " Target " << TargetInfo::TargetType |
| 318 | << " Data Type: " << input->info()->data_type() |
Georgios Pinitas | 2a2db59 | 2018-08-15 12:14:46 +0100 | [diff] [blame] | 319 | << " Groups: " << num_groups |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 320 | << qss.str() |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 321 | << " Input shape: " << input->info()->tensor_shape() |
| 322 | << " Weights shape: " << weights->info()->tensor_shape() |
| 323 | << " Output shape: " << output->info()->tensor_shape() |
| 324 | << std::endl); |
| 325 | return func; |
| 326 | } |
| 327 | |
| 328 | /** Create a backend deconvolution layer function |
| 329 | * |
| 330 | * @tparam DeconvolutionLayerFunction Backend deconvolution function |
| 331 | * @tparam TargetInfo Target-specific information |
| 332 | * |
| 333 | * @param[in] node Node to create the backend function for |
| 334 | * @param[in] ctx Graph context |
| 335 | * |
| 336 | * @return Backend deconvolution layer function |
| 337 | */ |
| 338 | template <typename DeconvolutionLayerFunction, typename TargetInfo> |
| 339 | std::unique_ptr<IFunction> create_deconvolution_layer(DeconvolutionLayerNode &node, GraphContext &ctx) |
| 340 | { |
| 341 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 342 | |
| 343 | // Extract IO and info |
| 344 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 345 | typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1)); |
| 346 | typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2)); |
| 347 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 348 | |
| 349 | const PadStrideInfo deconv_info = node.deconvolution_info(); |
| 350 | const Size2D inner_border = node.inner_border(); |
| 351 | |
| 352 | // Create and configure function (we assume that functions have been validated before creation) |
| 353 | std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, TargetInfo::TargetType); |
| 354 | std::unique_ptr<IFunction> func; |
| 355 | |
| 356 | std::tie(func, std::ignore) = create_named_memory_managed_function<DeconvolutionLayerFunction>( |
| 357 | std::string(), mm, |
| 358 | input, weights, biases, output, deconv_info, inner_border.x(), inner_border.y()); |
| 359 | |
| 360 | // Log info |
| 361 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 362 | << " Target " << TargetInfo::TargetType |
| 363 | << " Data Type: " << input->info()->data_type() |
| 364 | << " Input shape: " << input->info()->tensor_shape() |
| 365 | << " Weights shape: " << weights->info()->tensor_shape() |
| 366 | << " Output shape: " << output->info()->tensor_shape() |
| 367 | << std::endl); |
| 368 | return func; |
| 369 | } |
| 370 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 371 | /** Create a backend layer depth-wise convolution function |
| 372 | * |
| 373 | * @tparam DepthwiseConvolutionLayerFunctions Backend depthwise convolution function |
| 374 | * @tparam TargetInfo Target-specific information |
| 375 | * |
| 376 | * @param[in] node Node to create the backend function for |
| 377 | * |
| 378 | * @return Backend depth-wise convolution layer function |
| 379 | */ |
| 380 | template <typename DepthwiseConvolutionLayerFunctions, typename TargetInfo> |
| 381 | std::unique_ptr<IFunction> create_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node) |
| 382 | { |
| 383 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 384 | |
| 385 | // Extract IO and info |
| 386 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 387 | typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1)); |
| 388 | typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2)); |
| 389 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 390 | |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 391 | const bool is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 392 | |
| 393 | if(is_quantized) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 394 | { |
| 395 | biases->info()->set_data_type(DataType::S32); |
| 396 | } |
| 397 | |
| 398 | const PadStrideInfo conv_info = node.convolution_info(); |
| 399 | const DepthwiseConvolutionMethod dwc_algorithm = node.depthwise_convolution_method(); |
| 400 | |
| 401 | // Create and configure function (we assume that functions have been validated before creation) |
| 402 | std::unique_ptr<IFunction> func; |
| 403 | std::string func_name; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 404 | if(dwc_algorithm == DepthwiseConvolutionMethod::Optimized3x3) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 405 | { |
| 406 | std::tie(func, func_name) = create_named_function<typename DepthwiseConvolutionLayerFunctions::DepthwiseConvolutionLayer3x3>( |
| 407 | std::string("DepthwiseConvolutionLayer3x3"), |
| 408 | input, weights, biases, output, conv_info); |
| 409 | } |
| 410 | else |
| 411 | { |
| 412 | std::tie(func, func_name) = create_named_function<typename DepthwiseConvolutionLayerFunctions::GenericDepthwiseConvolutionLayer>( |
| 413 | std::string("DepthwiseConvolutionLayer"), |
| 414 | input, weights, biases, output, conv_info); |
| 415 | } |
| 416 | |
| 417 | // Log info |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 418 | std::ostringstream qss; |
| 419 | if(is_quantized) |
| 420 | { |
| 421 | qss << " Input QuantInfo: " << input->info()->quantization_info() |
| 422 | << " Weights QuantInfo: " << weights->info()->quantization_info() |
| 423 | << " Output QuantInfo: " << output->info()->quantization_info(); |
| 424 | } |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 425 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name |
| 426 | << " Target " << TargetInfo::TargetType |
| 427 | << " Data Type: " << input->info()->data_type() |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 428 | << qss.str() |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 429 | << " Input shape: " << input->info()->tensor_shape() |
| 430 | << " Weights shape: " << weights->info()->tensor_shape() |
| 431 | << " Output shape: " << output->info()->tensor_shape() |
| 432 | << std::endl); |
| 433 | return func; |
| 434 | } |
| 435 | |
| 436 | /** Create a backend element-wise operation layer function |
| 437 | * |
| 438 | * @tparam EltwiseFunctions Backend element-wise function |
| 439 | * @tparam TargetInfo Target-specific information |
| 440 | * |
| 441 | * @param[in] node Node to create the backend function for |
| 442 | * |
| 443 | * @return Backend element-wise operation layer function |
| 444 | */ |
| 445 | template <typename EltwiseFunctions, typename TargetInfo> |
| 446 | std::unique_ptr<IFunction> create_eltwise_layer(EltwiseLayerNode &node) |
| 447 | { |
| 448 | validate_node<TargetInfo>(node, 2 /* expected inputs */, 1 /* expected outputs */); |
| 449 | |
| 450 | // Extract IO and info |
| 451 | typename TargetInfo::TensorType *input1 = get_backing_tensor<TargetInfo>(node.input(0)); |
| 452 | typename TargetInfo::TensorType *input2 = get_backing_tensor<TargetInfo>(node.input(1)); |
| 453 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 454 | const EltwiseOperation eltwise_op = node.eltwise_operation(); |
| 455 | const ConvertPolicy convert_policy = node.convert_policy(); |
| 456 | ARM_COMPUTE_ERROR_ON(input1 == nullptr); |
| 457 | ARM_COMPUTE_ERROR_ON(input2 == nullptr); |
| 458 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 459 | |
| 460 | std::unique_ptr<IFunction> func = nullptr; |
| 461 | std::string func_name; |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 462 | if(eltwise_op == EltwiseOperation::Add) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 463 | { |
| 464 | std::tie(func, func_name) = create_named_function<typename EltwiseFunctions::Addition>( |
| 465 | std::string("ArithmeticAddition"), |
| 466 | input1, input2, output, convert_policy); |
| 467 | } |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 468 | else if(eltwise_op == EltwiseOperation::Sub) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 469 | { |
| 470 | std::tie(func, func_name) = create_named_function<typename EltwiseFunctions::Subtraction>( |
| 471 | std::string("ArithmeticSubtraction"), |
| 472 | input1, input2, output, convert_policy); |
| 473 | } |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 474 | else if(eltwise_op == EltwiseOperation::Mul) |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 475 | { |
| 476 | std::tie(func, func_name) = create_named_function<typename EltwiseFunctions::Multiplication>( |
| 477 | std::string("PixelWiseMultiplication"), |
| 478 | input1, input2, output, 1.f, convert_policy, node.rounding_policy()); |
| 479 | } |
| 480 | else |
| 481 | { |
| 482 | ARM_COMPUTE_ERROR("Unsupported element-wise operation!"); |
| 483 | } |
| 484 | |
| 485 | // Log info |
| 486 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 487 | << " Target " << TargetInfo::TargetType |
| 488 | << " Operation " << func_name |
| 489 | << " Data Type: " << input1->info()->data_type() |
| 490 | << " Shape : " << input1->info()->tensor_shape() |
| 491 | << std::endl); |
| 492 | |
| 493 | return func; |
| 494 | } |
| 495 | |
| 496 | /** Create a backend flatten layer function |
| 497 | * |
| 498 | * @tparam FlattenLayerFunction Backend flatten function |
| 499 | * @tparam TargetInfo Target-specific information |
| 500 | * |
| 501 | * @param[in] node Node to create the backend function for |
| 502 | * |
| 503 | * @return Backend flatten layer function |
| 504 | */ |
| 505 | template <typename FlattenLayerFunction, typename TargetInfo> |
| 506 | std::unique_ptr<IFunction> create_flatten_layer(FlattenLayerNode &node) |
| 507 | { |
| 508 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 509 | |
| 510 | // Extract IO and info |
| 511 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 512 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 513 | |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 514 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 515 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 516 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 517 | // Create and configure function |
| 518 | auto func = support::cpp14::make_unique<FlattenLayerFunction>(); |
| 519 | func->configure(input, output); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 520 | |
| 521 | // Log info |
| 522 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 523 | << " Target " << TargetInfo::TargetType |
| 524 | << " Data Type: " << input->info()->data_type() |
| 525 | << " Input shape: " << input->info()->tensor_shape() |
| 526 | << " Output shape: " << output->info()->tensor_shape() |
| 527 | << std::endl); |
| 528 | |
| 529 | return std::move(func); |
| 530 | } |
| 531 | |
| 532 | /** Create a backend fully connected layer function |
| 533 | * |
| 534 | * @tparam FullyConnectedLayerFunction Backend fully-connected function |
| 535 | * @tparam TargetInfo Target-specific information |
| 536 | * |
| 537 | * @param[in] node Node to create the backend function for |
| 538 | * @param[in] ctx Graph context |
| 539 | * |
| 540 | * @return Backend fully connected layer function |
| 541 | */ |
| 542 | template <typename FullyConnectedLayerFunction, typename TargetInfo> |
| 543 | std::unique_ptr<IFunction> create_fully_connected_layer(FullyConnectedLayerNode &node, GraphContext &ctx) |
| 544 | { |
| 545 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 546 | |
| 547 | // Extract IO and info |
| 548 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 549 | typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1)); |
| 550 | typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2)); |
| 551 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
Georgios Pinitas | 7d66a8e | 2018-07-17 12:28:42 +0100 | [diff] [blame] | 552 | const FullyConnectedLayerInfo fc_info = node.info(); |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 553 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 554 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 555 | ARM_COMPUTE_ERROR_ON(weights == nullptr); |
| 556 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 557 | |
Georgios Pinitas | e222055 | 2018-07-20 13:23:44 +0100 | [diff] [blame] | 558 | // Create and configure function |
| 559 | auto func = support::cpp14::make_unique<FullyConnectedLayerFunction>(get_memory_manager(ctx, TargetInfo::TargetType)); |
| 560 | func->configure(input, weights, biases, output, fc_info); |
| 561 | |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 562 | const bool is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); |
| 563 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 564 | // Log info |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 565 | std::ostringstream qss; |
| 566 | if(is_quantized) |
| 567 | { |
| 568 | qss << " Input QuantInfo: " << input->info()->quantization_info() |
| 569 | << " Weights QuantInfo: " << weights->info()->quantization_info() |
| 570 | << " Output QuantInfo: " << output->info()->quantization_info(); |
| 571 | } |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 572 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 573 | << " Target " << TargetInfo::TargetType |
| 574 | << " Data Type: " << input->info()->data_type() |
Georgios Pinitas | fd7e853 | 2018-09-07 10:51:27 +0100 | [diff] [blame] | 575 | << qss.str() |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 576 | << " Input shape: " << input->info()->tensor_shape() |
| 577 | << " Weights shape: " << weights->info()->tensor_shape() |
| 578 | << " Output shape: " << output->info()->tensor_shape() |
| 579 | << std::endl); |
| 580 | |
| 581 | return std::move(func); |
| 582 | } |
| 583 | |
| 584 | /** Create a backend normalization layer function |
| 585 | * |
| 586 | * @tparam NormalizationLayerFunction Backend normalization function |
| 587 | * @tparam TargetInfo Target-specific information |
| 588 | * |
| 589 | * @param[in] node Node to create the backend function for |
| 590 | * @param[in] ctx Graph context |
| 591 | * |
| 592 | * @return Backend normalization layer function |
| 593 | */ |
| 594 | template <typename NormalizationLayerFunction, typename TargetInfo> |
| 595 | std::unique_ptr<IFunction> create_normalization_layer(NormalizationLayerNode &node, GraphContext &ctx) |
| 596 | { |
| 597 | ARM_COMPUTE_UNUSED(ctx); |
| 598 | |
| 599 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 600 | |
| 601 | // Extract IO and info |
| 602 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 603 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 604 | const NormalizationLayerInfo norm_info = node.normalization_info(); |
| 605 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 606 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 607 | |
| 608 | // Create and configure function |
| 609 | auto func = support::cpp14::make_unique<NormalizationLayerFunction>(); |
| 610 | func->configure(input, output, norm_info); |
| 611 | |
| 612 | // Log info |
| 613 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 614 | << " Target " << TargetInfo::TargetType |
| 615 | << " Data Type: " << input->info()->data_type() |
| 616 | << " Input shape: " << input->info()->tensor_shape() |
| 617 | << " Output shape: " << output->info()->tensor_shape() |
| 618 | << " Normalization info: " << norm_info.type() |
| 619 | << std::endl); |
| 620 | |
| 621 | return std::move(func); |
| 622 | } |
| 623 | |
Michele Di Giorgio | 555d110 | 2018-09-12 13:51:59 +0100 | [diff] [blame] | 624 | /** Create a backend normalize planar YUV layer function |
| 625 | * |
| 626 | * @tparam NormalizePlanarYUVLayerFunction Backend normalize planar YUV function |
| 627 | * @tparam TargetInfo Target-specific information |
| 628 | * |
| 629 | * @param[in] node Node to create the backend function for |
| 630 | * |
| 631 | * @return Backend normalize plnar YUV layer function |
| 632 | */ |
| 633 | template <typename NormalizePlanarYUVLayerFunction, typename TargetInfo> |
| 634 | std::unique_ptr<IFunction> create_normalize_planar_yuv_layer(NormalizePlanarYUVLayerNode &node) |
| 635 | { |
| 636 | validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */); |
| 637 | |
| 638 | // Extract IO and info |
| 639 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 640 | typename TargetInfo::TensorType *mean = get_backing_tensor<TargetInfo>(node.input(1)); |
| 641 | typename TargetInfo::TensorType *std = get_backing_tensor<TargetInfo>(node.input(2)); |
| 642 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 643 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 644 | ARM_COMPUTE_ERROR_ON(mean == nullptr); |
| 645 | ARM_COMPUTE_ERROR_ON(std == nullptr); |
| 646 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 647 | |
| 648 | // Create and configure function |
| 649 | auto func = support::cpp14::make_unique<NormalizePlanarYUVLayerFunction>(); |
| 650 | func->configure(input, output, mean, std); |
| 651 | |
| 652 | // Log info |
| 653 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 654 | << " Target " << TargetInfo::TargetType |
| 655 | << " Data Type: " << input->info()->data_type() |
| 656 | << " Shape: " << input->info()->tensor_shape() |
| 657 | << std::endl); |
| 658 | |
| 659 | return std::move(func); |
| 660 | } |
| 661 | |
Georgios Pinitas | 57c4824 | 2018-08-02 13:41:49 +0100 | [diff] [blame] | 662 | /** Create a backend permute layer function |
| 663 | * |
| 664 | * @tparam PermuteLayerFunction Backend permute function |
| 665 | * @tparam TargetInfo Target-specific information |
| 666 | * |
| 667 | * @param[in] node Node to create the backend function for |
| 668 | * |
| 669 | * @return Backend permute layer function |
| 670 | */ |
| 671 | template <typename PermuteLayerFunction, typename TargetInfo> |
| 672 | std::unique_ptr<IFunction> create_permute_layer(PermuteLayerNode &node) |
| 673 | { |
| 674 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 675 | |
| 676 | // Extract IO and info |
| 677 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 678 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 679 | const PermutationVector &perm = node.permutation_vector(); |
| 680 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 681 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 682 | |
| 683 | // Create and configure function |
| 684 | auto func = support::cpp14::make_unique<PermuteLayerFunction>(); |
| 685 | func->configure(input, output, perm); |
| 686 | |
| 687 | // Log info |
| 688 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 689 | << " Target " << TargetInfo::TargetType |
| 690 | << " Data Type: " << input->info()->data_type() |
| 691 | << " Input shape: " << input->info()->tensor_shape() |
| 692 | << " Output shape: " << output->info()->tensor_shape() |
| 693 | << " Permutation vector: " << perm |
| 694 | << std::endl); |
| 695 | |
| 696 | return std::move(func); |
| 697 | } |
| 698 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 699 | /** Create a backend pooling layer function |
| 700 | * |
| 701 | * @tparam PoolingLayerFunction Backend pooling function |
| 702 | * @tparam TargetInfo Target-specific information |
| 703 | * |
| 704 | * @param[in] node Node to create the backend function for |
| 705 | * |
| 706 | * @return Backend pooling layer function |
| 707 | */ |
| 708 | template <typename PoolingLayerFunction, typename TargetInfo> |
| 709 | std::unique_ptr<IFunction> create_pooling_layer(PoolingLayerNode &node) |
| 710 | { |
| 711 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 712 | |
| 713 | // Extract IO and info |
| 714 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 715 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 716 | const PoolingLayerInfo pool_info = node.pooling_info(); |
| 717 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 718 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 719 | |
| 720 | // Create and configure function |
| 721 | auto func = support::cpp14::make_unique<PoolingLayerFunction>(); |
| 722 | func->configure(input, output, pool_info); |
| 723 | |
| 724 | // Log info |
| 725 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 726 | << " Target " << TargetInfo::TargetType |
| 727 | << " Data Type: " << input->info()->data_type() |
| 728 | << " Input shape: " << input->info()->tensor_shape() |
| 729 | << " Output shape: " << output->info()->tensor_shape() |
| 730 | << " Pooling info: " << pool_info.pool_type() |
| 731 | << std::endl); |
| 732 | |
| 733 | return std::move(func); |
| 734 | } |
| 735 | |
Gian Marco Iodice | 23e2479 | 2018-09-07 15:32:14 +0100 | [diff] [blame] | 736 | /** Create a backend reorg layer function |
| 737 | * |
| 738 | * @tparam ReorgLayerFunction Backend reshape function |
| 739 | * @tparam TargetInfo Target-specific information |
| 740 | * |
| 741 | * @param[in] node Node to create the backend function for |
| 742 | * |
| 743 | * @return Backend reshape layer function |
| 744 | */ |
| 745 | template <typename ReorgLayerFunction, typename TargetInfo> |
| 746 | std::unique_ptr<IFunction> create_reorg_layer(ReorgLayerNode &node) |
| 747 | { |
| 748 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 749 | |
| 750 | // Extract IO and info |
| 751 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 752 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 753 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 754 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 755 | |
| 756 | // Create and configure function |
| 757 | auto func = support::cpp14::make_unique<ReorgLayerFunction>(); |
| 758 | func->configure(input, output, node.stride()); |
| 759 | |
| 760 | // Log info |
| 761 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 762 | << " Target " << TargetInfo::TargetType |
| 763 | << " Data Type: " << input->info()->data_type() |
| 764 | << " Input shape: " << input->info()->tensor_shape() |
| 765 | << " Output shape: " << output->info()->tensor_shape() |
| 766 | << std::endl); |
| 767 | |
| 768 | return std::move(func); |
| 769 | } |
| 770 | |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 771 | /** Create a backend reshape layer function |
| 772 | * |
| 773 | * @tparam ReshapeLayerFunction Backend reshape function |
| 774 | * @tparam TargetInfo Target-specific information |
| 775 | * |
| 776 | * @param[in] node Node to create the backend function for |
| 777 | * |
| 778 | * @return Backend reshape layer function |
| 779 | */ |
| 780 | template <typename ReshapeLayerFunction, typename TargetInfo> |
| 781 | std::unique_ptr<IFunction> create_reshape_layer(ReshapeLayerNode &node) |
| 782 | { |
| 783 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 784 | |
| 785 | // Extract IO and info |
| 786 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 787 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 788 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 789 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 790 | |
| 791 | // Create and configure function |
| 792 | auto func = support::cpp14::make_unique<ReshapeLayerFunction>(); |
| 793 | func->configure(input, output); |
| 794 | |
| 795 | // Log info |
| 796 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 797 | << " Target " << TargetInfo::TargetType |
| 798 | << " Data Type: " << input->info()->data_type() |
| 799 | << " Input shape: " << input->info()->tensor_shape() |
| 800 | << " Output shape: " << output->info()->tensor_shape() |
| 801 | << std::endl); |
| 802 | |
| 803 | return std::move(func); |
| 804 | } |
| 805 | |
| 806 | /** Create a backend resize layer function |
| 807 | * |
| 808 | * @tparam ResizeLayerFunction Backend resize function |
| 809 | * @tparam TargetInfo Target-specific information |
| 810 | * |
| 811 | * @param[in] node Node to create the backend function for |
| 812 | * |
| 813 | * @return Backend resize layer function |
| 814 | */ |
| 815 | template <typename ResizeLayerFunction, typename TargetInfo> |
| 816 | std::unique_ptr<IFunction> create_resize_layer(ResizeLayerNode &node) |
| 817 | { |
| 818 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 819 | |
| 820 | // Extract IO and info |
| 821 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 822 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 823 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 824 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 825 | const InterpolationPolicy policy = node.policy(); |
| 826 | |
| 827 | // Create and configure function |
| 828 | auto func = support::cpp14::make_unique<ResizeLayerFunction>(); |
| 829 | func->configure(input, output, policy, BorderMode::CONSTANT); |
| 830 | |
| 831 | // Log info |
| 832 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 833 | << " Target " << TargetInfo::TargetType |
| 834 | << " Data Type: " << input->info()->data_type() |
| 835 | << " Input shape: " << input->info()->tensor_shape() |
| 836 | << " Output shape: " << output->info()->tensor_shape() |
| 837 | << " Interpolation: " << policy |
| 838 | << std::endl); |
| 839 | |
| 840 | return std::move(func); |
| 841 | } |
| 842 | |
| 843 | /** Create a backend softmax layer function |
| 844 | * |
| 845 | * @tparam SoftmaxLayerFunction Backend softmax function |
| 846 | * @tparam TargetInfo Target-specific information |
| 847 | * |
| 848 | * @param[in] node Node to create the backend function for |
| 849 | * @param[in] ctx Graph context |
| 850 | * |
| 851 | * @return Backend softmax layer function |
| 852 | */ |
| 853 | template <typename SoftmaxLayerFunction, typename TargetInfo> |
| 854 | std::unique_ptr<IFunction> create_softmax_layer(SoftmaxLayerNode &node, GraphContext &ctx) |
| 855 | { |
| 856 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 857 | |
| 858 | // Extract IO and info |
| 859 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 860 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 861 | const float beta = node.beta(); |
| 862 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 863 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 864 | |
| 865 | // Create and configure function |
| 866 | auto func = support::cpp14::make_unique<SoftmaxLayerFunction>(get_memory_manager(ctx, TargetInfo::TargetType)); |
| 867 | func->configure(input, output, beta); |
| 868 | |
| 869 | // Log info |
| 870 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 871 | << " Target " << TargetInfo::TargetType |
| 872 | << " Data Type: " << input->info()->data_type() |
| 873 | << " Input shape: " << input->info()->tensor_shape() |
| 874 | << " Output shape: " << output->info()->tensor_shape() |
| 875 | << std::endl); |
| 876 | |
| 877 | return std::move(func); |
| 878 | } |
Michalis Spyrou | 96f6769 | 2018-09-13 11:39:28 +0100 | [diff] [blame] | 879 | /** Create a backend YOLO layer function |
| 880 | * |
| 881 | * @tparam YoloLayerFunction Backend YOLO function |
| 882 | * @tparam TargetInfo Target-specific information |
| 883 | * |
| 884 | * @param[in] node Node to create the backend function for |
| 885 | * @param[in] ctx Graph context |
| 886 | * |
| 887 | * @return Backend YOLO layer function |
| 888 | */ |
| 889 | template <typename YOLOlayerFunction, typename TargetInfo> |
| 890 | std::unique_ptr<IFunction> create_yolo_layer(YOLOLayerNode &node, GraphContext &ctx) |
| 891 | { |
| 892 | validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */); |
| 893 | |
| 894 | // Extract IO and info |
| 895 | typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0)); |
| 896 | typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0)); |
| 897 | const ActivationLayerInfo act_info = node.activation_info(); |
| 898 | const int32_t num_classes = node.num_classes(); |
| 899 | ARM_COMPUTE_ERROR_ON(num_classes <= 0); |
| 900 | ARM_COMPUTE_ERROR_ON(input == nullptr); |
| 901 | ARM_COMPUTE_ERROR_ON(output == nullptr); |
| 902 | |
| 903 | // Create and configure function |
| 904 | auto func = support::cpp14::make_unique<YOLOlayerFunction>(); |
| 905 | func->configure(input, output, act_info, num_classes); |
| 906 | |
| 907 | // Log info |
| 908 | ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type() |
| 909 | << " Target " << TargetInfo::TargetType |
| 910 | << " Data Type: " << input->info()->data_type() |
| 911 | << " Input shape: " << input->info()->tensor_shape() |
| 912 | << " Output shape: " << output->info()->tensor_shape() |
| 913 | << " Activation function: " << act_info.activation() |
| 914 | << " Num classes: " << num_classes |
| 915 | << std::endl); |
| 916 | |
| 917 | return std::move(func); |
| 918 | } |
Georgios Pinitas | da2491f | 2018-06-01 17:49:09 +0100 | [diff] [blame] | 919 | } // namespace detail |
| 920 | } // namespace backends |
| 921 | } // namespace graph |
| 922 | } // namespace arm_compute |
| 923 | |
| 924 | #endif /* __ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_FUNCTION_HELPERS_H__ */ |