From 7bfe4c52823b3fad82339e5a686aa94e30d57e7b Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Fri, 24 Nov 2017 09:54:20 +0000 Subject: COMPMID-554 Add Nodes - DepthwiseConvolutionLayer Change-Id: Icaef85d7474f7532bf7d93d11b5c787712e57bdd Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/110524 Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com Reviewed-by: Georgios Pinitas --- src/graph/operations/CLSimpleOperations.cpp | 50 +++++++++++++++++++++++++++++ src/graph/operations/NESimpleOperations.cpp | 50 +++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) (limited to 'src/graph/operations') diff --git a/src/graph/operations/CLSimpleOperations.cpp b/src/graph/operations/CLSimpleOperations.cpp index 4ec3a22f37..881f4910ad 100644 --- a/src/graph/operations/CLSimpleOperations.cpp +++ b/src/graph/operations/CLSimpleOperations.cpp @@ -135,6 +135,56 @@ REGISTER_SIMPLE_OPERATION(CLDepthConvertLayerOperation, OPENCL, OperationType::D return std::move(depthconvert); } +/* DepthwiseConvolutionLayer Layer */ +REGISTER_SIMPLE_OPERATION(CLDepthwiseConvolutionOperation, OPENCL, OperationType::DepthwiseConvolutionLayer) +{ + ARM_COMPUTE_ERROR_ON(ctx.num_inputs() != 2 || ctx.num_inputs() != 3); + ARM_COMPUTE_ERROR_ON(ctx.num_outputs() != 1); + ARM_COMPUTE_ERROR_ON(dynamic_cast(ctx.input(0)) == nullptr); + ARM_COMPUTE_ERROR_ON(dynamic_cast(ctx.output(0)) == nullptr); + + // Extract IO and info + auto *in = dynamic_cast(ctx.input(0)); + auto *weights = dynamic_cast(ctx.input(1)); + auto *biases = ctx.num_inputs() == 3 ? dynamic_cast(ctx.input(2)) : nullptr; + auto *out = dynamic_cast(ctx.output(0)); + const auto conv_info = ctx.parameter("ConvolutionInfo"); + const auto opt3x3 = ctx.parameter("Optimized3x3"); + + // Create and configure function + std::unique_ptr func; + bool run_3x3_opt = opt3x3 && weights->info()->dimension(0) == 3; + if(run_3x3_opt) + { + auto depwthwise_conv = arm_compute::support::cpp14::make_unique(); + depwthwise_conv->configure(in, weights, biases, out, conv_info); + func = std::move(depwthwise_conv); + } + else + { + auto depwthwise_conv = arm_compute::support::cpp14::make_unique(); + depwthwise_conv->configure(in, weights, biases, out, conv_info); + func = std::move(depwthwise_conv); + } + + // Log info + ARM_COMPUTE_LOG_GRAPH_INFO("Instantiating CLDepthwiseConvolutionLayer" + << " Data Type: " << in->info()->data_type() + << " Input shape: " << in->info()->tensor_shape() + << " Weights shape: " << weights->info()->tensor_shape() + << " Output shape: " << out->info()->tensor_shape()); + if(biases == nullptr) + { + ARM_COMPUTE_LOG_GRAPH_INFO(" Biases shape: No biases provided" << std::endl); + } + else + { + ARM_COMPUTE_LOG_GRAPH_INFO(" Biases shape: " << biases->info()->tensor_shape() << std::endl); + } + + return func; +} + /* DeQuantizationLayer Layer */ REGISTER_SIMPLE_OPERATION(CLDequantizationLayerOperation, OPENCL, OperationType::DequantizationLayer) { diff --git a/src/graph/operations/NESimpleOperations.cpp b/src/graph/operations/NESimpleOperations.cpp index 12f8c6c76b..c77aeeca11 100644 --- a/src/graph/operations/NESimpleOperations.cpp +++ b/src/graph/operations/NESimpleOperations.cpp @@ -135,6 +135,56 @@ REGISTER_SIMPLE_OPERATION(NEDepthConvertLayerOperation, NEON, OperationType::Dep return std::move(depthconvert); } +/* DepthwiseConvolutionLayer Layer */ +REGISTER_SIMPLE_OPERATION(NEDepthwiseConvolutionOperation, NEON, OperationType::DepthwiseConvolutionLayer) +{ + ARM_COMPUTE_ERROR_ON(ctx.num_inputs() != 2 || ctx.num_inputs() != 3); + ARM_COMPUTE_ERROR_ON(ctx.num_outputs() != 1); + ARM_COMPUTE_ERROR_ON(dynamic_cast(ctx.input(0)) == nullptr); + ARM_COMPUTE_ERROR_ON(dynamic_cast(ctx.output(0)) == nullptr); + + // Extract IO and info + auto *in = dynamic_cast(ctx.input(0)); + auto *weights = dynamic_cast(ctx.input(1)); + auto *biases = ctx.num_inputs() == 3 ? dynamic_cast(ctx.input(2)) : nullptr; + auto *out = dynamic_cast(ctx.output(0)); + const auto conv_info = ctx.parameter("ConvolutionInfo"); + const auto opt3x3 = ctx.parameter("Optimized3x3"); + + // Create and configure function + std::unique_ptr func; + bool run_3x3_opt = opt3x3 && weights->info()->dimension(0) == 3; + if(run_3x3_opt) + { + auto depwthwise_conv = arm_compute::support::cpp14::make_unique(); + depwthwise_conv->configure(in, weights, biases, out, conv_info); + func = std::move(depwthwise_conv); + } + else + { + auto depwthwise_conv = arm_compute::support::cpp14::make_unique(); + depwthwise_conv->configure(in, weights, biases, out, conv_info); + func = std::move(depwthwise_conv); + } + + // Log info + ARM_COMPUTE_LOG_GRAPH_INFO("Instantiating NEDepthwiseConvolutionLayer" + << " Data Type: " << in->info()->data_type() + << " Input shape: " << in->info()->tensor_shape() + << " Weights shape: " << weights->info()->tensor_shape() + << " Output shape: " << out->info()->tensor_shape()); + if(biases == nullptr) + { + ARM_COMPUTE_LOG_GRAPH_INFO(" Biases shape: No biases provided" << std::endl); + } + else + { + ARM_COMPUTE_LOG_GRAPH_INFO(" Biases shape: " << biases->info()->tensor_shape() << std::endl); + } + + return func; +} + /* DeQuantizationLayer Layer */ REGISTER_SIMPLE_OPERATION(NEDequantizationLayerOperation, NEON, OperationType::DequantizationLayer) { -- cgit v1.2.1