Compute Library
 21.02
AccessWindowStatic Class Reference

Implementation of a static rectangular access pattern. More...

#include <AccessWindowStatic.h>

Collaboration diagram for AccessWindowStatic:
[legend]

Public Member Functions

 AccessWindowStatic (ITensorInfo *info, int start_x, int start_y, int end_x, int end_y)
 Constructor for a static access pattern. More...
 
 AccessWindowStatic (const AccessWindowStatic &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
AccessWindowStaticoperator= (const AccessWindowStatic &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 AccessWindowStatic (AccessWindowStatic &&)=default
 Allow instances of this class to be move constructed. More...
 
AccessWindowStaticoperator= (AccessWindowStatic &&)=default
 Allow instances of this class to be moved. More...
 
 ~AccessWindowStatic ()=default
 Default destructor. More...
 
void set_valid_region (const Window &window, const ValidRegion &input_valid_region)
 Set the valid region based on the static access pattern and valid region of the inputs. More...
 
ValidRegion compute_valid_region (const Window &window, ValidRegion input_valid_region) const
 Compute the valid region based on the static access pattern and valid region of the inputs. More...
 
bool update_window_if_needed (Window &window) const override
 Shrink the window if padding is not large enough. More...
 
bool update_padding_if_needed (const Window &window) override
 Increase the padding to be large enough for the window. More...
 
ValidRegion compute_valid_region (const Window &window, ValidRegion input_valid_region, bool border_undefined, BorderSize border_size) const override
 Compute the valid region based on access pattern and valid region of the inputs. More...
 
- Public Member Functions inherited from IAccessWindow
virtual ~IAccessWindow ()=default
 Default virtual destructor. More...
 

Detailed Description

Implementation of a static rectangular access pattern.

In this implementation the access offsets and sizes are not relative to the current element. Instead they are considered to be absolute coordinates within the accessed tensor's shape.

Definition at line 46 of file AccessWindowStatic.h.

Constructor & Destructor Documentation

◆ AccessWindowStatic() [1/3]

AccessWindowStatic ( ITensorInfo info,
int  start_x,
int  start_y,
int  end_x,
int  end_y 
)

Constructor for a static access pattern.

Parameters
[in,out]infoTensor info of the accessed kernel.
[in]start_xStart of the access in X direction.
[in]start_yStart of the access in Y direction.
[in]end_xEnd of the access in X direction.
[in]end_yEnd of the access in Y direction.

Definition at line 32 of file AccessWindowStatic.cpp.

33  : _info(info), _start_x(start_x), _start_y(start_y), _end_x(end_x), _end_y(end_y)
34 {
35 }

◆ AccessWindowStatic() [2/3]

AccessWindowStatic ( const AccessWindowStatic )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ AccessWindowStatic() [3/3]

Allow instances of this class to be move constructed.

◆ ~AccessWindowStatic()

~AccessWindowStatic ( )
default

Default destructor.

Member Function Documentation

◆ compute_valid_region() [1/2]

ValidRegion compute_valid_region ( const Window window,
ValidRegion  input_valid_region 
) const

Compute the valid region based on the static access pattern and valid region of the inputs.

Parameters
[in]windowExecution window of the kernel.
[in]input_valid_regionCombined valid region of all inputs.
Returns
a valid region.

Definition at line 45 of file AccessWindowStatic.cpp.

References ValidRegion::anchor, ARM_COMPUTE_UNUSED, ITensorInfo::num_dimensions(), Dimensions< T >::set(), TensorShape::set(), arm_compute::test::validation::shape, ValidRegion::shape, and ITensorInfo::tensor_shape().

Referenced by AccessWindowStatic::compute_valid_region(), and AccessWindowStatic::set_valid_region().

46 {
47  if(_info == nullptr)
48  {
49  return input_valid_region;
50  }
51 
52  ARM_COMPUTE_UNUSED(window);
53 
54  Coordinates &anchor = input_valid_region.anchor;
55  TensorShape &shape = input_valid_region.shape;
56 
57  // Start of the valid region is equal to the start of the static access but
58  // never outside of the tensor.
59  anchor.set(0, std::max<int>(0, _start_x));
60  if(_info->num_dimensions() > 1)
61  {
62  anchor.set(1, std::max<int>(0, _start_y));
63  }
64 
65  // End of the valid region is equal to the end of the static access but
66  // never outside of the tensor.
67  shape.set(0, std::min<int>(_end_x, _info->tensor_shape()[0]));
68  if(_info->num_dimensions() > 1)
69  {
70  shape.set(1, std::min<int>(_end_y, _info->tensor_shape()[1]));
71  }
72 
73  return input_valid_region;
74 }
void set(size_t dimension, T value, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Definition: Dimensions.h:76
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
Shape of a tensor.
Definition: TensorShape.h:39
TensorShape shape
Shape of the valid region.
Definition: Types.h:261
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Coordinates of an item.
Definition: Coordinates.h:37
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Definition: TensorShape.h:79
Coordinates anchor
Anchor for the start of the valid region.
Definition: Types.h:260

◆ compute_valid_region() [2/2]

ValidRegion compute_valid_region ( const Window window,
ValidRegion  input_valid_region,
bool  border_undefined,
BorderSize  border_size 
) const
overridevirtual

Compute the valid region based on access pattern and valid region of the inputs.

Note
This method assumes that there is no border.
Parameters
[in]windowExecution window of the kernel.
[in]input_valid_regionCombined valid region of all inputs.
[in]border_undefinedUndefined borders are excluded from the valid region.
[in]border_sizeSize of the border around the XY-plane of the tensor.
Returns
a valid region.

Implements IAccessWindow.

Definition at line 37 of file AccessWindowStatic.cpp.

References ARM_COMPUTE_UNUSED, and AccessWindowStatic::compute_valid_region().

38 {
39  ARM_COMPUTE_UNUSED(border_undefined);
40  ARM_COMPUTE_UNUSED(border_size);
41 
42  return compute_valid_region(window, input_valid_region);
43 }
ValidRegion compute_valid_region(const Window &window, ValidRegion input_valid_region) const
Compute the valid region based on the static access pattern and valid region of the inputs...
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ operator=() [1/2]

AccessWindowStatic& operator= ( const AccessWindowStatic )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ operator=() [2/2]

AccessWindowStatic& operator= ( AccessWindowStatic &&  )
default

Allow instances of this class to be moved.

◆ set_valid_region()

void set_valid_region ( const Window window,
const ValidRegion input_valid_region 
)

Set the valid region based on the static access pattern and valid region of the inputs.

Parameters
[in]windowExecution window of the kernel.
[in]input_valid_regionCombined valid region of all inputs.

Definition at line 76 of file AccessWindowStatic.cpp.

References AccessWindowStatic::compute_valid_region(), and ITensorInfo::set_valid_region().

Referenced by GCTransposeKernel::configure().

77 {
78  if(_info != nullptr)
79  {
80  _info->set_valid_region(compute_valid_region(window, input_valid_region));
81  }
82 }
ValidRegion compute_valid_region(const Window &window, ValidRegion input_valid_region) const
Compute the valid region based on the static access pattern and valid region of the inputs...
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.

◆ update_padding_if_needed()

bool update_padding_if_needed ( const Window window)
overridevirtual

Increase the padding to be large enough for the window.

Parameters
[in]windowWindow used by the kernel.
Returns
True if the padding has been changed.

Implements IAccessWindow.

Definition at line 160 of file AccessWindowStatic.cpp.

References ARM_COMPUTE_UNUSED, BorderSize::bottom, ITensorInfo::extend_padding(), ITensorInfo::is_resizable(), BorderSize::left, BorderSize::right, arm_compute::test::validation::shape, ITensorInfo::tensor_shape(), and BorderSize::top.

161 {
162  ARM_COMPUTE_UNUSED(window);
163 
164  // Only update the padding if the tensor allows it
165  if(_info == nullptr || !_info->is_resizable())
166  {
167  return false;
168  }
169 
170  const TensorShape &shape = _info->tensor_shape();
171 
172  PaddingSize padding;
173  padding.left = std::max(0, -_start_x);
174  padding.right = std::max<int>(0, _end_x - shape[0]);
175  padding.top = std::max(0, -_start_y);
176  padding.bottom = std::max<int>(0, _end_y - shape[1]);
177 
178  // Update strides in tensor info
179  return _info->extend_padding(padding);
180 }
unsigned int top
top of the border
Definition: Types.h:375
Shape of a tensor.
Definition: TensorShape.h:39
Container for 2D border size.
Definition: Types.h:273
unsigned int bottom
bottom of the border
Definition: Types.h:377
virtual bool is_resizable() const =0
Flag indicating whether the size of the tensor can be changed.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
unsigned int left
left of the border
Definition: Types.h:378
unsigned int right
right of the border
Definition: Types.h:376
virtual bool extend_padding(const PaddingSize &padding)=0
Update the offset to the first element, the strides and the total size.

◆ update_window_if_needed()

bool update_window_if_needed ( Window window) const
overridevirtual

Shrink the window if padding is not large enough.

Parameters
[in]windowWindow used by the kernel.
Returns
True if the window has been changed.

Implements IAccessWindow.

Definition at line 84 of file AccessWindowStatic.cpp.

References ITensorInfo::is_resizable(), ITensorInfo::num_dimensions(), Dimensions< int >::num_max_dimensions, ITensorInfo::offset_first_element_in_bytes(), Window::set(), arm_compute::test::validation::shape, ITensorInfo::strides_in_bytes(), ITensorInfo::tensor_shape(), and ITensorInfo::total_size().

85 {
86  // If the padding is not enough and the tensor is not resizable, shrink the window to size 0
87  if(_info == nullptr || _info->is_resizable())
88  {
89  return false;
90  }
91 
92  const TensorShape &shape = _info->tensor_shape();
93  const Strides &strides = _info->strides_in_bytes();
94  const size_t offset_first_element = _info->offset_first_element_in_bytes();
95 
96  bool window_modified = false;
97 
98  // Calculate if padding is enough
99  if(_start_y < 0)
100  {
101  const int front_pad_y_available = -static_cast<int>(offset_first_element / strides[1]);
102 
103  if(_start_y < front_pad_y_available)
104  {
105  window_modified = true;
106  }
107  }
108 
109  if(!window_modified)
110  {
111  if(_end_y > static_cast<int>(shape[1]))
112  {
113  const int stride_z = _info->num_dimensions() > 2 ? strides[2] : _info->total_size();
114  const int tail_pad_y_available = (stride_z / strides[1]) - shape[1];
115 
116  if(static_cast<int>(shape[1]) + tail_pad_y_available < _end_y)
117  {
118  window_modified = true;
119  }
120  }
121 
122  if(!window_modified)
123  {
124  const int stride_y = _info->num_dimensions() > 1 ? strides[1] : _info->total_size();
125 
126  if(_start_x < 0)
127  {
128  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]);
129 
130  if(_start_x < front_pad_x_available)
131  {
132  window_modified = true;
133  }
134  }
135 
136  if(!window_modified && _end_x > static_cast<int>(shape[0]))
137  {
138  const int tail_pad_x_available = (stride_y / strides[0]) - shape[0];
139 
140  if(static_cast<int>(shape[0]) + tail_pad_x_available < _end_x)
141  {
142  window_modified = true;
143  }
144  }
145  }
146  }
147 
148  // If padding is not enough
149  if(window_modified)
150  {
151  for(size_t i = 0; i < Coordinates::num_max_dimensions; ++i)
152  {
153  window.set(i, Window::Dimension(0, 0, 1));
154  }
155  }
156 
157  return window_modified;
158 }
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
Shape of a tensor.
Definition: TensorShape.h:39
Describe one of the image&#39;s dimensions with a start, end and step.
Definition: Window.h:77
virtual bool is_resizable() const =0
Flag indicating whether the size of the tensor can be changed.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
Strides of an item in bytes.
Definition: Strides.h:37
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 size_t total_size() const =0
Returns the total size of the tensor in bytes.
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:46

The documentation for this class was generated from the following files: