Compute Library
 19.08
IAccessWindow.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2018 ARM Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #ifndef __ARM_COMPUTE_IACCESS_WINDOW_H__
25 #define __ARM_COMPUTE_IACCESS_WINDOW_H__
26 
29 #include "arm_compute/core/Types.h"
30 
31 #include <array>
32 
33 namespace arm_compute
34 {
35 class Window;
36 class ITensorInfo;
37 
47 inline int adjust_down(int required, int available, int step)
48 {
50 
51  return required - step * ((required - available + step - 1) / step);
52 }
53 
63 inline int adjust_up(int required, int available, int step)
64 {
66 
67  return required + step * ((available - required + step - 1) / step);
68 }
69 
72 {
73 public:
75  virtual ~IAccessWindow() = default;
83  virtual bool update_window_if_needed(Window &window) const = 0;
90  virtual bool update_padding_if_needed(const Window &window) = 0;
103  virtual ValidRegion compute_valid_region(const Window &window, ValidRegion input_valid_region, bool border_undefined, BorderSize border_size) const = 0;
104 };
105 
108 {
109 public:
120  AccessWindowRectangle(ITensorInfo *info, int x, int y, int width, int height)
121  : AccessWindowRectangle(info, x, y, width, height, 1.f, 1.f)
122  {
123  }
124 
137  AccessWindowRectangle(ITensorInfo *info, int x, int y, int width, int height, float scale_x, float scale_y)
138  : _info(info), _x(x), _y(y), _width(width), _height(height), _scale_x(scale_x), _scale_y(scale_y)
139  {
140  ARM_COMPUTE_ERROR_ON(width < 0);
141  ARM_COMPUTE_ERROR_ON(height < 0);
142  ARM_COMPUTE_ERROR_ON(scale_x < 0);
143  ARM_COMPUTE_ERROR_ON(scale_y < 0);
144  }
145 
155  ~AccessWindowRectangle() = default;
156 
164  void set_valid_region(const Window &window, const ValidRegion &input_valid_region, bool border_undefined = false, const BorderSize &border_size = BorderSize(0));
165 
176  ValidRegion compute_valid_region(const Window &window, const ValidRegion &input_valid_region) const;
177 
178  // Inherited methods overridden:
179 
192  ValidRegion compute_valid_region(const Window &window, ValidRegion input_valid_region, bool border_undefined, BorderSize border_size) const override;
193 
194  bool update_window_if_needed(Window &window) const override;
195  bool update_padding_if_needed(const Window &window) override;
196 protected:
197  PaddingSize get_needed_padding(const Window &window)const;
198 
199 protected:
200  ITensorInfo *_info;
201  int _x;
202  int _y;
203  int _width;
204  int _height;
205  float _scale_x;
206  float _scale_y;
207 };
208 
211 {
212 public:
222  AccessWindowVertical(ITensorInfo *info, int y, int height, float scale_y = 1.f)
223  : AccessWindowRectangle(info, 0, y, 1, height, 1.f, scale_y)
224  {
225  ARM_COMPUTE_ERROR_ON(height < 0);
226  ARM_COMPUTE_ERROR_ON(scale_y < 0);
227  }
228 };
229 
232 {
233 public:
243  AccessWindowHorizontal(ITensorInfo *info, int x, int width, float scale_x = 1.f)
244  : AccessWindowRectangle(info, x, 0, width, 1, scale_x, 1.f)
245  {
246  ARM_COMPUTE_ERROR_ON(width < 0);
247  ARM_COMPUTE_ERROR_ON(scale_x < 0);
248  }
249 };
250 } // namespace arm_compute
251 #endif /*__ARM_COMPUTE_IACCESS_WINDOW_H__*/
Implementation of a column access pattern.
Container for 2D border size.
Definition: Types.h:259
~AccessWindowRectangle()=default
Default destructor.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
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.
Store the tensor's metadata.
Definition: ITensorInfo.h:40
virtual bool update_padding_if_needed(const Window &window)=0
Increase the padding to be large enough for the window.
virtual ~IAccessWindow()=default
Default virtual destructor.
Copyright (c) 2017-2018 ARM Limited.
virtual ValidRegion compute_valid_region(const Window &window, ValidRegion input_valid_region, bool border_undefined, BorderSize border_size) const =0
Compute the valid region based on access pattern and valid region of the inputs.
virtual bool update_window_if_needed(Window &window) const =0
Shrink the window if padding is not large enough.
AccessWindowHorizontal(ITensorInfo *info, int x, int width, float scale_x=1.f)
Constructor for a row access pattern.
Implementation of a rectangular access pattern.
AccessWindowRectangle(ITensorInfo *info, int x, int y, int width, int height, float scale_x, float scale_y)
Constructor for a rectangular access pattern.
int adjust_up(int required, int available, int step)
Increase required in steps of step until it's greater than available.
Definition: IAccessWindow.h:63
Interface describing methods to update access window and padding based on kernel parameters.
Definition: IAccessWindow.h:71
Implementation of a row access pattern.
bool update_window_if_needed(Window &window) const override
Shrink the window if padding is not large enough.
AccessWindowVertical(ITensorInfo *info, int y, int height, float scale_y=1.f)
Constructor for a column access pattern.
AccessWindowRectangle & operator=(const AccessWindowRectangle &)=delete
Prevent instances of this class from being copied (As this class contains pointers)
bool update_padding_if_needed(const Window &window) override
Increase the padding to be large enough for the window.
Container for valid region of a window.
Definition: Types.h:174
AccessWindowRectangle(ITensorInfo *info, int x, int y, int width, int height)
Constructor for a rectangular access pattern.
int adjust_down(int required, int available, int step)
Decrease required in steps of step until it's less than available.
Definition: IAccessWindow.h:47
Describe a multidimensional execution window.
Definition: Window.h:39
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.