COMPMID-1151: Templatize FunctionFactories.
Change-Id: Id1c68c3bf442c3fcff265041b260d007db7593cb
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/134027
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
diff --git a/arm_compute/graph/TypePrinter.h b/arm_compute/graph/TypePrinter.h
index edce77c..36d924b 100644
--- a/arm_compute/graph/TypePrinter.h
+++ b/arm_compute/graph/TypePrinter.h
@@ -156,6 +156,77 @@
return os;
}
+inline ::std::ostream &operator<<(::std::ostream &os, const NodeType &node_type)
+{
+ switch(node_type)
+ {
+ case NodeType::ActivationLayer:
+ os << "ActivationLayer";
+ break;
+ case NodeType::BatchNormalizationLayer:
+ os << "BatchNormalizationLayer";
+ break;
+ case NodeType::ChannelShuffleLayer:
+ os << "ChannelShuffleLayer";
+ break;
+ case NodeType::ConvolutionLayer:
+ os << "ConvolutionLayer";
+ break;
+ case NodeType::DeconvolutionLayer:
+ os << "DeconvolutionLayer";
+ break;
+ case NodeType::DepthConcatenateLayer:
+ os << "DepthConcatenateLayer";
+ break;
+ case NodeType::DepthwiseConvolutionLayer:
+ os << "DepthwiseConvolutionLayer";
+ break;
+ case NodeType::EltwiseLayer:
+ os << "EltwiseLayer";
+ break;
+ case NodeType::FlattenLayer:
+ os << "FlattenLayer";
+ break;
+ case NodeType::FullyConnectedLayer:
+ os << "FullyConnectedLayer";
+ break;
+ case NodeType::NormalizationLayer:
+ os << "NormalizationLayer";
+ break;
+ case NodeType::PoolingLayer:
+ os << "PoolingLayer";
+ break;
+ case NodeType::ReshapeLayer:
+ os << "ReshapeLayer";
+ break;
+ case NodeType::ResizeLayer:
+ os << "ResizeLayer";
+ break;
+ case NodeType::SoftmaxLayer:
+ os << "SoftmaxLayer";
+ break;
+ case NodeType::SplitLayer:
+ os << "SplitLayer";
+ break;
+ case NodeType::Input:
+ os << "Input";
+ break;
+ case NodeType::Output:
+ os << "Output";
+ break;
+ case NodeType::Const:
+ os << "Const";
+ break;
+ case NodeType::Dummy:
+ os << "Dummy";
+ break;
+ default:
+ ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
+ }
+
+ return os;
+}
+
/** Formatted output of the activation function type. */
inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function)
{
diff --git a/arm_compute/graph/backends/FunctionHelpers.h b/arm_compute/graph/backends/FunctionHelpers.h
new file mode 100644
index 0000000..16536bc
--- /dev/null
+++ b/arm_compute/graph/backends/FunctionHelpers.h
@@ -0,0 +1,737 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_FUNCTION_HELPERS_H__
+#define __ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_FUNCTION_HELPERS_H__
+
+#include "arm_compute/graph/Logger.h"
+#include "arm_compute/graph/Tensor.h"
+#include "arm_compute/graph/TypePrinter.h"
+#include "arm_compute/graph/Types.h"
+#include "arm_compute/graph/backends/Utils.h"
+#include "arm_compute/graph/nodes/Nodes.h"
+
+#include "arm_compute/core/Error.h"
+#include "arm_compute/core/Helpers.h"
+#include "arm_compute/core/ITensorInfo.h"
+#include "arm_compute/core/utils/misc/Cast.h"
+
+namespace arm_compute
+{
+namespace graph
+{
+namespace backends
+{
+namespace detail
+{
+/** Returns backing tensor of a given tensor
+ *
+ * @tparam TargetInfo Target information
+ *
+ * @param[in] tensor Tensor to extract the backing tensor from
+ *
+ * @return Backing tensor if present else nullptr
+ */
+template <typename TargetInfo>
+typename TargetInfo::TensorType *get_backing_tensor(arm_compute::graph::Tensor *tensor)
+{
+ typename TargetInfo::TensorType *backing_tensor = nullptr;
+ if(tensor != nullptr)
+ {
+ ARM_COMPUTE_ERROR_ON(tensor->desc().target != TargetInfo::TargetType);
+ // Get backing tensor handle
+ ITensorHandle *tensor_handle = tensor->handle();
+ // Get backing tensor
+ backing_tensor = (tensor_handle != nullptr) ? arm_compute::utils::cast::polymorphic_cast<typename TargetInfo::TensorType *>(&tensor_handle->tensor()) : nullptr;
+ }
+
+ return backing_tensor;
+}
+
+template <typename TargetInfo>
+void validate_node(const INode &node, size_t num_expected_inputs, size_t num_expected_outputs)
+{
+ ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating " << node.type()
+ << " Target : " << TargetInfo::TargetType
+ << " ID : " << node.id()
+ << " Name: " << node.name()
+ << std::endl);
+
+ ARM_COMPUTE_ERROR_ON(TargetInfo::TargetType != node.assigned_target());
+ ARM_COMPUTE_ERROR_ON(node.num_inputs() != num_expected_inputs);
+ ARM_COMPUTE_ERROR_ON(node.num_outputs() != num_expected_outputs);
+}
+
+/** Creates a backend activation layer function
+ *
+ * @tparam ActivationLayerFunction Backend activation function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend activation layer function
+ */
+template <typename ActivationLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_activation_layer(ActivationLayerNode &node)
+{
+ validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+ const ActivationLayerInfo act_info = node.activation_info();
+
+ // Create function
+ auto func = support::cpp14::make_unique<ActivationLayerFunction>();
+ func->configure(input, output, act_info);
+
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Shape: " << input->info()->tensor_shape()
+ << " Activation function: " << act_info.activation()
+ << " a: " << act_info.a()
+ << " b: " << act_info.b()
+ << " InPlace : " << is_in_place_operation(input, output)
+ << std::endl);
+
+ return std::move(func);
+}
+
+/** Create a backend batch normalization layer function
+ *
+ * @tparam BatchNormalizationLayerFunction Backend batch normalization function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend batch normalization layer function
+ */
+template <typename BatchNormalizationLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_batch_normalization_layer(BatchNormalizationLayerNode &node)
+{
+ validate_node<TargetInfo>(node, 5 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *mean = get_backing_tensor<TargetInfo>(node.input(1));
+ typename TargetInfo::TensorType *var = get_backing_tensor<TargetInfo>(node.input(2));
+ typename TargetInfo::TensorType *beta = get_backing_tensor<TargetInfo>(node.input(3));
+ typename TargetInfo::TensorType *gamma = get_backing_tensor<TargetInfo>(node.input(4));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+ const float epsilon = node.epsilon();
+ const ActivationLayerInfo fused_act = node.fused_activation();
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<BatchNormalizationLayerFunction>();
+ func->configure(input, output, mean, var, beta, gamma, epsilon, fused_act);
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Shape: " << input->info()->tensor_shape()
+ << " Epsilon: " << epsilon << " "
+ << (fused_act.enabled() ? to_string(fused_act.activation()) : "")
+ << " InPlace : " << is_in_place_operation(input, output)
+ << std::endl);
+
+ return std::move(func);
+}
+
+/** Create a backend channel shuffle layer function
+ *
+ * @tparam ChannelShuffleLayerFunction Backend channel shuffle function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend channel shuffle layer function
+ */
+template <typename ChannelShuffleLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_channel_shuffle_layer(ChannelShuffleLayerNode &node)
+{
+ validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+ const unsigned int num_groups = node.num_groups();
+
+ // Create function
+ auto func = support::cpp14::make_unique<ChannelShuffleLayerFunction>();
+ func->configure(input, output, num_groups);
+
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Shape: " << input->info()->tensor_shape()
+ << " Num groups: " << num_groups
+ << std::endl);
+
+ return std::move(func);
+}
+
+/** Create a backend convolution layer function
+ *
+ * @tparam ConvolutionLayerFunctions Backend convolution functions
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ * @param[in] ctx Graph context
+ *
+ * @return Backend convolution layer function
+ */
+template <typename ConvolutionLayerFunctions, typename TargetInfo>
+std::unique_ptr<IFunction> create_convolution_layer(ConvolutionLayerNode &node, GraphContext &ctx)
+{
+ validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1));
+ typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+
+ if(is_data_type_quantized_asymmetric(input->info()->data_type()))
+ {
+ biases->info()->set_data_type(DataType::S32);
+ }
+
+ const PadStrideInfo conv_info = node.convolution_info();
+ const ConvolutionMethod conv_algorithm = node.convolution_method();
+ const bool fast_math = node.fast_math_hint() == FastMathHint::ENABLED;
+
+ // Create and configure function (we assume that functions have been validated before creation)
+ std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, TargetInfo::TargetType);
+ std::unique_ptr<IFunction> func;
+ std::string func_name;
+
+ if(conv_algorithm == ConvolutionMethod::WINOGRAD)
+ {
+ std::tie(func, func_name) = create_named_memory_managed_function<typename ConvolutionLayerFunctions::WinogradConvolutionLayer>(
+ std::string("WinogradConvolutionLayer"), mm,
+ input, weights, biases, output, conv_info, ActivationLayerInfo(), fast_math);
+ }
+ else if(conv_algorithm == ConvolutionMethod::DIRECT)
+ {
+ std::tie(func, func_name) = create_named_function<typename ConvolutionLayerFunctions::DirectConvolutionLayer>(
+ std::string("DirectConvolutionLayer"),
+ input, weights, biases, output, conv_info);
+ }
+ else if(conv_algorithm == ConvolutionMethod::GEMM)
+ {
+ std::tie(func, func_name) = create_named_memory_managed_function<typename ConvolutionLayerFunctions::GEMMConvolutionLayer>(
+ std::string("GEMMConvolutionLayer"), mm,
+ input, weights, biases, output, conv_info);
+ }
+ else
+ {
+ std::tie(func, func_name) = create_named_memory_managed_function<typename ConvolutionLayerFunctions::GenericConvolutionLayer>(
+ std::string("GenericConvolutionLayer"), mm,
+ input, weights, biases, output, conv_info, WeightsInfo(), Size2D(1U, 1U), ActivationLayerInfo(), fast_math);
+ }
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input QuantInfo: " << input->info()->quantization_info()
+ << " Weights QuantInfo: " << weights->info()->quantization_info()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Weights shape: " << weights->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << std::endl);
+ return func;
+}
+
+/** Create a backend deconvolution layer function
+ *
+ * @tparam DeconvolutionLayerFunction Backend deconvolution function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ * @param[in] ctx Graph context
+ *
+ * @return Backend deconvolution layer function
+ */
+template <typename DeconvolutionLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_deconvolution_layer(DeconvolutionLayerNode &node, GraphContext &ctx)
+{
+ validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1));
+ typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+
+ const PadStrideInfo deconv_info = node.deconvolution_info();
+ const Size2D inner_border = node.inner_border();
+
+ // Create and configure function (we assume that functions have been validated before creation)
+ std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, TargetInfo::TargetType);
+ std::unique_ptr<IFunction> func;
+
+ std::tie(func, std::ignore) = create_named_memory_managed_function<DeconvolutionLayerFunction>(
+ std::string(), mm,
+ input, weights, biases, output, deconv_info, inner_border.x(), inner_border.y());
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Weights shape: " << weights->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << std::endl);
+ return func;
+}
+
+/** Create a backend layer depth concatenate function
+ *
+ * @tparam DepthConcatenateLayerFunction Backend depth concatenate function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend depth concatenate layer function
+ */
+template <typename DepthConcatenateLayerFunction, typename TargetInfo>
+std::unique_ptr<arm_compute::IFunction> create_depth_concatenate_layer(DepthConcatenateLayerNode &node)
+{
+ ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating DepthConcatenate node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
+ ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
+
+ // Return nullptr if depth concatenate is switched off
+ if(!node.is_enabled())
+ {
+ return nullptr;
+ }
+
+ // Extract IO and info
+ std::vector<typename TargetInfo::TensorType *> inputs;
+ for(unsigned int i = 0; i < node.num_inputs(); ++i)
+ {
+ inputs.push_back(get_backing_tensor<TargetInfo>(node.input(i)));
+ }
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<DepthConcatenateLayerFunction>();
+ func->configure(inputs, output);
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << output->info()->data_type()
+ << " Shape: " << output->info()->tensor_shape()
+ << " Num Inputs: " << inputs.size()
+ << std::endl);
+
+ return std::move(func);
+}
+
+/** Create a backend layer depth-wise convolution function
+ *
+ * @tparam DepthwiseConvolutionLayerFunctions Backend depthwise convolution function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend depth-wise convolution layer function
+ */
+template <typename DepthwiseConvolutionLayerFunctions, typename TargetInfo>
+std::unique_ptr<IFunction> create_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node)
+{
+ validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1));
+ typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+
+ if(is_data_type_quantized_asymmetric(input->info()->data_type()))
+ {
+ biases->info()->set_data_type(DataType::S32);
+ }
+
+ const PadStrideInfo conv_info = node.convolution_info();
+ const DepthwiseConvolutionMethod dwc_algorithm = node.depthwise_convolution_method();
+
+ // Create and configure function (we assume that functions have been validated before creation)
+ std::unique_ptr<IFunction> func;
+ std::string func_name;
+ if(dwc_algorithm == DepthwiseConvolutionMethod::OPTIMIZED_3x3)
+ {
+ std::tie(func, func_name) = create_named_function<typename DepthwiseConvolutionLayerFunctions::DepthwiseConvolutionLayer3x3>(
+ std::string("DepthwiseConvolutionLayer3x3"),
+ input, weights, biases, output, conv_info);
+ }
+ else
+ {
+ std::tie(func, func_name) = create_named_function<typename DepthwiseConvolutionLayerFunctions::GenericDepthwiseConvolutionLayer>(
+ std::string("DepthwiseConvolutionLayer"),
+ input, weights, biases, output, conv_info);
+ }
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input QuantInfo: " << input->info()->quantization_info()
+ << " Weights QuantInfo: " << weights->info()->quantization_info()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Weights shape: " << weights->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << std::endl);
+ return func;
+}
+
+/** Create a backend element-wise operation layer function
+ *
+ * @tparam EltwiseFunctions Backend element-wise function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend element-wise operation layer function
+ */
+template <typename EltwiseFunctions, typename TargetInfo>
+std::unique_ptr<IFunction> create_eltwise_layer(EltwiseLayerNode &node)
+{
+ validate_node<TargetInfo>(node, 2 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input1 = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *input2 = get_backing_tensor<TargetInfo>(node.input(1));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+ const EltwiseOperation eltwise_op = node.eltwise_operation();
+ const ConvertPolicy convert_policy = node.convert_policy();
+ ARM_COMPUTE_ERROR_ON(input1 == nullptr);
+ ARM_COMPUTE_ERROR_ON(input2 == nullptr);
+ ARM_COMPUTE_ERROR_ON(output == nullptr);
+
+ std::unique_ptr<IFunction> func = nullptr;
+ std::string func_name;
+ if(eltwise_op == EltwiseOperation::ADD)
+ {
+ std::tie(func, func_name) = create_named_function<typename EltwiseFunctions::Addition>(
+ std::string("ArithmeticAddition"),
+ input1, input2, output, convert_policy);
+ }
+ else if(eltwise_op == EltwiseOperation::SUB)
+ {
+ std::tie(func, func_name) = create_named_function<typename EltwiseFunctions::Subtraction>(
+ std::string("ArithmeticSubtraction"),
+ input1, input2, output, convert_policy);
+ }
+ else if(eltwise_op == EltwiseOperation::MUL)
+ {
+ std::tie(func, func_name) = create_named_function<typename EltwiseFunctions::Multiplication>(
+ std::string("PixelWiseMultiplication"),
+ input1, input2, output, 1.f, convert_policy, node.rounding_policy());
+ }
+ else
+ {
+ ARM_COMPUTE_ERROR("Unsupported element-wise operation!");
+ }
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Operation " << func_name
+ << " Data Type: " << input1->info()->data_type()
+ << " Shape : " << input1->info()->tensor_shape()
+ << std::endl);
+
+ return func;
+}
+
+/** Create a backend flatten layer function
+ *
+ * @tparam FlattenLayerFunction Backend flatten function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend flatten layer function
+ */
+template <typename FlattenLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_flatten_layer(FlattenLayerNode &node)
+{
+ validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<FlattenLayerFunction>();
+ func->configure(input, output);
+ ARM_COMPUTE_ERROR_ON(input == nullptr);
+ ARM_COMPUTE_ERROR_ON(output == nullptr);
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << std::endl);
+
+ return std::move(func);
+}
+
+/** Create a backend fully connected layer function
+ *
+ * @tparam FullyConnectedLayerFunction Backend fully-connected function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ * @param[in] ctx Graph context
+ *
+ * @return Backend fully connected layer function
+ */
+template <typename FullyConnectedLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_fully_connected_layer(FullyConnectedLayerNode &node, GraphContext &ctx)
+{
+ validate_node<TargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *weights = get_backing_tensor<TargetInfo>(node.input(1));
+ typename TargetInfo::TensorType *biases = get_backing_tensor<TargetInfo>(node.input(2));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<FullyConnectedLayerFunction>(get_memory_manager(ctx, TargetInfo::TargetType));
+ func->configure(input, weights, biases, output);
+ ARM_COMPUTE_ERROR_ON(input == nullptr);
+ ARM_COMPUTE_ERROR_ON(weights == nullptr);
+ ARM_COMPUTE_ERROR_ON(output == nullptr);
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Weights shape: " << weights->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << std::endl);
+
+ return std::move(func);
+}
+
+/** Create a backend normalization layer function
+ *
+ * @tparam NormalizationLayerFunction Backend normalization function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ * @param[in] ctx Graph context
+ *
+ * @return Backend normalization layer function
+ */
+template <typename NormalizationLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_normalization_layer(NormalizationLayerNode &node, GraphContext &ctx)
+{
+ ARM_COMPUTE_UNUSED(ctx);
+
+ validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+ const NormalizationLayerInfo norm_info = node.normalization_info();
+ ARM_COMPUTE_ERROR_ON(input == nullptr);
+ ARM_COMPUTE_ERROR_ON(output == nullptr);
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<NormalizationLayerFunction>();
+ func->configure(input, output, norm_info);
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << " Normalization info: " << norm_info.type()
+ << std::endl);
+
+ return std::move(func);
+}
+
+/** Create a backend pooling layer function
+ *
+ * @tparam PoolingLayerFunction Backend pooling function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend pooling layer function
+ */
+template <typename PoolingLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_pooling_layer(PoolingLayerNode &node)
+{
+ validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+ const PoolingLayerInfo pool_info = node.pooling_info();
+ ARM_COMPUTE_ERROR_ON(input == nullptr);
+ ARM_COMPUTE_ERROR_ON(output == nullptr);
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<PoolingLayerFunction>();
+ func->configure(input, output, pool_info);
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << " Pooling info: " << pool_info.pool_type()
+ << std::endl);
+
+ return std::move(func);
+}
+
+/** Create a backend reshape layer function
+ *
+ * @tparam ReshapeLayerFunction Backend reshape function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend reshape layer function
+ */
+template <typename ReshapeLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_reshape_layer(ReshapeLayerNode &node)
+{
+ validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+ ARM_COMPUTE_ERROR_ON(input == nullptr);
+ ARM_COMPUTE_ERROR_ON(output == nullptr);
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<ReshapeLayerFunction>();
+ func->configure(input, output);
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << std::endl);
+
+ return std::move(func);
+}
+
+/** Create a backend resize layer function
+ *
+ * @tparam ResizeLayerFunction Backend resize function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ *
+ * @return Backend resize layer function
+ */
+template <typename ResizeLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_resize_layer(ResizeLayerNode &node)
+{
+ validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+ ARM_COMPUTE_ERROR_ON(input == nullptr);
+ ARM_COMPUTE_ERROR_ON(output == nullptr);
+ const InterpolationPolicy policy = node.policy();
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<ResizeLayerFunction>();
+ func->configure(input, output, policy, BorderMode::CONSTANT);
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << " Interpolation: " << policy
+ << std::endl);
+
+ return std::move(func);
+}
+
+/** Create a backend softmax layer function
+ *
+ * @tparam SoftmaxLayerFunction Backend softmax function
+ * @tparam TargetInfo Target-specific information
+ *
+ * @param[in] node Node to create the backend function for
+ * @param[in] ctx Graph context
+ *
+ * @return Backend softmax layer function
+ */
+template <typename SoftmaxLayerFunction, typename TargetInfo>
+std::unique_ptr<IFunction> create_softmax_layer(SoftmaxLayerNode &node, GraphContext &ctx)
+{
+ validate_node<TargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */);
+
+ // Extract IO and info
+ typename TargetInfo::TensorType *input = get_backing_tensor<TargetInfo>(node.input(0));
+ typename TargetInfo::TensorType *output = get_backing_tensor<TargetInfo>(node.output(0));
+ const float beta = node.beta();
+ ARM_COMPUTE_ERROR_ON(input == nullptr);
+ ARM_COMPUTE_ERROR_ON(output == nullptr);
+
+ // Create and configure function
+ auto func = support::cpp14::make_unique<SoftmaxLayerFunction>(get_memory_manager(ctx, TargetInfo::TargetType));
+ func->configure(input, output, beta);
+
+ // Log info
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << TargetInfo::TargetType
+ << " Data Type: " << input->info()->data_type()
+ << " Input shape: " << input->info()->tensor_shape()
+ << " Output shape: " << output->info()->tensor_shape()
+ << std::endl);
+
+ return std::move(func);
+}
+} // namespace detail
+} // namespace backends
+} // namespace graph
+} // namespace arm_compute
+
+#endif /* __ARM_COMPUTE_GRAPH_BACKENDS_DETAIL_FUNCTION_HELPERS_H__ */
diff --git a/src/graph/backends/CL/CLFunctionsFactory.cpp b/src/graph/backends/CL/CLFunctionsFactory.cpp
index 90ea81f..4d67348 100644
--- a/src/graph/backends/CL/CLFunctionsFactory.cpp
+++ b/src/graph/backends/CL/CLFunctionsFactory.cpp
@@ -25,16 +25,9 @@
#include "arm_compute/core/utils/misc/Cast.h"
#include "arm_compute/graph/Graph.h"
-#include "arm_compute/graph/GraphContext.h"
-#include "arm_compute/graph/Logger.h"
-#include "arm_compute/graph/TypePrinter.h"
-#include "arm_compute/graph/Types.h"
-#include "arm_compute/graph/backends/Utils.h"
-#include "arm_compute/graph/nodes/Nodes.h"
+#include "arm_compute/graph/backends/FunctionHelpers.h"
#include "arm_compute/runtime/CL/CLFunctions.h"
-#include "support/ToolchainSupport.h"
-
using namespace arm_compute::utils::cast;
namespace arm_compute
@@ -43,634 +36,38 @@
{
namespace backends
{
-namespace
+/** Target specific information structure used to pass information to the layer templates */
+struct CLTargetInfo
{
-/** Returns backing tensor of a given tensor
- *
- * @param[in] tensor Tensor to extract the backing tensor from
- *
- * @return Backing tensor if present else nullptr
- */
-arm_compute::ICLTensor *get_backing_tensor(arm_compute::graph::Tensor *tensor)
+ using TensorType = arm_compute::ICLTensor;
+ static Target TargetType;
+};
+
+Target CLTargetInfo::TargetType = Target::CL;
+
+/** Collection of CL convolution functions */
+struct CLConvolutionLayerFunctions
{
- arm_compute::ICLTensor *backing_tensor = nullptr;
- if(tensor != nullptr)
- {
- ARM_COMPUTE_ERROR_ON(tensor->desc().target != arm_compute::graph::Target::CL);
- // Get backing tensor handle
- ITensorHandle *tensor_handle = tensor->handle();
- // Get backing tensor
- backing_tensor = (tensor_handle != nullptr) ? polymorphic_cast<ICLTensor *>(&tensor_handle->tensor()) : nullptr;
- }
+ using GenericConvolutionLayer = CLConvolutionLayer;
+ using GEMMConvolutionLayer = CLGEMMConvolutionLayer;
+ using DirectConvolutionLayer = CLDirectConvolutionLayer;
+ using WinogradConvolutionLayer = CLWinogradConvolutionLayer;
+};
- return backing_tensor;
-}
-
-/** Create a backend activation layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend activation layer function
- */
-std::unique_ptr<IFunction> create_activation_layer(ActivationLayerNode &node)
+/** Collection of CL depthwise convolution functions */
+struct CLDepthwiseConvolutionLayerFunctions
{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL ActivationLayerNode node with ID : " << node.id() << " and Name: " << node.name()
- << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
+ using GenericDepthwiseConvolutionLayer = CLDepthwiseConvolutionLayer;
+ using DepthwiseConvolutionLayer3x3 = CLDepthwiseConvolutionLayer3x3;
+};
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *output = get_backing_tensor(node.output(0));
- const ActivationLayerInfo act_info = node.activation_info();
-
- // Create function
- auto func = support::cpp14::make_unique<CLActivationLayer>();
- func->configure(input, output, act_info);
-
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLActivationLayer"
- << " Data Type: " << input->info()->data_type()
- << " Shape: " << input->info()->tensor_shape()
- << " Activation function: " << act_info.activation()
- << " a: " << act_info.a()
- << " b: " << act_info.b()
- << " InPlace : " << is_in_place_operation(input, output)
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend batch normalization layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend batch normalization layer function
- */
-std::unique_ptr<IFunction> create_batch_normalization_layer(BatchNormalizationLayerNode &node)
+/** Collection of CL element-wise functions */
+struct CLEltwiseFunctions
{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating CL BatchNormalization node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
-
- // TODO (geopin01) : Var and mean are compulsory, switch function to accept nullptr as beta and/or gamma
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 5);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *mean = get_backing_tensor(node.input(1));
- ICLTensor *var = get_backing_tensor(node.input(2));
- ICLTensor *beta = get_backing_tensor(node.input(3));
- ICLTensor *gamma = get_backing_tensor(node.input(4));
- ICLTensor *output = get_backing_tensor(node.output(0));
- const float epsilon = node.epsilon();
- const ActivationLayerInfo fused_act = node.fused_activation();
-
- // Create and configure function
- auto func = support::cpp14::make_unique<CLBatchNormalizationLayer>();
- func->configure(input, output, mean, var, beta, gamma, epsilon, fused_act);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLBatchNormalizationLayer"
- << " Data Type: " << input->info()->data_type()
- << " Shape: " << input->info()->tensor_shape()
- << " Epsilon: " << epsilon << " "
- << (fused_act.enabled() ? to_string(fused_act.activation()) : "")
- << " InPlace : " << is_in_place_operation(input, output)
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend channel shuffle layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend channel shuffle layer function
- */
-std::unique_ptr<IFunction> create_channel_shuffle_layer(ChannelShuffleLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL Channel Shuffle node with ID : " << node.id() << " and Name: " << node.name()
- << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *output = get_backing_tensor(node.output(0));
- const unsigned int num_groups = node.num_groups();
-
- // Create function
- auto func = support::cpp14::make_unique<CLChannelShuffleLayer>();
- func->configure(input, output, num_groups);
-
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLChannelShuffleLayer"
- << " Data Type: " << input->info()->data_type()
- << " Shape: " << input->info()->tensor_shape()
- << " Num groups: " << num_groups
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend convolution layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend convolution layer function
- */
-std::unique_ptr<IFunction> create_convolution_layer(ConvolutionLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating CL ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *weights = get_backing_tensor(node.input(1));
- ICLTensor *biases = get_backing_tensor(node.input(2));
- ICLTensor *output = get_backing_tensor(node.output(0));
-
- if(is_data_type_quantized_asymmetric(input->info()->data_type()))
- {
- biases->info()->set_data_type(DataType::S32);
- }
-
- const PadStrideInfo conv_info = node.convolution_info();
- const ConvolutionMethod conv_algorithm = node.convolution_method();
- const bool fast_math = node.fast_math_hint() == FastMathHint::ENABLED;
-
- // Create and configure function (we assume that functions have been validated before creation)
- std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, Target::CL);
- std::unique_ptr<IFunction> func;
- std::string func_name;
-
- if(conv_algorithm == ConvolutionMethod::WINOGRAD)
- {
- std::tie(func, func_name) = create_named_memory_managed_function<CLWinogradConvolutionLayer>(
- std::string("CLWinogradConvolutionLayer"), mm, input, weights, biases, output, conv_info, ActivationLayerInfo(), fast_math);
- }
- else if(conv_algorithm == ConvolutionMethod::DIRECT)
- {
- std::tie(func, func_name) = create_named_function<CLDirectConvolutionLayer>(
- std::string("CLDirectConvolutionLayer"), input, weights, biases, output, conv_info);
- }
- else if(conv_algorithm == ConvolutionMethod::GEMM)
- {
- std::tie(func, func_name) = create_named_memory_managed_function<CLGEMMConvolutionLayer>(std::string("CLGEMMConvolutionLayer"), mm,
- input, weights, biases, output, conv_info);
- }
- else
- {
- std::tie(func, func_name) = create_named_memory_managed_function<CLConvolutionLayer>(std::string("CLConvolutionLayer"), mm,
- input, weights, biases, output, conv_info, WeightsInfo(), Size2D(1U, 1U), ActivationLayerInfo(), fast_math);
- }
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
- << " Data Type: " << input->info()->data_type()
- << " Input QuantInfo: " << input->info()->quantization_info()
- << " Weights QuantInfo: " << weights->info()->quantization_info()
- << " Input shape: " << input->info()->tensor_shape()
- << " Weights shape: " << weights->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
- return func;
-}
-
-/** Create a backend deconvolution layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend deconvolution layer function
- */
-std::unique_ptr<IFunction> create_deconvolution_layer(DeconvolutionLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating CL DeconvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *weights = get_backing_tensor(node.input(1));
- ICLTensor *biases = get_backing_tensor(node.input(2));
- ICLTensor *output = get_backing_tensor(node.output(0));
-
- const PadStrideInfo deconv_info = node.deconvolution_info();
- const Size2D inner_border = node.inner_border();
-
- // Create and configure function (we assume that functions have been validated before creation)
- std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, Target::CL);
- std::unique_ptr<IFunction> func;
- std::string func_name;
-
- std::tie(func, func_name) = create_named_memory_managed_function<CLDeconvolutionLayer>(std::string("CLDeconvolutionLayer"), mm,
- input, weights, biases, output,
- deconv_info, inner_border.x(), inner_border.y());
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Weights shape: " << weights->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
- return func;
-}
-
-/** Create a backend layer depth concatenate function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend depth concatenate layer function
- */
-std::unique_ptr<arm_compute::IFunction> create_depth_concatenate_layer(DepthConcatenateLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating CL DepthConcatenate node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Return nullptr if depth concatenate is switched off
- if(!node.is_enabled())
- {
- return nullptr;
- }
-
- // Extract IO and info
- std::vector<arm_compute::ICLTensor *> inputs;
- for(unsigned int i = 0; i < node.num_inputs(); ++i)
- {
- inputs.push_back(get_backing_tensor(node.input(i)));
- }
- ICLTensor *output = get_backing_tensor(node.output(0));
-
- // Create and configure function
- auto func = support::cpp14::make_unique<CLDepthConcatenateLayer>();
- func->configure(inputs, output);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLDepthConcatenateLayer"
- << " Data Type: " << output->info()->data_type()
- << " Shape: " << output->info()->tensor_shape()
- << " Num Inputs: " << inputs.size()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend layer depth-wise convolution function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend depth-wise convolution layer function
- */
-std::unique_ptr<IFunction> create_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL DepthwiseConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name()
- << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *weights = get_backing_tensor(node.input(1));
- ICLTensor *biases = get_backing_tensor(node.input(2));
- ICLTensor *output = get_backing_tensor(node.output(0));
-
- if(is_data_type_quantized_asymmetric(input->info()->data_type()))
- {
- biases->info()->set_data_type(DataType::S32);
- }
-
- const PadStrideInfo conv_info = node.convolution_info();
- const DepthwiseConvolutionMethod dwc_algorithm = node.depthwise_convolution_method();
-
- // Create and configure function (we assume that functions have been validated before creation)
- std::unique_ptr<IFunction> func;
- std::string func_name;
- if(dwc_algorithm == DepthwiseConvolutionMethod::OPTIMIZED_3x3)
- {
- std::tie(func, func_name) = create_named_function<CLDepthwiseConvolutionLayer3x3>(
- std::string("CLDepthwiseConvolutionLayer3x3"), input, weights, biases, output, conv_info);
- }
- else
- {
- std::tie(func, func_name) = create_named_function<CLDepthwiseConvolutionLayer>(
- std::string("CLDepthwiseConvolutionLayer"), input, weights, biases, output, conv_info);
- }
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
- << " Data Type: " << input->info()->data_type()
- << " Input QuantInfo: " << input->info()->quantization_info()
- << " Weights QuantInfo: " << weights->info()->quantization_info()
- << " Input shape: " << input->info()->tensor_shape()
- << " Weights shape: " << weights->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
- return func;
-}
-
-/** Create a backend element-wise operation layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend element-wise operation layer function
- */
-std::unique_ptr<IFunction> create_eltwise_layer(EltwiseLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 2);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input1 = get_backing_tensor(node.input(0));
- ICLTensor *input2 = get_backing_tensor(node.input(1));
- ICLTensor *output = get_backing_tensor(node.output(0));
- const EltwiseOperation eltwise_op = node.eltwise_operation();
- const ConvertPolicy convert_policy = node.convert_policy();
- ARM_COMPUTE_ERROR_ON(input1 == nullptr);
- ARM_COMPUTE_ERROR_ON(input2 == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- std::unique_ptr<IFunction> func = nullptr;
- std::string func_name;
- if(eltwise_op == EltwiseOperation::ADD)
- {
- std::tie(func, func_name) = create_named_function<CLArithmeticAddition>(std::string("CLArithmeticAddition"),
- input1, input2, output,
- convert_policy);
- }
- else if(eltwise_op == EltwiseOperation::SUB)
- {
- std::tie(func, func_name) = create_named_function<CLArithmeticSubtraction>(
- std::string("CLArithmeticSubtraction"), input1, input2, output, convert_policy);
- }
- else if(eltwise_op == EltwiseOperation::MUL)
- {
- std::tie(func, func_name) = create_named_function<CLPixelWiseMultiplication>(
- std::string("CLPixelWiseMultiplication"), input1, input2, output, 1.f, convert_policy,
- node.rounding_policy());
- }
- else
- {
- ARM_COMPUTE_ERROR("Unsupported element-wise operation!");
- }
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
- << " Data Type: " << input1->info()->data_type()
- << " Shape : " << input1->info()->tensor_shape()
- << std::endl);
-
- return func;
-}
-
-/** Create a backend flatten layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend flatten layer function
- */
-std::unique_ptr<IFunction> create_flatten_layer(FlattenLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL FlattenLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *output = get_backing_tensor(node.output(0));
-
- // Create and configure function
- auto func = support::cpp14::make_unique<CLFlattenLayer>();
- func->configure(input, output);
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLFlattenLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend fully connected layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend fully connected layer function
- */
-std::unique_ptr<IFunction> create_fully_connected_layer(FullyConnectedLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL FullyConnectedLayer node with ID : " << node.id() << " and Name: " << node.name()
- << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *weights = get_backing_tensor(node.input(1));
- ICLTensor *biases = get_backing_tensor(node.input(2));
- ICLTensor *output = get_backing_tensor(node.output(0));
-
- // Create and configure function
- auto func = support::cpp14::make_unique<CLFullyConnectedLayer>(get_memory_manager(ctx, Target::CL));
- func->configure(input, weights, biases, output);
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(weights == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLFullyConnectedLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Weights shape: " << weights->info()->tensor_shape()
- << " Biases Shape: " << biases->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend normalization layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend normalization layer function
- */
-std::unique_ptr<IFunction> create_normalization_layer(NormalizationLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL NormalizationLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *output = get_backing_tensor(node.output(0));
- const NormalizationLayerInfo norm_info = node.normalization_info();
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Create and configure function
- auto func = support::cpp14::make_unique<CLNormalizationLayer>();
- func->configure(input, output, norm_info);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLNormalizationLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << " Normalization info: " << norm_info.type()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend pooling layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend pooling layer function
- */
-std::unique_ptr<IFunction> create_pooling_layer(PoolingLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL PoolingLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *output = get_backing_tensor(node.output(0));
- const PoolingLayerInfo pool_info = node.pooling_info();
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Create and configure function
- auto func = support::cpp14::make_unique<CLPoolingLayer>();
- func->configure(input, output, pool_info);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLPoolingLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << " Pooling info: " << pool_info.pool_type()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend reshape layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend reshape layer function
- */
-std::unique_ptr<IFunction> create_reshape_layer(ReshapeLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL ReshapeLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *output = get_backing_tensor(node.output(0));
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Create and configure function
- auto func = support::cpp14::make_unique<CLReshapeLayer>();
- func->configure(input, output);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLReshapeLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend resize layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend resize layer function
- */
-std::unique_ptr<IFunction> create_resize_layer(ResizeLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL Resize node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *output = get_backing_tensor(node.output(0));
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
- const InterpolationPolicy policy = node.policy();
-
- // Create and configure function
- auto func = support::cpp14::make_unique<CLScale>();
- func->configure(input, output, policy, BorderMode::CONSTANT);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLScale"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << " Interpolation: " << policy
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend softmax layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend softmax layer function
- */
-std::unique_ptr<IFunction> create_softmax_layer(SoftmaxLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating CL SoftmaxLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ICLTensor *input = get_backing_tensor(node.input(0));
- ICLTensor *output = get_backing_tensor(node.output(0));
- const float beta = node.beta();
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Create and configure function
- auto func = support::cpp14::make_unique<CLSoftmaxLayer>(get_memory_manager(ctx, Target::CL));
- func->configure(input, output, beta);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated CLSoftmaxLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
-
- return std::move(func);
-}
-} // namespace
+ using Addition = CLArithmeticAddition;
+ using Subtraction = CLArithmeticSubtraction;
+ using Multiplication = CLPixelWiseMultiplication;
+};
std::unique_ptr<IFunction> CLFunctionFactory::create(INode *node, GraphContext &ctx)
{
@@ -683,35 +80,35 @@
switch(type)
{
case NodeType::ActivationLayer:
- return create_activation_layer(*polymorphic_downcast<ActivationLayerNode *>(node));
+ return detail::create_activation_layer<CLActivationLayer, CLTargetInfo>(*polymorphic_downcast<ActivationLayerNode *>(node));
case NodeType::BatchNormalizationLayer:
- return create_batch_normalization_layer(*polymorphic_downcast<BatchNormalizationLayerNode *>(node));
+ return detail::create_batch_normalization_layer<CLBatchNormalizationLayer, CLTargetInfo>(*polymorphic_downcast<BatchNormalizationLayerNode *>(node));
case NodeType::ChannelShuffleLayer:
- return create_channel_shuffle_layer(*polymorphic_downcast<ChannelShuffleLayerNode *>(node));
+ return detail::create_channel_shuffle_layer<CLChannelShuffleLayer, CLTargetInfo>(*polymorphic_downcast<ChannelShuffleLayerNode *>(node));
case NodeType::ConvolutionLayer:
- return create_convolution_layer(*polymorphic_downcast<ConvolutionLayerNode *>(node), ctx);
+ return detail::create_convolution_layer<CLConvolutionLayerFunctions, CLTargetInfo>(*polymorphic_downcast<ConvolutionLayerNode *>(node), ctx);
case NodeType::DeconvolutionLayer:
- return create_deconvolution_layer(*polymorphic_downcast<DeconvolutionLayerNode *>(node), ctx);
+ return detail::create_deconvolution_layer<CLDeconvolutionLayer, CLTargetInfo>(*polymorphic_downcast<DeconvolutionLayerNode *>(node), ctx);
case NodeType::DepthConcatenateLayer:
- return create_depth_concatenate_layer(*polymorphic_downcast<DepthConcatenateLayerNode *>(node));
+ return detail::create_depth_concatenate_layer<CLDepthConcatenateLayer, CLTargetInfo>(*polymorphic_downcast<DepthConcatenateLayerNode *>(node));
case NodeType::DepthwiseConvolutionLayer:
- return create_depthwise_convolution_layer(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
+ return detail::create_depthwise_convolution_layer<CLDepthwiseConvolutionLayerFunctions, CLTargetInfo>(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
case NodeType::EltwiseLayer:
- return create_eltwise_layer(*polymorphic_downcast<EltwiseLayerNode *>(node));
+ return detail::create_eltwise_layer<CLEltwiseFunctions, CLTargetInfo>(*polymorphic_downcast<EltwiseLayerNode *>(node));
case NodeType::FlattenLayer:
- return create_flatten_layer(*polymorphic_downcast<FlattenLayerNode *>(node));
+ return detail::create_flatten_layer<CLFlattenLayer, CLTargetInfo>(*polymorphic_downcast<FlattenLayerNode *>(node));
case NodeType::FullyConnectedLayer:
- return create_fully_connected_layer(*polymorphic_downcast<FullyConnectedLayerNode *>(node), ctx);
+ return detail::create_fully_connected_layer<CLFullyConnectedLayer, CLTargetInfo>(*polymorphic_downcast<FullyConnectedLayerNode *>(node), ctx);
case NodeType::NormalizationLayer:
- return create_normalization_layer(*polymorphic_downcast<NormalizationLayerNode *>(node));
+ return detail::create_normalization_layer<CLNormalizationLayer, CLTargetInfo>(*polymorphic_downcast<NormalizationLayerNode *>(node), ctx);
case NodeType::PoolingLayer:
- return create_pooling_layer(*polymorphic_downcast<PoolingLayerNode *>(node));
+ return detail::create_pooling_layer<CLPoolingLayer, CLTargetInfo>(*polymorphic_downcast<PoolingLayerNode *>(node));
case NodeType::ReshapeLayer:
- return create_reshape_layer(*polymorphic_downcast<ReshapeLayerNode *>(node));
+ return detail::create_reshape_layer<CLReshapeLayer, CLTargetInfo>(*polymorphic_downcast<ReshapeLayerNode *>(node));
case NodeType::ResizeLayer:
- return create_resize_layer(*polymorphic_downcast<ResizeLayerNode *>(node));
+ return detail::create_resize_layer<CLScale, CLTargetInfo>(*polymorphic_downcast<ResizeLayerNode *>(node));
case NodeType::SoftmaxLayer:
- return create_softmax_layer(*polymorphic_downcast<SoftmaxLayerNode *>(node), ctx);
+ return detail::create_softmax_layer<CLSoftmaxLayer, CLTargetInfo>(*polymorphic_downcast<SoftmaxLayerNode *>(node), ctx);
default:
return nullptr;
}
diff --git a/src/graph/backends/GLES/GCFunctionsFactory.cpp b/src/graph/backends/GLES/GCFunctionsFactory.cpp
index d53daf1..e6bd5a5 100644
--- a/src/graph/backends/GLES/GCFunctionsFactory.cpp
+++ b/src/graph/backends/GLES/GCFunctionsFactory.cpp
@@ -25,16 +25,9 @@
#include "arm_compute/core/utils/misc/Cast.h"
#include "arm_compute/graph/Graph.h"
-#include "arm_compute/graph/GraphContext.h"
-#include "arm_compute/graph/Logger.h"
-#include "arm_compute/graph/TypePrinter.h"
-#include "arm_compute/graph/Types.h"
-#include "arm_compute/graph/backends/Utils.h"
-#include "arm_compute/graph/nodes/Nodes.h"
+#include "arm_compute/graph/backends/FunctionHelpers.h"
#include "arm_compute/runtime/GLES_COMPUTE/GCFunctions.h"
-#include "support/ToolchainSupport.h"
-
using namespace arm_compute::utils::cast;
namespace arm_compute
@@ -43,121 +36,48 @@
{
namespace backends
{
-namespace
+/** Target specific information structure used to pass information to the layer templates */
+struct GCTargetInfo
{
-/** Returns backing tensor of a given tensor
- *
- * @param[in] tensor Tensor to extract the backing tensor from
- *
- * @return Backing tensor if present else nullptr
- */
-arm_compute::IGCTensor *get_backing_tensor(arm_compute::graph::Tensor *tensor)
-{
- arm_compute::IGCTensor *backing_tensor = nullptr;
- if(tensor != nullptr)
- {
- ARM_COMPUTE_ERROR_ON(tensor->desc().target != arm_compute::graph::Target::GC);
- // Get backing tensor handle
- ITensorHandle *tensor_handle = tensor->handle();
- // Get backing tensor
- backing_tensor = (tensor_handle != nullptr) ? polymorphic_cast<IGCTensor *>(&tensor_handle->tensor()) : nullptr;
- }
+ using TensorType = arm_compute::IGCTensor;
+ static Target TargetType;
+};
- return backing_tensor;
-}
+Target GCTargetInfo::TargetType = Target::GC;
-/** Create a backend activation layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend activation layer function
- */
-std::unique_ptr<IFunction> create_activation_layer(ActivationLayerNode &node)
+/** Collection of GC convolution functions */
+struct GCConvolutionLayerFunctions
{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating GC ActivationLayerNode node with ID : " << node.id() << " and Name: " << node.name()
- << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
+ using GenericConvolutionLayer = GCConvolutionLayer;
+ using GEMMConvolutionLayer = GCConvolutionLayer;
+ using DirectConvolutionLayer = GCDirectConvolutionLayer;
+};
+
+/** Collection of GC depthwise convolution functions */
+struct GCDepthwiseConvolutionLayerFunctions
+{
+ using DepthwiseConvolutionLayer3x3 = GCDepthwiseConvolutionLayer3x3;
+};
+
+/** Collection of GC element-wise functions */
+struct GCEltwiseFunctions
+{
+ using Addition = GCArithmeticAddition;
+ using Multiplication = GCPixelWiseMultiplication;
+};
+
+namespace detail
+{
+template <>
+std::unique_ptr<IFunction> create_convolution_layer<GCConvolutionLayerFunctions, GCTargetInfo>(ConvolutionLayerNode &node, GraphContext &ctx)
+{
+ validate_node<GCTargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */);
// Extract IO and info
- IGCTensor *input = get_backing_tensor(node.input(0));
- IGCTensor *output = get_backing_tensor(node.output(0));
- const ActivationLayerInfo act_info = node.activation_info();
-
- // Create function
- auto func = support::cpp14::make_unique<GCActivationLayer>();
- func->configure(input, output, act_info);
-
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated GCActivationLayer"
- << " Data Type: " << input->info()->data_type()
- << " Shape: " << input->info()->tensor_shape()
- << " Activation function: " << act_info.activation()
- << " a: " << act_info.a()
- << " b: " << act_info.b()
- << " InPlace : " << is_in_place_operation(input, output)
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend batch normalization layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend batch normalization layer function
- */
-std::unique_ptr<IFunction> create_batch_normalization_layer(BatchNormalizationLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating GC BatchNormalization node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
-
- // TODO (geopin01) : Var and mean are compulsory, switch function to accept nullptr as beta and/or gamma
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 5);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- IGCTensor *input = get_backing_tensor(node.input(0));
- IGCTensor *mean = get_backing_tensor(node.input(1));
- IGCTensor *var = get_backing_tensor(node.input(2));
- IGCTensor *beta = get_backing_tensor(node.input(3));
- IGCTensor *gamma = get_backing_tensor(node.input(4));
- IGCTensor *output = get_backing_tensor(node.output(0));
- const float epsilon = node.epsilon();
- const ActivationLayerInfo fused_act = node.fused_activation();
-
- // Create and configure function
- auto func = support::cpp14::make_unique<GCBatchNormalizationLayer>();
- func->configure(input, output, mean, var, beta, gamma, epsilon, fused_act);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated GCBatchNormalizationLayer"
- << " Data Type: " << input->info()->data_type()
- << " Shape: " << input->info()->tensor_shape()
- << " Epsilon: " << epsilon << " "
- << (fused_act.enabled() ? to_string(fused_act.activation()) : "")
- << " InPlace : " << is_in_place_operation(input, output)
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend convolution layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend convolution layer function
- */
-std::unique_ptr<IFunction> create_convolution_layer(ConvolutionLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating GC ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- IGCTensor *input = get_backing_tensor(node.input(0));
- IGCTensor *weights = get_backing_tensor(node.input(1));
- IGCTensor *biases = get_backing_tensor(node.input(2));
- IGCTensor *output = get_backing_tensor(node.output(0));
+ GCTargetInfo::TensorType *input = get_backing_tensor<GCTargetInfo>(node.input(0));
+ GCTargetInfo::TensorType *weights = get_backing_tensor<GCTargetInfo>(node.input(1));
+ GCTargetInfo::TensorType *biases = get_backing_tensor<GCTargetInfo>(node.input(2));
+ GCTargetInfo::TensorType *output = get_backing_tensor<GCTargetInfo>(node.output(0));
if(is_data_type_quantized_asymmetric(input->info()->data_type()))
{
@@ -168,19 +88,21 @@
const ConvolutionMethod conv_algorithm = node.convolution_method();
// Create and configure function (we assume that functions have been validated before creation)
- std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, Target::GC);
+ std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, GCTargetInfo::TargetType);
std::unique_ptr<IFunction> func;
std::string func_name;
if(conv_algorithm == ConvolutionMethod::DIRECT)
{
- std::tie(func, func_name) = create_named_function<GCDirectConvolutionLayer>(
- std::string("GCDirectConvolutionLayer"), input, weights, biases, output, conv_info);
+ std::tie(func, func_name) = create_named_function<GCConvolutionLayerFunctions::DirectConvolutionLayer>(
+ std::string("DirectConvolutionLayer"),
+ input, weights, biases, output, conv_info);
}
else
{
- std::tie(func, func_name) = create_named_memory_managed_function<GCConvolutionLayer>(std::string("GCConvolutionLayer"), mm,
- input, weights, biases, output, conv_info);
+ std::tie(func, func_name) = create_named_memory_managed_function<GCConvolutionLayerFunctions::GenericConvolutionLayer>(
+ std::string("ConvolutionLayer"), mm,
+ input, weights, biases, output, conv_info);
}
// Log info
@@ -195,64 +117,16 @@
return func;
}
-/** Create a backend layer depth concatenate function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend depth concatenate layer function
- */
-std::unique_ptr<arm_compute::IFunction> create_depth_concatenate_layer(DepthConcatenateLayerNode &node)
+template <>
+std::unique_ptr<IFunction> create_depthwise_convolution_layer<GCDepthwiseConvolutionLayerFunctions, GCTargetInfo>(DepthwiseConvolutionLayerNode &node)
{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating GC DepthConcatenate node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Return nullptr if depth concatenate is switched off
- if(!node.is_enabled())
- {
- return nullptr;
- }
+ validate_node<GCTargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */);
// Extract IO and info
- std::vector<arm_compute::IGCTensor *> inputs;
- for(unsigned int i = 0; i < node.num_inputs(); ++i)
- {
- inputs.push_back(get_backing_tensor(node.input(i)));
- }
- IGCTensor *output = get_backing_tensor(node.output(0));
-
- // Create and configure function
- auto func = support::cpp14::make_unique<GCDepthConcatenateLayer>();
- func->configure(inputs, output);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated GCDepthConcatenateLayer"
- << " Data Type: " << output->info()->data_type()
- << " Shape: " << output->info()->tensor_shape()
- << " Num Inputs: " << inputs.size()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend layer depth-wise convolution function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend depth-wise convolution layer function
- */
-std::unique_ptr<IFunction> create_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating GC DepthwiseConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name()
- << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- IGCTensor *input = get_backing_tensor(node.input(0));
- IGCTensor *weights = get_backing_tensor(node.input(1));
- IGCTensor *biases = get_backing_tensor(node.input(2));
- IGCTensor *output = get_backing_tensor(node.output(0));
+ GCTargetInfo::TensorType *input = get_backing_tensor<GCTargetInfo>(node.input(0));
+ GCTargetInfo::TensorType *weights = get_backing_tensor<GCTargetInfo>(node.input(1));
+ GCTargetInfo::TensorType *biases = get_backing_tensor<GCTargetInfo>(node.input(2));
+ GCTargetInfo::TensorType *output = get_backing_tensor<GCTargetInfo>(node.output(0));
if(is_data_type_quantized_asymmetric(input->info()->data_type()))
{
@@ -267,8 +141,9 @@
std::string func_name;
if(dwc_algorithm == DepthwiseConvolutionMethod::OPTIMIZED_3x3)
{
- std::tie(func, func_name) = create_named_function<GCDepthwiseConvolutionLayer3x3>(
- std::string("GCDepthwiseConvolutionLayer3x3"), input, weights, biases, output, conv_info);
+ std::tie(func, func_name) = create_named_function<GCDepthwiseConvolutionLayerFunctions::DepthwiseConvolutionLayer3x3>(
+ std::string("DepthwiseConvolutionLayer3x3"),
+ input, weights, biases, output, conv_info);
}
else
{
@@ -277,6 +152,7 @@
// Log info
ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
+ << " Target " << GCTargetInfo::TargetType
<< " Data Type: " << input->info()->data_type()
<< " Input QuantInfo: " << input->info()->quantization_info()
<< " Weights QuantInfo: " << weights->info()->quantization_info()
@@ -287,13 +163,8 @@
return func;
}
-/** Create a backend element-wise operation layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend element-wise operation layer function
- */
-std::unique_ptr<IFunction> create_eltwise_layer(EltwiseLayerNode &node)
+template <>
+std::unique_ptr<IFunction> create_eltwise_layer<GCEltwiseFunctions, GCTargetInfo>(EltwiseLayerNode &node)
{
ARM_COMPUTE_LOG_GRAPH_VERBOSE(
"Creating GC EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
@@ -301,11 +172,11 @@
ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
// Extract IO and info
- IGCTensor *input1 = get_backing_tensor(node.input(0));
- IGCTensor *input2 = get_backing_tensor(node.input(1));
- IGCTensor *output = get_backing_tensor(node.output(0));
- const EltwiseOperation eltwise_op = node.eltwise_operation();
- const ConvertPolicy convert_policy = node.convert_policy();
+ GCTargetInfo::TensorType *input1 = get_backing_tensor<GCTargetInfo>(node.input(0));
+ GCTargetInfo::TensorType *input2 = get_backing_tensor<GCTargetInfo>(node.input(1));
+ GCTargetInfo::TensorType *output = get_backing_tensor<GCTargetInfo>(node.output(0));
+ const EltwiseOperation eltwise_op = node.eltwise_operation();
+ const ConvertPolicy convert_policy = node.convert_policy();
ARM_COMPUTE_ERROR_ON(input1 == nullptr);
ARM_COMPUTE_ERROR_ON(input2 == nullptr);
ARM_COMPUTE_ERROR_ON(output == nullptr);
@@ -314,9 +185,9 @@
std::string func_name;
if(eltwise_op == EltwiseOperation::ADD)
{
- std::tie(func, func_name) = create_named_function<GCArithmeticAddition>(std::string("GCArithmeticAddition"),
- input1, input2, output,
- convert_policy);
+ std::tie(func, func_name) = create_named_function<GCEltwiseFunctions::Addition>(
+ std::string("GCArithmeticAddition"),
+ input1, input2, output, convert_policy);
}
else if(eltwise_op == EltwiseOperation::SUB)
{
@@ -324,8 +195,9 @@
}
else if(eltwise_op == EltwiseOperation::MUL)
{
- std::tie(func, func_name) = create_named_function<GCPixelWiseMultiplication>(
- std::string("GCPixelWiseMultiplication"), input1, input2, output, 1.f);
+ std::tie(func, func_name) = create_named_function<GCEltwiseFunctions::Multiplication>(
+ std::string("PixelWiseMultiplication"),
+ input1, input2, output, 1.f);
}
else
{
@@ -333,157 +205,16 @@
}
// Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << GCTargetInfo::TargetType
+ << " Operation " << func_name
<< " Data Type: " << input1->info()->data_type()
<< " Shape : " << input1->info()->tensor_shape()
<< std::endl);
return func;
}
-
-/** Create a backend fully connected layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend fully connected layer function
- */
-std::unique_ptr<IFunction> create_fully_connected_layer(FullyConnectedLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating GC FullyConnectedLayer node with ID : " << node.id() << " and Name: " << node.name()
- << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- IGCTensor *input = get_backing_tensor(node.input(0));
- IGCTensor *weights = get_backing_tensor(node.input(1));
- IGCTensor *biases = get_backing_tensor(node.input(2));
- IGCTensor *output = get_backing_tensor(node.output(0));
-
- // Create and configure function
- auto func = support::cpp14::make_unique<GCFullyConnectedLayer>(get_memory_manager(ctx, Target::GC));
- func->configure(input, weights, biases, output);
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(weights == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated GCFullyConnectedLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Weights shape: " << weights->info()->tensor_shape()
- << " Biases Shape: " << biases->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend normalization layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend normalization layer function
- */
-std::unique_ptr<IFunction> create_normalization_layer(NormalizationLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating GC NormalizationLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- IGCTensor *input = get_backing_tensor(node.input(0));
- IGCTensor *output = get_backing_tensor(node.output(0));
- const NormalizationLayerInfo norm_info = node.normalization_info();
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Create and configure function
- auto func = support::cpp14::make_unique<GCNormalizationLayer>();
- func->configure(input, output, norm_info);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated GCNormalizationLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << " Normalization info: " << norm_info.type()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend pooling layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend pooling layer function
- */
-std::unique_ptr<IFunction> create_pooling_layer(PoolingLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating GC PoolingLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- IGCTensor *input = get_backing_tensor(node.input(0));
- IGCTensor *output = get_backing_tensor(node.output(0));
- const PoolingLayerInfo pool_info = node.pooling_info();
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Create and configure function
- auto func = support::cpp14::make_unique<GCPoolingLayer>();
- func->configure(input, output, pool_info);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated GCPoolingLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << " Pooling info: " << pool_info.pool_type()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend softmax layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend softmax layer function
- */
-std::unique_ptr<IFunction> create_softmax_layer(SoftmaxLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating GC SoftmaxLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- IGCTensor *input = get_backing_tensor(node.input(0));
- IGCTensor *output = get_backing_tensor(node.output(0));
- const float beta = node.beta();
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Create and configure function
- auto func = support::cpp14::make_unique<GCSoftmaxLayer>(get_memory_manager(ctx, Target::CL));
- func->configure(input, output, beta);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated GCSoftmaxLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
-
- return std::move(func);
-}
-} // namespace
+} //namespace detail
std::unique_ptr<IFunction> GCFunctionFactory::create(INode *node, GraphContext &ctx)
{
@@ -496,25 +227,27 @@
switch(type)
{
case NodeType::ActivationLayer:
- return create_activation_layer(*polymorphic_downcast<ActivationLayerNode *>(node));
+ return detail::create_activation_layer<GCActivationLayer, GCTargetInfo>(*polymorphic_downcast<ActivationLayerNode *>(node));
case NodeType::BatchNormalizationLayer:
- return create_batch_normalization_layer(*polymorphic_downcast<BatchNormalizationLayerNode *>(node));
+ return detail::create_batch_normalization_layer<GCBatchNormalizationLayer, GCTargetInfo>(*polymorphic_downcast<BatchNormalizationLayerNode *>(node));
case NodeType::ConvolutionLayer:
- return create_convolution_layer(*polymorphic_downcast<ConvolutionLayerNode *>(node), ctx);
+ return detail::create_convolution_layer<GCConvolutionLayerFunctions, GCTargetInfo>(*polymorphic_downcast<ConvolutionLayerNode *>(node), ctx);
case NodeType::DepthConcatenateLayer:
- return create_depth_concatenate_layer(*polymorphic_downcast<DepthConcatenateLayerNode *>(node));
+ return detail::create_depth_concatenate_layer<GCDepthConcatenateLayer, GCTargetInfo>(*polymorphic_downcast<DepthConcatenateLayerNode *>(node));
case NodeType::DepthwiseConvolutionLayer:
- return create_depthwise_convolution_layer(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
+ return detail::create_depthwise_convolution_layer<GCDepthwiseConvolutionLayerFunctions, GCTargetInfo>(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
case NodeType::EltwiseLayer:
- return create_eltwise_layer(*polymorphic_downcast<EltwiseLayerNode *>(node));
+ return detail::create_eltwise_layer<GCEltwiseFunctions, GCTargetInfo>(*polymorphic_downcast<EltwiseLayerNode *>(node));
case NodeType::FullyConnectedLayer:
- return create_fully_connected_layer(*polymorphic_downcast<FullyConnectedLayerNode *>(node), ctx);
+ return detail::create_fully_connected_layer<GCFullyConnectedLayer, GCTargetInfo>(*polymorphic_downcast<FullyConnectedLayerNode *>(node), ctx);
case NodeType::NormalizationLayer:
- return create_normalization_layer(*polymorphic_downcast<NormalizationLayerNode *>(node));
+ return detail::create_normalization_layer<GCNormalizationLayer, GCTargetInfo>(*polymorphic_downcast<NormalizationLayerNode *>(node), ctx);
case NodeType::PoolingLayer:
- return create_pooling_layer(*polymorphic_downcast<PoolingLayerNode *>(node));
+ return detail::create_pooling_layer<GCPoolingLayer, GCTargetInfo>(*polymorphic_downcast<PoolingLayerNode *>(node));
+ case NodeType::ResizeLayer:
+ return detail::create_resize_layer<GCScale, GCTargetInfo>(*polymorphic_downcast<ResizeLayerNode *>(node));
case NodeType::SoftmaxLayer:
- return create_softmax_layer(*polymorphic_downcast<SoftmaxLayerNode *>(node), ctx);
+ return detail::create_softmax_layer<GCSoftmaxLayer, GCTargetInfo>(*polymorphic_downcast<SoftmaxLayerNode *>(node), ctx);
default:
return nullptr;
}
diff --git a/src/graph/backends/NEON/NEFunctionFactory.cpp b/src/graph/backends/NEON/NEFunctionFactory.cpp
index 8376feb..3b7417d 100644
--- a/src/graph/backends/NEON/NEFunctionFactory.cpp
+++ b/src/graph/backends/NEON/NEFunctionFactory.cpp
@@ -28,6 +28,7 @@
#include "arm_compute/graph/GraphContext.h"
#include "arm_compute/graph/Logger.h"
#include "arm_compute/graph/TypePrinter.h"
+#include "arm_compute/graph/backends/FunctionHelpers.h"
#include "arm_compute/graph/backends/Utils.h"
#include "arm_compute/graph/nodes/Nodes.h"
#include "arm_compute/runtime/NEON/NEFunctions.h"
@@ -41,109 +42,53 @@
{
namespace backends
{
-namespace
+/** Target specific information structure used to pass information to the layer templates */
+struct NETargetInfo
{
-/** Returns backing tensor of a given tensor
- *
- * @param[in] tensor Tensor to extract the backing tensor from
- *
- * @return Backing tensor if present else nullptr
- */
-arm_compute::ITensor *get_backing_tensor(arm_compute::graph::Tensor *tensor)
-{
- return ((tensor == nullptr) || (tensor->handle() == nullptr)) ? nullptr : &tensor->handle()->tensor();
-}
+ using TensorType = arm_compute::ITensor;
+ static Target TargetType;
+};
-/** Create a backend activation layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend activation layer function
- */
-std::unique_ptr<IFunction> create_activation_layer(ActivationLayerNode &node)
+Target NETargetInfo::TargetType = Target::NEON;
+
+/** Collection of CL convolution functions */
+struct NEConvolutionLayerFunctions
{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON ActivationLayerNode node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
+ using GenericConvolutionLayer = NEConvolutionLayer;
+ using GEMMConvolutionLayer = NEGEMMConvolutionLayer;
+ using DirectConvolutionLayer = NEDirectConvolutionLayer;
+ using WinogradConvolutionLayer = NEWinogradConvolutionLayer;
+};
+
+/** Collection of CL depthwise convolution functions */
+struct NEDepthwiseConvolutionLayerFunctions
+{
+ using GenericDepthwiseConvolutionLayer = NEDepthwiseConvolutionLayer;
+ using DepthwiseConvolutionLayer3x3 = NEDepthwiseConvolutionLayer3x3;
+};
+
+/** Collection of CL element-wise functions */
+struct NEEltwiseFunctions
+{
+ using Addition = NEArithmeticAddition;
+ using Subtraction = NEArithmeticSubtraction;
+ using Multiplication = NEPixelWiseMultiplication;
+};
+
+namespace detail
+{
+// Specialize functions
+template <>
+std::unique_ptr<IFunction> create_convolution_layer<NEConvolutionLayerFunctions, NETargetInfo>(ConvolutionLayerNode &node,
+ GraphContext &ctx)
+{
+ validate_node<NETargetInfo>(node, 3 /* expected inputs */, 1 /* expected outputs */);
// Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *output = get_backing_tensor(node.output(0));
- const ActivationLayerInfo act_info = node.activation_info();
-
- // Create function
- auto func = support::cpp14::make_unique<NEActivationLayer>();
- func->configure(input, output, act_info);
-
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated NEActivationLayer"
- << " Data Type: " << input->info()->data_type()
- << " Shape: " << input->info()->tensor_shape()
- << " Activation function: " << act_info.activation()
- << " a: " << act_info.a()
- << " b: " << act_info.b()
- << " InPlace : " << is_in_place_operation(input, output)
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend batch normalization layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend batch normalization layer function
- */
-std::unique_ptr<IFunction> create_batch_normalization_layer(BatchNormalizationLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON BatchNormalization node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
-
- // TODO (geopin01) : Var and mean are compulsory, switch function to accept nullptr as beta and/or gamma
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 5);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *mean = get_backing_tensor(node.input(1));
- ITensor *var = get_backing_tensor(node.input(2));
- ITensor *beta = get_backing_tensor(node.input(3));
- ITensor *gamma = get_backing_tensor(node.input(4));
- ITensor *output = get_backing_tensor(node.output(0));
- const float epsilon = node.epsilon();
- const ActivationLayerInfo fused_act = node.fused_activation();
-
- // Create and configure function
- auto func = support::cpp14::make_unique<NEBatchNormalizationLayer>();
- func->configure(input, output, mean, var, beta, gamma, epsilon, fused_act);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated NEBatchNormalizationLayer"
- << " Data Type: " << input->info()->data_type()
- << " Shape: " << input->info()->tensor_shape()
- << " Epsilon: " << epsilon << " "
- << (fused_act.enabled() ? to_string(fused_act.activation()) : "")
- << " InPlace : " << is_in_place_operation(input, output)
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend convolution layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend convolution layer function
- */
-std::unique_ptr<IFunction> create_convolution_layer(ConvolutionLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON ConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *weights = get_backing_tensor(node.input(1));
- ITensor *biases = get_backing_tensor(node.input(2));
- ITensor *output = get_backing_tensor(node.output(0));
+ NETargetInfo::TensorType *input = get_backing_tensor<NETargetInfo>(node.input(0));
+ NETargetInfo::TensorType *weights = get_backing_tensor<NETargetInfo>(node.input(1));
+ NETargetInfo::TensorType *biases = get_backing_tensor<NETargetInfo>(node.input(2));
+ NETargetInfo::TensorType *output = get_backing_tensor<NETargetInfo>(node.output(0));
if(is_data_type_quantized_asymmetric(input->info()->data_type()))
{
@@ -159,27 +104,28 @@
std::string func_name;
if(conv_algorithm == ConvolutionMethod::DIRECT)
{
- std::tie(func, func_name) = create_named_memory_managed_function<NEDirectConvolutionLayer>(std::string("NEDirectConvolutionLayer"), mm,
- input, weights, biases, output, conv_info);
+ std::tie(func, func_name) = create_named_memory_managed_function<NEDirectConvolutionLayer>(
+ std::string("DirectConvolutionLayer"), mm, input, weights, biases, output, conv_info);
}
else if(conv_algorithm == ConvolutionMethod::GEMM)
{
- std::tie(func, func_name) = create_named_memory_managed_function<NEGEMMConvolutionLayer>(std::string("NEGEMMConvolutionLayer"), mm,
- input, weights, biases, output, conv_info);
+ std::tie(func, func_name) = create_named_memory_managed_function<NEGEMMConvolutionLayer>(
+ std::string("GEMMConvolutionLayer"), mm, input, weights, biases, output, conv_info);
}
else if(conv_algorithm == ConvolutionMethod::WINOGRAD)
{
- std::tie(func, func_name) = create_named_memory_managed_function<NEWinogradConvolutionLayer>(std::string("NEWinogradConvolutionLayer"), mm,
- input, weights, biases, output, conv_info);
+ std::tie(func, func_name) = create_named_memory_managed_function<NEWinogradConvolutionLayer>(
+ std::string("WinogradConvolutionLayer"), mm, input, weights, biases, output, conv_info);
}
else
{
- std::tie(func, func_name) = create_named_memory_managed_function<NEConvolutionLayer>(std::string("NEConvolutionLayer"), mm,
- input, weights, biases, output, conv_info);
+ std::tie(func, func_name) = create_named_memory_managed_function<NEConvolutionLayer>(
+ std::string("ConvolutionLayer"), mm, input, weights, biases, output, conv_info);
}
// Log info
ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
+ << " Target " << NETargetInfo::TargetType
<< " Data Type: " << input->info()->data_type()
<< " Input QuantInfo: " << input->info()->quantization_info()
<< " Weights QuantInfo: " << weights->info()->quantization_info()
@@ -190,284 +136,25 @@
return func;
}
-/** Create a backend deconvolution layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend deconvolution layer function
- */
-std::unique_ptr<IFunction> create_deconvolution_layer(DeconvolutionLayerNode &node, GraphContext &ctx)
+template <>
+std::unique_ptr<IFunction> create_normalization_layer<NENormalizationLayer, NETargetInfo>(NormalizationLayerNode &node, GraphContext &ctx)
{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON DeconvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
+ validate_node<NETargetInfo>(node, 1 /* expected inputs */, 1 /* expected outputs */);
// Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *weights = get_backing_tensor(node.input(1));
- ITensor *biases = get_backing_tensor(node.input(2));
- ITensor *output = get_backing_tensor(node.output(0));
-
- const PadStrideInfo deconv_info = node.deconvolution_info();
- const Size2D inner_border = node.inner_border();
-
- // Create and configure function (we assume that functions have been validated before creation)
- std::shared_ptr<IMemoryManager> mm = get_memory_manager(ctx, Target::CL);
- std::unique_ptr<IFunction> func;
- std::string func_name;
-
- std::tie(func, func_name) = create_named_memory_managed_function<NEDeconvolutionLayer>(std::string("NEDeconvolutionLayer"), mm,
- input, weights, biases, output,
- deconv_info, inner_border.x(), inner_border.y());
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Weights shape: " << weights->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
- return func;
-}
-
-/** Create a backend layer depth concatenate function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend depth concatenate layer function
- */
-std::unique_ptr<arm_compute::IFunction> create_depth_concatenate_layer(DepthConcatenateLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON DepthConcatenate node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Return nullptr if depth concatenate is switched off
- if(!node.is_enabled())
- {
- return nullptr;
- }
-
- // Extract IO and info
- std::vector<arm_compute::ITensor *> inputs;
- for(unsigned int i = 0; i < node.num_inputs(); ++i)
- {
- inputs.push_back(get_backing_tensor(node.input(i)));
- }
- ITensor *output = get_backing_tensor(node.output(0));
-
- // Create and configure function
- auto func = support::cpp14::make_unique<NEDepthConcatenateLayer>();
- func->configure(inputs, output);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated NEDepthConcatenateLayer"
- << " Data Type: " << output->info()->data_type()
- << " Shape: " << output->info()->tensor_shape()
- << " Num Inputs: " << inputs.size()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend layer depth-wise convolution function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend depth-wise convolution layer function
- */
-std::unique_ptr<IFunction> create_depthwise_convolution_layer(DepthwiseConvolutionLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON DepthwiseConvolutionLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *weights = get_backing_tensor(node.input(1));
- ITensor *biases = get_backing_tensor(node.input(2));
- ITensor *output = get_backing_tensor(node.output(0));
-
- if(is_data_type_quantized_asymmetric(input->info()->data_type()))
- {
- biases->info()->set_data_type(DataType::S32);
- }
-
- const PadStrideInfo conv_info = node.convolution_info();
- const DepthwiseConvolutionMethod dwc_algorithm = node.depthwise_convolution_method();
-
- // Create and configure function (we assume that functions have been validated before creation)
- std::unique_ptr<IFunction> func;
- std::string func_name;
- if(dwc_algorithm == DepthwiseConvolutionMethod::OPTIMIZED_3x3)
- {
- std::tie(func, func_name) = create_named_function<NEDepthwiseConvolutionLayer3x3>(std::string("NEDepthwiseConvolutionLayer3x3"),
- input, weights, biases, output, conv_info);
- }
- else
- {
- std::tie(func, func_name) = create_named_function<NEDepthwiseConvolutionLayer>(std::string("NEDepthwiseConvolutionLayer"),
- input, weights, biases, output, conv_info);
- }
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
- << " Data Type: " << input->info()->data_type()
- << " Input QuantInfo: " << input->info()->quantization_info()
- << " Weights QuantInfo: " << weights->info()->quantization_info()
- << " Input shape: " << input->info()->tensor_shape()
- << " Weights shape: " << weights->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
- return func;
-}
-
-/** Create a backend element-wise operation layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend element-wise operation layer function
- */
-std::unique_ptr<IFunction> create_eltwise_layer(EltwiseLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON EltwiseLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 2);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input1 = get_backing_tensor(node.input(0));
- ITensor *input2 = get_backing_tensor(node.input(1));
- ITensor *output = get_backing_tensor(node.output(0));
- const EltwiseOperation eltwise_op = node.eltwise_operation();
- const ConvertPolicy convert_policy = node.convert_policy();
- ARM_COMPUTE_ERROR_ON(input1 == nullptr);
- ARM_COMPUTE_ERROR_ON(input2 == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- std::unique_ptr<IFunction> func = nullptr;
- std::string func_name;
- if(eltwise_op == EltwiseOperation::ADD)
- {
- std::tie(func, func_name) = create_named_function<NEArithmeticAddition>(std::string("NEArithmeticAddition"),
- input1, input2, output, convert_policy);
- }
- else if(eltwise_op == EltwiseOperation::SUB)
- {
- std::tie(func, func_name) = create_named_function<NEArithmeticSubtraction>(std::string("NEArithmeticSubtraction"),
- input1, input2, output, convert_policy);
- }
- else if(eltwise_op == EltwiseOperation::MUL)
- {
- std::tie(func, func_name) = create_named_function<NEPixelWiseMultiplication>(std::string("NEPixelWiseMultiplication"),
- input1, input2, output, 1.f,
- convert_policy, node.rounding_policy());
- }
- else
- {
- ARM_COMPUTE_ERROR("Unsupported element-wise operation!");
- }
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << func_name
- << " Data Type: " << input1->info()->data_type()
- << " Shape : " << input1->info()->tensor_shape()
- << std::endl);
-
- return func;
-}
-
-/** Create a backend flatten layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend flatten layer function
- */
-std::unique_ptr<IFunction> create_flatten_layer(FlattenLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON FlattenLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *output = get_backing_tensor(node.output(0));
-
- // Create and configure function
- auto func = support::cpp14::make_unique<NEFlattenLayer>();
- func->configure(input, output);
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated NEFlattenLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend fully connected layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend fully connected layer function
- */
-std::unique_ptr<IFunction> create_fully_connected_layer(FullyConnectedLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON FullyConnectedLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 3);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *weights = get_backing_tensor(node.input(1));
- ITensor *biases = get_backing_tensor(node.input(2));
- ITensor *output = get_backing_tensor(node.output(0));
-
- // Create and configure function
- auto func = support::cpp14::make_unique<NEFullyConnectedLayer>(get_memory_manager(ctx, Target::NEON));
- func->configure(input, weights, biases, output);
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(weights == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated NEFullyConnectedLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Weights shape: " << weights->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend normalization layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend normalization layer function
- */
-std::unique_ptr<IFunction> create_normalization_layer(NormalizationLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON NormalizationLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *output = get_backing_tensor(node.output(0));
+ NETargetInfo::TensorType *input = get_backing_tensor<NETargetInfo>(node.input(0));
+ NETargetInfo::TensorType *output = get_backing_tensor<NETargetInfo>(node.output(0));
const NormalizationLayerInfo norm_info = node.normalization_info();
ARM_COMPUTE_ERROR_ON(input == nullptr);
ARM_COMPUTE_ERROR_ON(output == nullptr);
// Create and configure function
- auto func = support::cpp14::make_unique<NENormalizationLayer>(get_memory_manager(ctx, Target::NEON));
+ auto func = support::cpp14::make_unique<NENormalizationLayer>(get_memory_manager(ctx, NETargetInfo::TargetType));
func->configure(input, output, norm_info);
// Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated NENormalizationLayer"
+ ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " << node.type()
+ << " Target " << NETargetInfo::TargetType
<< " Data Type: " << input->info()->data_type()
<< " Input shape: " << input->info()->tensor_shape()
<< " Output shape: " << output->info()->tensor_shape()
@@ -476,141 +163,7 @@
return std::move(func);
}
-
-/** Create a backend pooling layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend pooling layer function
- */
-std::unique_ptr<IFunction> create_pooling_layer(PoolingLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON PoolingLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *output = get_backing_tensor(node.output(0));
- const PoolingLayerInfo pool_info = node.pooling_info();
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Create and configure function
- auto func = support::cpp14::make_unique<NEPoolingLayer>();
- func->configure(input, output, pool_info);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated NEPoolingLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << " Pooling info: " << pool_info.pool_type()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend reshape layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend reshape layer function
- */
-std::unique_ptr<IFunction> create_reshape_layer(ReshapeLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON ReshapeLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *output = get_backing_tensor(node.output(0));
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Create and configure function
- auto func = support::cpp14::make_unique<NEReshapeLayer>();
- func->configure(input, output);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated NEReshapeLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend resize layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend resize layer function
- */
-std::unique_ptr<IFunction> create_resize_layer(ResizeLayerNode &node)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE(
- "Creating NEON Resize node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *output = get_backing_tensor(node.output(0));
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
- const InterpolationPolicy policy = node.policy();
-
- // Create and configure function
- auto func = support::cpp14::make_unique<NEScale>();
- func->configure(input, output, policy, BorderMode::CONSTANT);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated NEScale"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << " Interpolation: " << policy
- << std::endl);
-
- return std::move(func);
-}
-
-/** Create a backend softmax layer function
- *
- * @param[in] node Node to create the backend function for
- *
- * @return Backend softmax layer function
- */
-std::unique_ptr<IFunction> create_softmax_layer(SoftmaxLayerNode &node, GraphContext &ctx)
-{
- ARM_COMPUTE_LOG_GRAPH_VERBOSE("Creating NEON SoftmaxLayer node with ID : " << node.id() << " and Name: " << node.name() << std::endl);
- ARM_COMPUTE_ERROR_ON(node.num_inputs() != 1);
- ARM_COMPUTE_ERROR_ON(node.num_outputs() != 1);
-
- // Extract IO and info
- ITensor *input = get_backing_tensor(node.input(0));
- ITensor *output = get_backing_tensor(node.output(0));
- const float beta = node.beta();
- ARM_COMPUTE_ERROR_ON(input == nullptr);
- ARM_COMPUTE_ERROR_ON(output == nullptr);
-
- // Create and configure function
- auto func = support::cpp14::make_unique<NESoftmaxLayer>(get_memory_manager(ctx, Target::NEON));
- func->configure(input, output, beta);
-
- // Log info
- ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated NESoftmaxLayer"
- << " Data Type: " << input->info()->data_type()
- << " Input shape: " << input->info()->tensor_shape()
- << " Output shape: " << output->info()->tensor_shape()
- << std::endl);
-
- return std::move(func);
-}
-} // namespace
+} // namespace detail
std::unique_ptr<IFunction> NEFunctionFactory::create(INode *node, GraphContext &ctx)
{
@@ -623,33 +176,33 @@
switch(type)
{
case NodeType::ActivationLayer:
- return create_activation_layer(*polymorphic_downcast<ActivationLayerNode *>(node));
+ return detail::create_activation_layer<NEActivationLayer, NETargetInfo>(*polymorphic_downcast<ActivationLayerNode *>(node));
case NodeType::BatchNormalizationLayer:
- return create_batch_normalization_layer(*polymorphic_downcast<BatchNormalizationLayerNode *>(node));
+ return detail::create_batch_normalization_layer<NEBatchNormalizationLayer, NETargetInfo>(*polymorphic_downcast<BatchNormalizationLayerNode *>(node));
case NodeType::ConvolutionLayer:
- return create_convolution_layer(*polymorphic_downcast<ConvolutionLayerNode *>(node), ctx);
+ return detail::create_convolution_layer<NEConvolutionLayerFunctions, NETargetInfo>(*polymorphic_downcast<ConvolutionLayerNode *>(node), ctx);
case NodeType::DeconvolutionLayer:
- return create_deconvolution_layer(*polymorphic_downcast<DeconvolutionLayerNode *>(node), ctx);
+ return detail::create_deconvolution_layer<NEDeconvolutionLayer, NETargetInfo>(*polymorphic_downcast<DeconvolutionLayerNode *>(node), ctx);
case NodeType::DepthConcatenateLayer:
- return create_depth_concatenate_layer(*polymorphic_downcast<DepthConcatenateLayerNode *>(node));
+ return detail::create_depth_concatenate_layer<NEDepthConcatenateLayer, NETargetInfo>(*polymorphic_downcast<DepthConcatenateLayerNode *>(node));
case NodeType::DepthwiseConvolutionLayer:
- return create_depthwise_convolution_layer(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
+ return detail::create_depthwise_convolution_layer<NEDepthwiseConvolutionLayerFunctions, NETargetInfo>(*polymorphic_downcast<DepthwiseConvolutionLayerNode *>(node));
case NodeType::EltwiseLayer:
- return create_eltwise_layer(*polymorphic_downcast<EltwiseLayerNode *>(node));
+ return detail::create_eltwise_layer<NEEltwiseFunctions, NETargetInfo>(*polymorphic_downcast<EltwiseLayerNode *>(node));
case NodeType::FlattenLayer:
- return create_flatten_layer(*polymorphic_downcast<FlattenLayerNode *>(node));
+ return detail::create_flatten_layer<NEFlattenLayer, NETargetInfo>(*polymorphic_downcast<FlattenLayerNode *>(node));
case NodeType::FullyConnectedLayer:
- return create_fully_connected_layer(*polymorphic_downcast<FullyConnectedLayerNode *>(node), ctx);
+ return detail::create_fully_connected_layer<NEFullyConnectedLayer, NETargetInfo>(*polymorphic_downcast<FullyConnectedLayerNode *>(node), ctx);
case NodeType::NormalizationLayer:
- return create_normalization_layer(*polymorphic_downcast<NormalizationLayerNode *>(node), ctx);
+ return detail::create_normalization_layer<NENormalizationLayer, NETargetInfo>(*polymorphic_downcast<NormalizationLayerNode *>(node), ctx);
case NodeType::PoolingLayer:
- return create_pooling_layer(*polymorphic_downcast<PoolingLayerNode *>(node));
+ return detail::create_pooling_layer<NEPoolingLayer, NETargetInfo>(*polymorphic_downcast<PoolingLayerNode *>(node));
case NodeType::ReshapeLayer:
- return create_reshape_layer(*polymorphic_downcast<ReshapeLayerNode *>(node));
+ return detail::create_reshape_layer<NEReshapeLayer, NETargetInfo>(*polymorphic_downcast<ReshapeLayerNode *>(node));
case NodeType::ResizeLayer:
- return create_resize_layer(*polymorphic_downcast<ResizeLayerNode *>(node));
+ return detail::create_resize_layer<NEScale, NETargetInfo>(*polymorphic_downcast<ResizeLayerNode *>(node));
case NodeType::SoftmaxLayer:
- return create_softmax_layer(*polymorphic_downcast<SoftmaxLayerNode *>(node), ctx);
+ return detail::create_softmax_layer<NESoftmaxLayer, NETargetInfo>(*polymorphic_downcast<SoftmaxLayerNode *>(node), ctx);
default:
return nullptr;
}