aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiorgio Arena <giorgio.arena@arm.com>2017-11-28 18:31:34 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:41:58 +0000
commitb81fa60a6a78aea2f8e30dd7f2a495b510b4f918 (patch)
tree50bce02bdf76f90f22fd30145c792716b48e8bb1
parent04a8f8c4994f1c32b3f16a832c0e6f2599364c02 (diff)
downloadComputeLibrary-b81fa60a6a78aea2f8e30dd7f2a495b510b4f918.tar.gz
COMPMID-715 Shrink window to size 0 if static and not resizable
Change-Id: Ifddf920bd5b8057a5a072ad64c68c9df2ba1c93c Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/111018 Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com <bsgcomp@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
-rw-r--r--src/core/AccessWindowStatic.cpp90
1 files changed, 37 insertions, 53 deletions
diff --git a/src/core/AccessWindowStatic.cpp b/src/core/AccessWindowStatic.cpp
index 8a7f37ac9b..81ad60bc4c 100644
--- a/src/core/AccessWindowStatic.cpp
+++ b/src/core/AccessWindowStatic.cpp
@@ -89,7 +89,7 @@ void AccessWindowStatic::set_valid_region(const Window &window, const ValidRegio
bool AccessWindowStatic::update_window_if_needed(Window &window) const
{
- // Only update the window size if we can't use padding
+ // If the padding is not enough and the tensor is not resizable, shrink the window to size 0
if(_info == nullptr || _info->is_resizable())
{
return false;
@@ -101,81 +101,65 @@ bool AccessWindowStatic::update_window_if_needed(Window &window) const
bool window_modified = false;
- int front_pad_y = 0;
-
- // Adjust window start for Y dimension
+ // Calculate if padding is enough
if(_start_y < 0)
{
- // Calculate rows available above the tensor
const int front_pad_y_available = -static_cast<int>(offset_first_element / strides[1]);
if(_start_y < front_pad_y_available)
{
- // Not enough padding available, need to shrink the window
- const int start = adjust_up(_start_y, front_pad_y_available, window.y().step());
-
- window.set(1, Window::Dimension(start, window.y().end(), window.y().step()));
window_modified = true;
}
-
- // Update front padding with reconstructed value
- front_pad_y = std::max(0, -window.y().start());
}
- // Adjust window end for Y dimension
- if(_end_y > static_cast<int>(shape[1]))
+ if(!window_modified)
{
- const int stride_z = _info->num_dimensions() > 2 ? strides[2] : _info->total_size();
-
- // Calculate rows available below the tensor
- const int tail_pad_y_available = (stride_z / strides[1]) - shape[1] - front_pad_y;
-
- if(static_cast<int>(shape[1]) + tail_pad_y_available < _end_y)
+ if(_end_y > static_cast<int>(shape[1]))
{
- // Not enough padding available, need to shrink the window
- const int end = adjust_down(_end_y, shape[1] + tail_pad_y_available, window.y().step()) + window.y().step();
- window.set(1, Window::Dimension(window.y().start(), end, window.y().step()));
- window_modified = true;
- }
- }
-
- int front_pad_x = 0;
+ const int stride_z = _info->num_dimensions() > 2 ? strides[2] : _info->total_size();
+ const int tail_pad_y_available = (stride_z / strides[1]) - shape[1];
- const int stride_y = _info->num_dimensions() > 1 ? strides[1] : _info->total_size();
-
- // Adjust window start for X dimension
- if(_start_x < 0)
- {
- const int front_pad_x_available = -std::min<int>(static_cast<int>(offset_first_element) - front_pad_y * strides[1], stride_y - shape[0] * strides[0]) / static_cast<int>(strides[0]);
+ if(static_cast<int>(shape[1]) + tail_pad_y_available < _end_y)
+ {
+ window_modified = true;
+ }
+ }
- if(_start_x < front_pad_x_available)
+ if(!window_modified)
{
- // Not enough padding available, need to shrink the window
- const int start = adjust_up(_start_x, front_pad_x_available, window.x().step());
- window.set(0, Window::Dimension(start, window.x().end(), window.x().step()));
- window_modified = true;
+ const int stride_y = _info->num_dimensions() > 1 ? strides[1] : _info->total_size();
+
+ if(_start_x < 0)
+ {
+ const int front_pad_x_available = -std::min<int>(static_cast<int>(offset_first_element), stride_y - shape[0] * strides[0]) / static_cast<int>(strides[0]);
+
+ if(_start_x < front_pad_x_available)
+ {
+ window_modified = true;
+ }
+ }
+
+ if(!window_modified && _end_x > static_cast<int>(shape[0]))
+ {
+ const int tail_pad_x_available = (stride_y / strides[0]) - shape[0];
+
+ if(static_cast<int>(shape[0]) + tail_pad_x_available < _end_x)
+ {
+ window_modified = true;
+ }
+ }
}
-
- // Update front padding with reconstructed value
- front_pad_x = std::max(0, -window.x().start());
}
- // Adjust window end for X dimension
- if(_end_x > static_cast<int>(shape[0]))
+ // If padding is not enough
+ if(window_modified)
{
- const int tail_pad_x_available = (stride_y / strides[0]) - shape[0] - front_pad_x;
-
- if(static_cast<int>(shape[0]) + tail_pad_x_available < _end_x)
+ for(size_t i = 0; i < Coordinates::num_max_dimensions; ++i)
{
- // Not enough padding available, need to shrink the window
- const int end = adjust_down(_end_x, shape[0] + tail_pad_x_available, window.x().step()) + window.x().step();
- window.set(0, Window::Dimension(window.x().start(), end, window.x().step()));
- window_modified = true;
+ window.set(i, Window::Dimension(0, 0, 1));
}
}
- window.validate();
-
return window_modified;
}