From 4e288696a2ca8e1c9d6d37d90d237c1a18d6e364 Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Tue, 27 Jun 2017 11:41:59 +0100 Subject: COMPMID-417 - Adding support for rectangular kernels Change-Id: I4dde0929bc689c83582b95856dd0253228125df2 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/78994 Reviewed-by: Moritz Pflanzer Tested-by: Kaizen Reviewed-by: Georgios Pinitas --- src/core/CL/kernels/CLPoolingLayerKernel.cpp | 24 ++++++++++----------- src/core/NEON/kernels/NEPoolingLayerKernel.cpp | 22 +++++++++---------- src/core/Utils.cpp | 25 ++++++++++++---------- src/runtime/CL/functions/CLConvolutionLayer.cpp | 7 +++--- .../CL/functions/CLLocallyConnectedLayer.cpp | 4 ++-- src/runtime/NEON/functions/NEConvolutionLayer.cpp | 7 +++--- .../NEON/functions/NELocallyConnectedLayer.cpp | 4 ++-- 7 files changed, 47 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/core/CL/kernels/CLPoolingLayerKernel.cpp b/src/core/CL/kernels/CLPoolingLayerKernel.cpp index 7648025caa..15f26e3985 100644 --- a/src/core/CL/kernels/CLPoolingLayerKernel.cpp +++ b/src/core/CL/kernels/CLPoolingLayerKernel.cpp @@ -52,16 +52,15 @@ BorderSize CLPoolingLayerKernel::border_size() const void CLPoolingLayerKernel::configure(const ICLTensor *input, ICLTensor *output, const PoolingLayerInfo &pool_info) { - int pool_pad_x = 0; - int pool_pad_y = 0; - int pool_stride_x = 0; - int pool_stride_y = 0; - unsigned int pooled_w = 0; - unsigned int pooled_h = 0; - const PoolingType pool_type = pool_info.pool_type(); - const int pool_size = pool_info.pool_size(); - const PadStrideInfo pad_stride_info = pool_info.pad_stride_info(); - DimensionRoundingType pool_round = pad_stride_info.round(); + int pool_pad_x = 0; + int pool_pad_y = 0; + int pool_stride_x = 0; + int pool_stride_y = 0; + unsigned int pooled_w = 0; + unsigned int pooled_h = 0; + const PoolingType pool_type = pool_info.pool_type(); + const int pool_size = pool_info.pool_size(); + const PadStrideInfo pad_stride_info = pool_info.pad_stride_info(); std::tie(pool_pad_x, pool_pad_y) = pad_stride_info.pad(); std::tie(pool_stride_x, pool_stride_y) = pad_stride_info.stride(); @@ -78,9 +77,8 @@ void CLPoolingLayerKernel::configure(const ICLTensor *input, ICLTensor *output, std::tie(pooled_w, pooled_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), pool_size, - pool_stride_x, pool_stride_y, - pool_pad_x, pool_pad_y, - pool_round); + pool_size, + pool_info.pad_stride_info()); ARM_COMPUTE_UNUSED(pooled_w); ARM_COMPUTE_UNUSED(pooled_h); ARM_COMPUTE_ERROR_ON((output->info()->dimension(0) != pooled_w) || (output->info()->dimension(1) != pooled_h)); diff --git a/src/core/NEON/kernels/NEPoolingLayerKernel.cpp b/src/core/NEON/kernels/NEPoolingLayerKernel.cpp index 8991e9b9ee..578b01419d 100644 --- a/src/core/NEON/kernels/NEPoolingLayerKernel.cpp +++ b/src/core/NEON/kernels/NEPoolingLayerKernel.cpp @@ -81,16 +81,15 @@ BorderSize NEPoolingLayerKernel::border_size() const void NEPoolingLayerKernel::configure(const ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info) { - int pool_pad_x = 0; - int pool_pad_y = 0; - int pool_stride_x = 0; - int pool_stride_y = 0; - unsigned int pooled_w = 0; - unsigned int pooled_h = 0; - PoolingType pool_type = pool_info.pool_type(); - int pool_size = pool_info.pool_size(); - const PadStrideInfo pad_stride_info = pool_info.pad_stride_info(); - DimensionRoundingType pool_round = pad_stride_info.round(); + int pool_pad_x = 0; + int pool_pad_y = 0; + int pool_stride_x = 0; + int pool_stride_y = 0; + unsigned int pooled_w = 0; + unsigned int pooled_h = 0; + PoolingType pool_type = pool_info.pool_type(); + int pool_size = pool_info.pool_size(); + const PadStrideInfo pad_stride_info = pool_info.pad_stride_info(); std::tie(pool_pad_x, pool_pad_y) = pad_stride_info.pad(); std::tie(pool_stride_x, pool_stride_y) = pad_stride_info.stride(); @@ -109,8 +108,7 @@ void NEPoolingLayerKernel::configure(const ITensor *input, ITensor *output, cons // Check output dimensions std::tie(pooled_w, pooled_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), - pool_size, pool_stride_x, pool_stride_y, - pool_pad_x, pool_pad_y, pool_round); + pool_size, pool_size, pool_info.pad_stride_info()); ARM_COMPUTE_UNUSED(pooled_w); ARM_COMPUTE_UNUSED(pooled_h); ARM_COMPUTE_ERROR_ON((output->info()->dimension(0) != pooled_w) || (output->info()->dimension(1) != pooled_h)); diff --git a/src/core/Utils.cpp b/src/core/Utils.cpp index bf005c12f6..f6230c0199 100644 --- a/src/core/Utils.cpp +++ b/src/core/Utils.cpp @@ -233,22 +233,25 @@ std::string arm_compute::lower_string(const std::string &val) return res; } -const std::pair arm_compute::scaled_dimensions(unsigned int width, unsigned int height, unsigned int kernel_size, - unsigned int stride_x, unsigned int stride_y, - unsigned int pad_x, unsigned int pad_y, - DimensionRoundingType round_type) +const std::pair arm_compute::scaled_dimensions(unsigned int width, unsigned int height, + unsigned int kernel_width, unsigned int kernel_height, + const PadStrideInfo &pad_stride_info) { - unsigned int w = 0; - unsigned int h = 0; - switch(round_type) + const unsigned int pad_x = pad_stride_info.pad().first; + const unsigned int pad_y = pad_stride_info.pad().second; + const unsigned int stride_x = pad_stride_info.stride().first; + const unsigned int stride_y = pad_stride_info.stride().second; + unsigned int w = 0; + unsigned int h = 0; + switch(pad_stride_info.round()) { case DimensionRoundingType::FLOOR: - w = static_cast(std::floor((static_cast(width + 2 * pad_x - kernel_size) / stride_x) + 1)); - h = static_cast(std::floor((static_cast(height + 2 * pad_y - kernel_size) / stride_y) + 1)); + w = static_cast(std::floor((static_cast(width + 2 * pad_x - kernel_width) / stride_x) + 1)); + h = static_cast(std::floor((static_cast(height + 2 * pad_y - kernel_height) / stride_y) + 1)); break; case DimensionRoundingType::CEIL: - w = static_cast(std::ceil((static_cast(width + 2 * pad_x - kernel_size) / stride_x) + 1)); - h = static_cast(std::ceil((static_cast(height + 2 * pad_y - kernel_size) / stride_y) + 1)); + w = static_cast(std::ceil((static_cast(width + 2 * pad_x - kernel_width) / stride_x) + 1)); + h = static_cast(std::ceil((static_cast(height + 2 * pad_y - kernel_height) / stride_y) + 1)); break; default: ARM_COMPUTE_ERROR("Unsupported rounding type"); diff --git a/src/runtime/CL/functions/CLConvolutionLayer.cpp b/src/runtime/CL/functions/CLConvolutionLayer.cpp index f0bbc3514f..933d92bef7 100644 --- a/src/runtime/CL/functions/CLConvolutionLayer.cpp +++ b/src/runtime/CL/functions/CLConvolutionLayer.cpp @@ -127,9 +127,10 @@ void CLConvolutionLayer::configure(const ICLTensor *input, const ICLTensor *weig unsigned int conv_w = 0; unsigned int conv_h = 0; - const unsigned int kernel_width = _are_weights_reshaped ? weights_info.kernel_size() : weights->info()->dimension(0); - std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), kernel_width, - stride_x, stride_y, pad_x, pad_y, conv_info.round()); + const unsigned int kernel_width = _are_weights_reshaped ? weights_info.kernel_size().first : weights->info()->dimension(0); + const unsigned int kernel_height = _are_weights_reshaped ? weights_info.kernel_size().second : weights->info()->dimension(1); + std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), kernel_width, kernel_height, + conv_info); ARM_COMPUTE_ERROR_ON_MSG((output->info()->dimension(0) != conv_w) || (output->info()->dimension(1) != conv_h), "Output shape does not match the expected one"); // Check if its a "fully connected" convolution diff --git a/src/runtime/CL/functions/CLLocallyConnectedLayer.cpp b/src/runtime/CL/functions/CLLocallyConnectedLayer.cpp index 263fb51987..0e6d23e0d8 100644 --- a/src/runtime/CL/functions/CLLocallyConnectedLayer.cpp +++ b/src/runtime/CL/functions/CLLocallyConnectedLayer.cpp @@ -68,8 +68,8 @@ void CLLocallyConnectedLayer::configure(const ICLTensor *input, const ICLTensor // Get convolved dimensions unsigned int conv_w = 0; unsigned int conv_h = 0; - std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), weights->info()->dimension(0), - stride_x, stride_y, pad_x, pad_y, conv_info.round()); + std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), weights->info()->dimension(0), weights->info()->dimension(1), + conv_info); ARM_COMPUTE_ERROR_ON_MSG((output->info()->dimension(0) != conv_w) || (output->info()->dimension(1) != conv_h), "Output shape does not match the expected one"); ARM_COMPUTE_ERROR_ON_MSG(weights->info()->dimension(4) != (conv_w * conv_h), "Weights shape does not match the expected one"); diff --git a/src/runtime/NEON/functions/NEConvolutionLayer.cpp b/src/runtime/NEON/functions/NEConvolutionLayer.cpp index 82c33d54bb..b38d6617d5 100644 --- a/src/runtime/NEON/functions/NEConvolutionLayer.cpp +++ b/src/runtime/NEON/functions/NEConvolutionLayer.cpp @@ -131,9 +131,10 @@ void NEConvolutionLayer::configure(const ITensor *input, const ITensor *weights, unsigned int conv_w = 0; unsigned int conv_h = 0; - const unsigned int kernel_width = (_are_weights_reshaped) ? weights_info.kernel_size() : weights->info()->dimension(0); - std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), kernel_width, - stride_x, stride_y, pad_x, pad_y, conv_info.round()); + const unsigned int kernel_width = (_are_weights_reshaped) ? weights_info.kernel_size().first : weights->info()->dimension(0); + const unsigned int kernel_height = (_are_weights_reshaped) ? weights_info.kernel_size().second : weights->info()->dimension(1); + std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), kernel_width, kernel_height, + conv_info); ARM_COMPUTE_ERROR_ON_MSG((output->info()->dimension(0) != conv_w) || (output->info()->dimension(1) != conv_h), "Output shape does not match the expected one"); // Check if its a "fully connected" convolution diff --git a/src/runtime/NEON/functions/NELocallyConnectedLayer.cpp b/src/runtime/NEON/functions/NELocallyConnectedLayer.cpp index 85d7ba3650..3b095b4688 100644 --- a/src/runtime/NEON/functions/NELocallyConnectedLayer.cpp +++ b/src/runtime/NEON/functions/NELocallyConnectedLayer.cpp @@ -68,8 +68,8 @@ void NELocallyConnectedLayer::configure(const ITensor *input, const ITensor *wei // Get convolved dimensions unsigned int conv_w = 0; unsigned int conv_h = 0; - std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), weights->info()->dimension(0), - stride_x, stride_y, pad_x, pad_y, conv_info.round()); + std::tie(conv_w, conv_h) = scaled_dimensions(input->info()->dimension(0), input->info()->dimension(1), weights->info()->dimension(0), weights->info()->dimension(1), + conv_info); ARM_COMPUTE_ERROR_ON_MSG((output->info()->dimension(0) != conv_w) || (output->info()->dimension(1) != conv_h), "Output shape does not match the expected one"); ARM_COMPUTE_ERROR_ON_MSG(weights->info()->dimension(4) != (conv_w * conv_h), "Weights shape does not match the expected one"); -- cgit v1.2.1