aboutsummaryrefslogtreecommitdiff
path: root/src/core/helpers
diff options
context:
space:
mode:
authorSiCongLi <sicong.li@arm.com>2021-02-22 14:28:33 +0000
committerSiCong Li <sicong.li@arm.com>2021-03-08 09:39:03 +0000
commitc7b1e84ac5f3ada1b2f78c66979ef4d44804a955 (patch)
tree3f2dd18121727cf8000a84ed0030523ce7c0e91e /src/core/helpers
parentb861074c74ea99222207a4a0a71954f8852f8704 (diff)
downloadComputeLibrary-c7b1e84ac5f3ada1b2f78c66979ef4d44804a955.tar.gz
Remove usage of valid window region in NHWC CPU kernels - Part1
Replace all calculate_max_window(ValidRegion, ...) with calculate_max_window(TensorShape, ...) in CPU kernels Resolves COMPMID-4152 (1/2) Change-Id: I7403ea6b24b9e7889890839142a06439d6c8a499 Signed-off-by: SiCongLi <sicong.li@arm.com> Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/5202 Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'src/core/helpers')
-rw-r--r--src/core/helpers/WindowHelpers.cpp53
-rw-r--r--src/core/helpers/WindowHelpers.h15
2 files changed, 65 insertions, 3 deletions
diff --git a/src/core/helpers/WindowHelpers.cpp b/src/core/helpers/WindowHelpers.cpp
index ba10eb9775..75ffb71b4b 100644
--- a/src/core/helpers/WindowHelpers.cpp
+++ b/src/core/helpers/WindowHelpers.cpp
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2020 Arm Limited.
+* Copyright (c) 2020-2021 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -79,6 +79,57 @@ Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps,
return window;
}
+Window calculate_max_window(const TensorShape &shape, const Steps &steps, bool skip_border, BorderSize border_size)
+{
+ if(!skip_border)
+ {
+ border_size = BorderSize(0);
+ }
+
+ Window window;
+
+ window.set(0, Window::Dimension(
+ // Skip the border left of the image
+ border_size.left,
+ // Skip the border right of the image
+ // Make sure the window width is a multiple of the step size
+ border_size.left + ceil_to_multiple(std::max(0, static_cast<int>(shape[0]) - static_cast<int>(border_size.left) - static_cast<int>(border_size.right)), steps[0]),
+ steps[0]));
+
+ size_t n = 1;
+
+ if(shape.num_dimensions() > 1)
+ {
+ window.set(1, Window::Dimension(
+ // Skip the border above the image
+ border_size.top,
+ // Skip the border below the image
+ border_size.top + ceil_to_multiple(std::max(0, static_cast<int>(shape[1]) - static_cast<int>(border_size.top) - static_cast<int>(border_size.bottom)), steps[1]),
+ steps[1]));
+
+ ++n;
+ }
+
+ if(shape.num_dimensions() > 2)
+ {
+ window.set(2, Window::Dimension(0, std::max<size_t>(1, shape[2]), steps[2]));
+
+ ++n;
+ }
+
+ for(; n < shape.num_dimensions(); ++n)
+ {
+ window.set(n, Window::Dimension(0, std::max<size_t>(1, shape[n])));
+ }
+
+ for(; n < Coordinates::num_max_dimensions; ++n)
+ {
+ window.set(n, Window::Dimension(0, 1));
+ }
+
+ return window;
+}
+
Window calculate_max_enlarged_window(const ValidRegion &valid_region, const Steps &steps, BorderSize border_size)
{
const Coordinates &anchor = valid_region.anchor;
diff --git a/src/core/helpers/WindowHelpers.h b/src/core/helpers/WindowHelpers.h
index 9bc2135b6d..9216c33f16 100644
--- a/src/core/helpers/WindowHelpers.h
+++ b/src/core/helpers/WindowHelpers.h
@@ -1,5 +1,5 @@
/*
-* Copyright (c) 2020 Arm Limited.
+* Copyright (c) 2020-2021 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
@@ -107,6 +107,17 @@ Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps
/** Calculate the maximum window for a given tensor shape and border setting
*
+ * @param[in] shape Shape of the tensor space
+ * @param[in] steps (Optional) Number of elements processed for each step.
+ * @param[in] skip_border (Optional) If true exclude the border region from the window.
+ * @param[in] border_size (Optional) Border size.
+ *
+ * @return The maximum window the kernel can be executed on.
+ */
+Window calculate_max_window(const TensorShape &shape, const Steps &steps = Steps(), bool skip_border = false, BorderSize border_size = BorderSize());
+
+/** Calculate the maximum window for a given tensor shape and border setting
+ *
* @param[in] info Tensor info object defining the shape of the object for which the window is created.
* @param[in] steps (Optional) Number of elements processed for each step.
* @param[in] skip_border (Optional) If true exclude the border region from the window.
@@ -116,7 +127,7 @@ Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps
*/
inline Window calculate_max_window(const ITensorInfo &info, const Steps &steps = Steps(), bool skip_border = false, BorderSize border_size = BorderSize())
{
- return calculate_max_window(info.valid_region(), steps, skip_border, border_size);
+ return calculate_max_window(info.tensor_shape(), steps, skip_border, border_size);
}
/** Calculate the maximum window used by a horizontal kernel for a given tensor shape and border setting