aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Tello <pablo.tello@arm.com>2019-04-30 10:32:42 +0100
committerPablo Marquez <pablo.tello@arm.com>2019-05-02 09:21:53 +0000
commit01bbacb465da79d3b4d1a3f313b172fe295642f5 (patch)
tree0d96441498211dbccc3ddd952aa7b0bb9aaee277
parent05fb448bf48e31d723dfd9f4bbf3899ff65f0fba (diff)
downloadComputeLibrary-01bbacb465da79d3b4d1a3f313b172fe295642f5.tar.gz
COMPMID-2176: Add dilation support in calculate_same_pad()
Change-Id: Ic12138cd3ebd3198c854b13eef02717137bda660 Signed-off-by: Pablo Tello <pablo.tello@arm.com> Reviewed-on: https://review.mlplatform.org/c/1059 Tested-by: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Usama Arif <usama.arif@arm.com> Comments-Addressed: Usama Arif <usama.arif@arm.com> Reviewed-by: Michalis Spyrou <michalis.spyrou@arm.com>
-rw-r--r--arm_compute/core/Utils.h19
-rw-r--r--src/core/Utils.cpp24
2 files changed, 25 insertions, 18 deletions
diff --git a/arm_compute/core/Utils.h b/arm_compute/core/Utils.h
index 2640264f55..1de0df6096 100644
--- a/arm_compute/core/Utils.h
+++ b/arm_compute/core/Utils.h
@@ -828,10 +828,11 @@ inline void permute_strides(Dimensions<T> &dimensions, const PermutationVector &
* @param[in] weights_shape Weights shape
* @param[in] conv_info Convolution information (containing strides)
* @param[in] data_layout (Optional) Data layout of the input and weights tensor
+ * @param[in] dilation (Optional) Dilation factor used in the convolution.
*
* @return PadStrideInfo for SAME padding
*/
-PadStrideInfo calculate_same_pad(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info, DataLayout data_layout = DataLayout::NCHW);
+PadStrideInfo calculate_same_pad(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info, DataLayout data_layout = DataLayout::NCHW, const Size2D &dilation = Size2D(1u, 1u));
/** Returns expected width and height of the deconvolution's output tensor.
*
@@ -846,10 +847,10 @@ PadStrideInfo calculate_same_pad(TensorShape input_shape, TensorShape weights_sh
*
* @return A pair with the new width in the first position and the new height in the second.
*/
-const std::pair<unsigned int, unsigned int> deconvolution_output_dimensions(unsigned int in_width, unsigned int in_height,
- unsigned int kernel_width, unsigned int kernel_height,
- unsigned int padx, unsigned int pady,
- unsigned int stride_x, unsigned int stride_y);
+std::pair<unsigned int, unsigned int> deconvolution_output_dimensions(unsigned int in_width, unsigned int in_height,
+ unsigned int kernel_width, unsigned int kernel_height,
+ unsigned int padx, unsigned int pady,
+ unsigned int stride_x, unsigned int stride_y);
/** Returns expected width and height of output scaled tensor depending on dimensions rounding mode.
*
@@ -862,10 +863,10 @@ const std::pair<unsigned int, unsigned int> deconvolution_output_dimensions(unsi
*
* @return A pair with the new width in the first position and the new height in the second.
*/
-const std::pair<unsigned int, unsigned int> scaled_dimensions(unsigned int width, unsigned int height,
- unsigned int kernel_width, unsigned int kernel_height,
- const PadStrideInfo &pad_stride_info,
- const Size2D &dilation = Size2D(1U, 1U));
+std::pair<unsigned int, unsigned int> scaled_dimensions(unsigned int width, unsigned int height,
+ unsigned int kernel_width, unsigned int kernel_height,
+ const PadStrideInfo &pad_stride_info,
+ const Size2D &dilation = Size2D(1U, 1U));
/** Convert a tensor format into a string.
*
diff --git a/src/core/Utils.cpp b/src/core/Utils.cpp
index 44d819942e..589b7375ae 100644
--- a/src/core/Utils.cpp
+++ b/src/core/Utils.cpp
@@ -326,24 +326,30 @@ std::string arm_compute::lower_string(const std::string &val)
return res;
}
-PadStrideInfo arm_compute::calculate_same_pad(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info, DataLayout data_layout)
+PadStrideInfo arm_compute::calculate_same_pad(TensorShape input_shape, TensorShape weights_shape, PadStrideInfo conv_info, DataLayout data_layout, const Size2D &dilation)
{
const unsigned int width_idx = arm_compute::get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
const unsigned int height_idx = arm_compute::get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
const auto &strides = conv_info.stride();
const int out_width = std::ceil(float(input_shape[width_idx]) / float(strides.first));
const int out_height = std::ceil(float(input_shape[height_idx]) / float(strides.second));
- const int pad_width = ((out_width - 1) * strides.first + weights_shape[width_idx] - input_shape[width_idx]);
- const int pad_height = ((out_height - 1) * strides.second + weights_shape[height_idx] - input_shape[height_idx]);
+ const int pad_width = (out_width - 1) * strides.first + (weights_shape[width_idx] + (dilation.x() - 1) * (weights_shape[width_idx] - 1) - input_shape[width_idx]);
+ const int pad_height = (out_height - 1) * strides.second + (weights_shape[height_idx] + (dilation.y() - 1) * (weights_shape[height_idx] - 1) - input_shape[height_idx]);
const int same_pad_left = pad_width / 2;
const int same_pad_top = pad_height / 2;
const int same_pad_right = pad_width - same_pad_left;
const int same_pad_bottom = pad_height - same_pad_top;
- return PadStrideInfo(strides.first, strides.second, same_pad_left, same_pad_right, same_pad_top, same_pad_bottom, DimensionRoundingType::CEIL);
+ return { static_cast<unsigned int>(strides.first),
+ static_cast<unsigned int>(strides.second),
+ static_cast<unsigned int>(same_pad_left),
+ static_cast<unsigned int>(same_pad_right),
+ static_cast<unsigned int>(same_pad_top),
+ static_cast<unsigned int>(same_pad_bottom),
+ DimensionRoundingType::CEIL };
}
-const std::pair<unsigned int, unsigned int> arm_compute::deconvolution_output_dimensions(
+std::pair<unsigned int, unsigned int> arm_compute::deconvolution_output_dimensions(
unsigned int in_width, unsigned int in_height, unsigned int kernel_width, unsigned int kernel_height, unsigned int padx, unsigned int pady,
unsigned int stride_x, unsigned int stride_y)
{
@@ -356,10 +362,10 @@ const std::pair<unsigned int, unsigned int> arm_compute::deconvolution_output_di
return std::make_pair<unsigned int, unsigned int>(w, h);
}
-const std::pair<unsigned int, unsigned int> arm_compute::scaled_dimensions(unsigned int width, unsigned int height,
- unsigned int kernel_width, unsigned int kernel_height,
- const PadStrideInfo &pad_stride_info,
- const Size2D &dilation)
+std::pair<unsigned int, unsigned int> arm_compute::scaled_dimensions(unsigned int width, unsigned int height,
+ unsigned int kernel_width, unsigned int kernel_height,
+ const PadStrideInfo &pad_stride_info,
+ const Size2D &dilation)
{
const unsigned int pad_left = pad_stride_info.pad_left();
const unsigned int pad_top = pad_stride_info.pad_top();