Compute Library
 21.08
PaddingCalculator Class Referencefinal

Calculate required padding. More...

#include <PaddingCalculator.h>

Public Types

enum  Option { EXCLUDE_BORDER, INCLUDE_BORDER }
 Options for computing the padding. More...
 

Public Member Functions

 PaddingCalculator (int size, int processed_elements)
 Construct calculator with size of tensor's dimension and step size. More...
 
void set_border_mode (BorderMode mode)
 Set border mode. More...
 
void set_border_size (int size)
 Set border size. More...
 
void set_access_offset (int offset)
 Set offset of the access relative to the current position. More...
 
void set_processed_elements (int elements)
 Set number of processed elements. More...
 
void set_accessed_elements (int elements)
 Set number of accessed elements. More...
 
PaddingSize required_padding () const
 Compute the required padding. More...
 
PaddingSize required_padding (Option option) const
 Compute the required padding. More...
 

Detailed Description

Calculate required padding.

Definition at line 36 of file PaddingCalculator.h.

Member Enumeration Documentation

◆ Option

enum Option
strong

Options for computing the padding.

Enumerator
EXCLUDE_BORDER 
INCLUDE_BORDER 

Definition at line 40 of file PaddingCalculator.h.

41  {
42  EXCLUDE_BORDER,
43  INCLUDE_BORDER
44  };

Constructor & Destructor Documentation

◆ PaddingCalculator()

PaddingCalculator ( int  size,
int  processed_elements 
)
inline

Construct calculator with size of tensor's dimension and step size.

Parameters
[in]sizeNumber of elements available.
[in]processed_elementsNumber of elements processed per iteration.

Definition at line 51 of file PaddingCalculator.h.

References clang_tidy_rules::mode, offset(), PaddingCalculator::required_padding(), PaddingCalculator::set_access_offset(), PaddingCalculator::set_accessed_elements(), PaddingCalculator::set_border_mode(), PaddingCalculator::set_border_size(), PaddingCalculator::set_processed_elements(), and arm_compute::UNDEFINED.

52  : _size{ size }, _num_processed_elements{ processed_elements }, _num_accessed_elements{ processed_elements }
53  {
54  }

Member Function Documentation

◆ required_padding() [1/2]

PaddingSize required_padding ( ) const
inline

Compute the required padding.

If access offset is negative and border mode is not undefined, the top, bottom and left padding is set to boder size. Otherwise it is zero. The right padding is always computed based on the specified parameters.

Returns
Required padding in number of elements.

Definition at line 141 of file PaddingCalculator.h.

References PaddingCalculator::EXCLUDE_BORDER, and PaddingCalculator::INCLUDE_BORDER.

Referenced by PaddingCalculator::PaddingCalculator().

◆ required_padding() [2/2]

PaddingSize required_padding ( Option  option) const
inline

Compute the required padding.

If option is INCLUDE_BORDER and border mode is not undefined, the top, bottom and left padding is set to boder size. Otherwise it is zero. The right padding is always computed based on the specified parameters.

Parameters
[in]optionPadding option
Returns
Required padding in number of elements.

Definition at line 146 of file PaddingCalculator.h.

References PaddingCalculator::EXCLUDE_BORDER, arm_compute::utils::cast::U, and arm_compute::UNDEFINED.

147 {
148  PaddingSize padding{ (_mode == BorderMode::UNDEFINED || option == Option::EXCLUDE_BORDER) ? 0U : static_cast<unsigned int>(std::max(0, _border_size)) };
149 
150  int padding_right = 0;
151 
152  if(_mode == BorderMode::UNDEFINED)
153  {
154  padding_right = (((_size - 2 * _border_size + _num_processed_elements - 1) / _num_processed_elements) - 1) * _num_processed_elements + _num_accessed_elements - _size + _border_size + _offset;
155  }
156  else
157  {
158  padding_right = (((_size + _num_processed_elements - 1) / _num_processed_elements) - 1) * _num_processed_elements + _num_accessed_elements - _size + _offset;
159  }
160 
161  padding.right = std::max(0, padding_right);
162 
163  return padding;
164 }
BorderSize PaddingSize
Container for 2D padding size.
Definition: Types.h:379
unsigned int right
right of the border
Definition: Types.h:373
Borders are left undefined.

◆ set_access_offset()

void set_access_offset ( int  offset)
inline

Set offset of the access relative to the current position.

Parameters
[in]offsetOffset of the access.

Definition at line 127 of file PaddingCalculator.h.

References offset().

Referenced by PaddingCalculator::PaddingCalculator().

128 {
129  _offset = offset;
130 }
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:861

◆ set_accessed_elements()

void set_accessed_elements ( int  elements)
inline

Set number of accessed elements.

Parameters
[in]elementsNumber of accessed elements per iteration.

Definition at line 136 of file PaddingCalculator.h.

Referenced by PaddingCalculator::PaddingCalculator().

137 {
138  _num_accessed_elements = elements;
139 }

◆ set_border_mode()

void set_border_mode ( BorderMode  mode)
inline

Set border mode.

Parameters
[in]modeBorder mode.

Definition at line 117 of file PaddingCalculator.h.

References clang_tidy_rules::mode.

Referenced by PaddingCalculator::PaddingCalculator().

118 {
119  _mode = mode;
120 }

◆ set_border_size()

void set_border_size ( int  size)
inline

Set border size.

Parameters
[in]sizeBorder size in elements.

Definition at line 122 of file PaddingCalculator.h.

Referenced by PaddingCalculator::PaddingCalculator().

123 {
124  _border_size = size;
125 }

◆ set_processed_elements()

void set_processed_elements ( int  elements)
inline

Set number of processed elements.

Parameters
[in]elementsNumber of processed elements per iteration.

Definition at line 132 of file PaddingCalculator.h.

Referenced by PaddingCalculator::PaddingCalculator().

133 {
134  _num_processed_elements = elements;
135 }

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