From 090502887d87f52d28e98e90c0e17c582b9e63d6 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Thu, 14 May 2020 10:03:56 +0100 Subject: COMPMID-3069: Align graph convolution implementation for CL and NEON. Enables fast-math on Neon backend for convolution Signed-off-by: Georgios Pinitas Change-Id: Ia072f0fd2db1f0814562049b290cffc91cbbd9a8 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3201 Reviewed-by: Michele Di Giorgio Comments-Addressed: Arm Jenkins --- src/graph/backends/NEON/NEFunctionFactory.cpp | 72 ----------------------- src/runtime/NEON/functions/NEConvolutionLayer.cpp | 4 +- 2 files changed, 2 insertions(+), 74 deletions(-) diff --git a/src/graph/backends/NEON/NEFunctionFactory.cpp b/src/graph/backends/NEON/NEFunctionFactory.cpp index 0aea15d941..454215e7ec 100644 --- a/src/graph/backends/NEON/NEFunctionFactory.cpp +++ b/src/graph/backends/NEON/NEFunctionFactory.cpp @@ -80,78 +80,6 @@ struct NEFusedLayerTypes namespace detail { -// Specialized functions -template <> -std::unique_ptr create_convolution_layer(ConvolutionLayerNode &node, - GraphContext &ctx) -{ - validate_node(node, 3 /* expected inputs */, 1 /* expected outputs */); - - // Extract IO and info - NETargetInfo::TensorType *input = get_backing_tensor(node.input(0)); - NETargetInfo::TensorType *weights = get_backing_tensor(node.input(1)); - NETargetInfo::TensorType *biases = get_backing_tensor(node.input(2)); - NETargetInfo::TensorType *output = get_backing_tensor(node.output(0)); - - const bool is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type()); - - if(is_quantized) - { - biases->info()->set_data_type(DataType::S32); - } - - const PadStrideInfo conv_info = node.convolution_info(); - const ConvolutionMethod conv_algorithm = node.convolution_method(); - const ActivationLayerInfo fused_act = node.fused_activation(); - - // Create and configure function (we assume that functions have been validated before creation) - std::shared_ptr mm = get_memory_manager(ctx, Target::NEON); - std::unique_ptr func; - std::string func_name; - - if(conv_algorithm == ConvolutionMethod::Direct) - { - std::tie(func, func_name) = create_named_memory_managed_function( - std::string("DirectConvolutionLayer"), mm, input, weights, biases, output, conv_info, fused_act); - } - else if(conv_algorithm == ConvolutionMethod::GEMM) - { - std::tie(func, func_name) = create_named_memory_managed_function( - std::string("GEMMConvolutionLayer"), mm, input, weights, biases, output, conv_info, WeightsInfo(), Size2D(1, 1), fused_act); - } - else if(conv_algorithm == ConvolutionMethod::Winograd) - { - std::tie(func, func_name) = create_named_memory_managed_function( - std::string("WinogradConvolutionLayer"), mm, input, weights, biases, output, conv_info, fused_act); - } - else - { - std::tie(func, func_name) = create_named_memory_managed_function( - std::string("ConvolutionLayer"), mm, input, weights, biases, output, conv_info, WeightsInfo(), Size2D(1, 1), fused_act); - } - - // Log info - std::ostringstream qss; - if(is_quantized) - { - qss << " Input QuantInfo: " << input->info()->quantization_info() - << " Weights QuantInfo: " << weights->info()->quantization_info() - << " Output QuantInfo: " << output->info()->quantization_info(); - } - ARM_COMPUTE_LOG_GRAPH_INFO("Instantiated " - << node.name() - << " Type: " << func_name - << " Target: " << NETargetInfo::TargetType - << " Data Type: " << input->info()->data_type() - << qss.str() - << " Input shape: " << input->info()->tensor_shape() - << " Weights shape: " << weights->info()->tensor_shape() - << " Output shape: " << output->info()->tensor_shape() - << (fused_act.enabled() ? " " + to_string(fused_act.activation()) : "") - << std::endl); - return func; -} - template <> std::unique_ptr create_normalization_layer(NormalizationLayerNode &node, GraphContext &ctx) { diff --git a/src/runtime/NEON/functions/NEConvolutionLayer.cpp b/src/runtime/NEON/functions/NEConvolutionLayer.cpp index dcd26fc1cd..4a779917a7 100644 --- a/src/runtime/NEON/functions/NEConvolutionLayer.cpp +++ b/src/runtime/NEON/functions/NEConvolutionLayer.cpp @@ -50,7 +50,7 @@ void NEConvolutionLayer::configure(ITensor *input, const ITensor *weights, const ARM_COMPUTE_ERROR_THROW_ON(NEConvolutionLayer::validate(input->info(), weights->info(), ((biases != nullptr) ? biases->info() : nullptr), output->info(), conv_info, weights_info, dilation, act_info, enable_fast_math)); - switch(NEConvolutionLayer::get_convolution_method(input->info(), weights->info(), output->info(), conv_info, weights_info, dilation, act_info)) + switch(NEConvolutionLayer::get_convolution_method(input->info(), weights->info(), output->info(), conv_info, weights_info, dilation, act_info, enable_fast_math)) { case ConvolutionMethod::WINOGRAD: { @@ -91,7 +91,7 @@ Status NEConvolutionLayer::validate(const ITensorInfo *input, const ITensorInfo { ARM_COMPUTE_RETURN_ERROR_ON_MSG((num_groups != 1), "Grouping (num_groups != 1) is not supported on NEON"); - switch(NEConvolutionLayer::get_convolution_method(input, weights, output, conv_info, weights_info, dilation, act_info)) + switch(NEConvolutionLayer::get_convolution_method(input, weights, output, conv_info, weights_info, dilation, act_info, enable_fast_math)) { case ConvolutionMethod::WINOGRAD: //Validate Winograd -- cgit v1.2.1