23.11
|
Go to the documentation of this file.
40 bool border_undefined,
45 return input_valid_region;
52 if (!border_undefined)
62 anchor.
set(0, std::max<int>(window.
x().
start() * _scale_x, anchor[0] + border_size.
left) + _x);
65 anchor.
set(1, std::max<int>(window.
y().
start() * _scale_y, anchor[1] + border_size.
top) + _y);
76 shape.set(0, std::min<int>(old_anchor[0] +
shape[0] - border_size.
right,
77 (window.
x().
end() - window.
x().
step()) * _scale_x + _width) -
82 (window.
y().
end() - window.
y().
step()) * _scale_y + _height) -
90 anchor.
set(d, std::max(window[d].start(), input_valid_region.
anchor[d]));
91 shape.set(d, std::min<int>(window[d].
end(), input_valid_region.
shape[d]) - anchor[d]);
94 return input_valid_region;
99 bool border_undefined,
102 if (_info !=
nullptr)
129 bool window_modified =
false;
133 const int min_y = window.
y().
start() * _scale_y + _y;
134 const int max_y = (window.
y().
end() - window.
y().
step()) * _scale_y + _y + _height;
140 const int front_pad_y_available = -
static_cast<int>(offset_first_element / strides[1]);
142 if (min_y < front_pad_y_available)
145 int start =
adjust_up(min_y, front_pad_y_available, window.
y().
step() * _scale_y) - _y;
146 start = std::min<int>(start / _scale_y, window.
y().
end());
149 window_modified =
true;
153 front_pad_y = std::max(0,
static_cast<int>(std::floor(-window.
y().
start() * _scale_y)) - _y);
157 if (max_y >
static_cast<int>(
shape[1]))
162 const int tail_pad_y_available = (stride_z / strides[1]) -
shape[1] - front_pad_y;
164 if (
static_cast<int>(
shape[1]) + tail_pad_y_available < max_y)
168 window.
y().
step() * _scale_y - _y - _height;
169 end = std::max<int>(window.
y().
start(),
end / _scale_y);
172 window_modified =
true;
178 const int min_x = window.
x().
start() * _scale_x + _x;
179 const int max_x = (window.
x().
end() - window.
x().
step()) * _scale_x + _x + _width;
186 const int front_pad_x_available =
187 -std::min<int>(
static_cast<int>(offset_first_element) - front_pad_y * strides[1],
188 stride_y -
shape[0] * strides[0]) /
189 static_cast<int>(strides[0]);
191 if (min_x < front_pad_x_available)
194 int start =
adjust_up(min_x, front_pad_x_available, window.
x().
step() * _scale_x) - _x;
195 start = std::min<int>(start / _scale_x, window.
x().
end());
198 window_modified =
true;
202 front_pad_x = std::max(0,
static_cast<int>(std::floor(-window.
x().
start() * _scale_x)) - _x);
206 if (max_x >
static_cast<int>(
shape[0]))
208 const int tail_pad_x_available = (stride_y / strides[0]) -
shape[0] - front_pad_x;
210 if (
static_cast<int>(
shape[0]) + tail_pad_x_available < max_x)
214 window.
x().
step() * _scale_x - _x - _width;
215 end = std::max<int>(window.
x().
start(),
end / _scale_x);
218 window_modified =
true;
224 return window_modified;
238 PaddingSize AccessWindowRectangle::get_needed_padding(
const Window &window)
const
243 const int min_x = window.
x().
start() * _scale_x + _x;
244 const int max_x = (window.
x().
end() - window.
x().
step()) * _scale_x + _x + _width;
245 const int min_y = window.
y().
start() * _scale_y + _y;
246 const int max_y = (window.
y().
end() - window.
y().
step()) * _scale_y + _y + _height;
251 padding.
left = std::max(0, -min_x);
252 padding.
right = std::max<int>(0, max_x -
shape[0]);
253 padding.
top = std::max(0, -min_y);
254 padding.
bottom = std::max<int>(0, max_y -
shape[1]);
unsigned int right
right of the border
constexpr int start() const
Return the start of the dimension.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Container for 2D border size.
constexpr int step() const
Return the step of the dimension.
virtual bool extend_padding(const PaddingSize &padding)=0
Update the offset to the first element, the strides and the total size.
ValidRegion compute_valid_region(const Window &window, const ValidRegion &input_valid_region) const
Compute the valid region based on access pattern, valid region of the inputs and border mode.
unsigned int top
top of the border
Strides of an item in bytes.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
unsigned int bottom
bottom of the border
Container for valid region of a window.
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
void validate() const
Will validate all the window's dimensions' values when asserts are enabled.
int adjust_up(int required, int available, int step)
Increase required in steps of step until it's greater than available.
bool update_window_if_needed(Window &window) const override
Shrink the window if padding is not large enough.
Describe one of the image's dimensions with a start, end and step.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
bool update_padding_if_needed(const Window &window) override
Increase the padding to be large enough for the window.
virtual bool is_resizable() const =0
Flag indicating whether the size of the tensor can be changed.
Describe a multidimensional execution window.
TensorShape shape
Shape of the valid region.
Copyright (c) 2017-2023 Arm Limited.
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
int adjust_down(int required, int available, int step)
Decrease required in steps of step until it's less than available.
unsigned int left
left of the border
virtual size_t offset_first_element_in_bytes() const =0
The offset from the beginning of the memory allocation to the first element of the tensor.
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
void end(TokenStream &in, bool &valid)
constexpr int end() const
Return the end of the dimension.
void set_valid_region(const Window &window, const ValidRegion &input_valid_region, bool border_undefined=false, const BorderSize &border_size=BorderSize(0))
Set the valid region based on access pattern, valid region of the inputs and border mode.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
Coordinates anchor
Anchor for the start of the valid region.
virtual PaddingSize padding() const =0
Padding of tensor.