Compute Library
 19.11
NEPoolingLayerKernel Class Reference

Interface for the pooling layer kernel. More...

#include <NEPoolingLayerKernel.h>

Collaboration diagram for NEPoolingLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEPoolingLayerKernel ()
 Default constructor. More...
 
 NEPoolingLayerKernel (const NEPoolingLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEPoolingLayerKerneloperator= (const NEPoolingLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEPoolingLayerKernel (NEPoolingLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEPoolingLayerKerneloperator= (NEPoolingLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEPoolingLayerKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const PoolingLayerInfo &pool_info)
 Set the input and output tensors. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
BorderSize border_size () const override
 The size of the border for that kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const PoolingLayerInfo &pool_info)
 Static function to check if given info will lead to a valid configuration of NEPoolingLayerKernel. More...
 

Detailed Description

Interface for the pooling layer kernel.

Definition at line 34 of file NEPoolingLayerKernel.h.

Constructor & Destructor Documentation

◆ NEPoolingLayerKernel() [1/3]

Default constructor.

Definition at line 323 of file NEPoolingLayerKernel.cpp.

324  : _func(nullptr), _input(nullptr), _output(nullptr), _pool_info(), _num_elems_processed_per_iteration(0), _border_size(0), _is_square(false)
325 {
326 }

◆ NEPoolingLayerKernel() [2/3]

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

◆ NEPoolingLayerKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEPoolingLayerKernel()

~NEPoolingLayerKernel ( )
default

Default destructor.

Member Function Documentation

◆ border_size()

BorderSize border_size ( ) const
overridevirtual

The size of the border for that kernel.

Returns
The width in number of elements of the border.

Reimplemented from IKernel.

Definition at line 328 of file NEPoolingLayerKernel.cpp.

329 {
330  return _border_size;
331 }

Referenced by NEPoolingLayer::configure(), and NEPoolingLayerKernel::validate().

◆ configure()

void configure ( const ITensor input,
ITensor output,
const PoolingLayerInfo pool_info 
)

Set the input and output tensors.

Note
F16 are supported for pool sizes 2 and 3 only
Parameters
[in]inputSource tensor. Data types supported: QASYMM8/F16/F32.
[out]outputDestination tensor. Data types supported: Same as input.
[in]pool_infoContains pooling operation information described in PoolingLayerInfo.

Definition at line 333 of file NEPoolingLayerKernel.cpp.

334 {
336 
337  const PadStrideInfo pad_stride_info = pool_info.pad_stride_info();
338  const bool is_global_pooling = pool_info.is_global_pooling();
339  const int pool_stride_x = pad_stride_info.stride().first;
340 
341  // Get data layout
342  const DataLayout data_layout = input->info()->data_layout();
345 
346  // Update pool size in case of global pooling
347  const Size2D pool_size(
348  is_global_pooling ? input->info()->dimension(idx_width) : pool_info.pool_size().width,
349  is_global_pooling ? input->info()->dimension(idx_height) : pool_info.pool_size().height);
350 
351  // Validate pool info before calling scaled_dimensions
352  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments_pool_info(pool_size.x(), pool_size.y()));
353 
354  // Check output dimensions
355  unsigned int pooled_w;
356  unsigned int pooled_h;
357  std::tie(pooled_w, pooled_h) = scaled_dimensions(input->info()->dimension(idx_width),
358  input->info()->dimension(idx_height),
359  pool_size.x(),
360  pool_size.y(),
361  pad_stride_info);
362 
363  // Perform validation step
364  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), pool_info, pooled_w, pooled_h));
365 
366  // Set instance variables
367  _input = input;
368  _output = output;
369  _pool_info = pool_info;
370  _is_square = (pool_size.x() == pool_size.y());
371 
372  // Get data type
373  const DataType data_type = input->info()->data_type();
374  const bool is_nchw = data_layout == DataLayout::NCHW;
375 
377  {
378  if(pool_size.x() == 2 && pool_stride_x < 3 && _is_square)
379  {
380  if(is_nchw)
381  {
382  _func = &NEPoolingLayerKernel::pooling2_qasymm8_nchw;
383  }
384  else
385  {
386  _func = &NEPoolingLayerKernel::poolingMxN_qasymm8_nhwc;
387  }
388  }
389  else if(pool_size.x() == 3 && pool_stride_x < 3 && _is_square)
390  {
391  if(is_nchw)
392  {
393  _func = &NEPoolingLayerKernel::pooling3_qasymm8_nchw;
394  }
395  else
396  {
397  _func = &NEPoolingLayerKernel::poolingMxN_qasymm8_nhwc;
398  }
399  }
400  else
401  {
402  if(is_nchw)
403  {
404  _func = &NEPoolingLayerKernel::poolingMxN_qasymm8_nchw;
405  }
406  else
407  {
408  _func = &NEPoolingLayerKernel::poolingMxN_qasymm8_nhwc;
409  }
410  }
411  }
412  else if(data_type == DataType::F16)
413  {
414  if(_is_square)
415  {
416  switch(pool_size.x())
417  {
418  case 2:
419  {
420  if(is_nchw)
421  {
422  _func = &NEPoolingLayerKernel::pooling2_f16_nchw;
423  }
424  else
425  {
426  _func = &NEPoolingLayerKernel::poolingMxN_f16_nhwc;
427  }
428  }
429  break;
430  case 3:
431  {
432  if(is_nchw)
433  {
434  _func = &NEPoolingLayerKernel::pooling3_f16_nchw;
435  }
436  else
437  {
438  _func = &NEPoolingLayerKernel::poolingMxN_f16_nhwc;
439  }
440  }
441  break;
442  default:
443  {
444  if(is_nchw)
445  {
446  _func = &NEPoolingLayerKernel::poolingMxN_f16_nchw;
447  }
448  else
449  {
450  _func = &NEPoolingLayerKernel::poolingMxN_f16_nhwc;
451  }
452  break;
453  }
454  break;
455  }
456  }
457  else
458  {
459  if(is_nchw)
460  {
461  _func = &NEPoolingLayerKernel::poolingMxN_f16_nchw;
462  }
463  else
464  {
465  _func = &NEPoolingLayerKernel::poolingMxN_f16_nhwc;
466  }
467  }
468  }
469  else if(data_type == DataType::F32)
470  {
471  if(_is_square)
472  {
473  switch(pool_size.x())
474  {
475  case 2:
476  {
477  if(is_nchw)
478  {
479  _func = &NEPoolingLayerKernel::pooling2_f32_nchw;
480  }
481  else
482  {
483  _func = &NEPoolingLayerKernel::poolingMxN_f32_nhwc;
484  }
485  break;
486  }
487  case 3:
488  {
489  if(is_nchw)
490  {
491  _func = &NEPoolingLayerKernel::pooling3_f32_nchw;
492  }
493  else
494  {
495  _func = &NEPoolingLayerKernel::poolingMxN_f32_nhwc;
496  }
497  break;
498  }
499  case 7:
500  {
501  if(is_nchw)
502  {
503  _func = &NEPoolingLayerKernel::pooling7_f32_nchw;
504  }
505  else
506  {
507  _func = &NEPoolingLayerKernel::poolingMxN_f32_nhwc;
508  }
509  break;
510  }
511  default:
512  {
513  if(is_nchw)
514  {
515  _func = &NEPoolingLayerKernel::poolingMxN_f32_nchw;
516  }
517  else
518  {
519  _func = &NEPoolingLayerKernel::poolingMxN_f32_nhwc;
520  }
521  break;
522  }
523  }
524  }
525  else
526  {
527  if(is_nchw)
528  {
529  _func = &NEPoolingLayerKernel::poolingMxN_f32_nchw;
530  }
531  else
532  {
533  _func = &NEPoolingLayerKernel::poolingMxN_f32_nhwc;
534  }
535  }
536  }
537 
538  // Configure kernel window
539  auto win_config = validate_and_configure_window(input->info(), output->info(), pool_info, _num_elems_processed_per_iteration, _border_size, pooled_w, pooled_h, pool_size.x(), pool_size.y());
540  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
541  INEKernel::configure(win_config.second);
542 }
const DataLayout data_layout
Definition: Im2Col.cpp:146
std::pair< unsigned int, unsigned int > scaled_dimensions(unsigned int width, unsigned int height, unsigned int kernel_width, unsigned int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode.
Definition: Utils.cpp:402
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:93
1 channel, 1 F16 per channel
quantized, asymmetric fixed-point 8-bit number unsigned
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Definition: Types.h:733
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
Padding and stride information class.
Definition: Types.h:685
Num samples, channels, height, width.
PadStrideInfo pad_stride_info() const
Get the padding and stride.
Definition: Types.h:1276
const Size2D & pool_size() const
Get the pooling size.
Definition: Types.h:1271
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:327
DataType
Available data types.
Definition: Types.h:74
DataLayout
[DataLayout enum definition]
Definition: Types.h:116
bool is_global_pooling() const
Check if is global pooling.
Definition: Types.h:1291

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, ITensor::info(), arm_compute::test::validation::input, PoolingLayerInfo::is_global_pooling(), PoolingLayerInfo::pad_stride_info(), PoolingLayerInfo::pool_size(), arm_compute::scaled_dimensions(), PadStrideInfo::stride(), Size2D::width, and arm_compute::WIDTH.

Referenced by NEPoolingLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 37 of file NEPoolingLayerKernel.h.

38  {
39  return "NEPoolingLayerKernel";
40  }

◆ operator=() [1/2]

NEPoolingLayerKernel& operator= ( const NEPoolingLayerKernel )
delete

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

◆ operator=() [2/2]

NEPoolingLayerKernel& operator= ( NEPoolingLayerKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Implements ICPPKernel.

Definition at line 1831 of file NEPoolingLayerKernel.cpp.

1832 {
1836  ARM_COMPUTE_ERROR_ON(_func == nullptr);
1837 
1838  const unsigned int pool_stride_x = _pool_info.pad_stride_info().stride().first;
1839  const unsigned int pool_stride_y = _pool_info.pad_stride_info().stride().second;
1840  const unsigned int pool_size = _pool_info.pool_size().width;
1841  const bool exclude_padding = _pool_info.exclude_padding();
1842 
1843  Window window_input(window);
1844  if(_input->info()->data_layout() == DataLayout::NCHW)
1845  {
1846  // Set step for input in x and y direction for the input
1847  unsigned int window_x_inc = 0;
1848  switch(_input->info()->data_type())
1849  {
1850  case DataType::QASYMM8:
1851  {
1852  window_x_inc = pool_stride_x;
1853  if((pool_size == 2 || pool_size == 3) && pool_stride_x < 3)
1854  {
1855  window_x_inc = (pool_stride_x == 2) ? _num_elems_processed_per_iteration * 2 : _num_elems_processed_per_iteration;
1856  }
1857  break;
1858  }
1859 
1860  case DataType::F16:
1861  case DataType::F32:
1862  {
1863  window_x_inc = pool_stride_x;
1864  break;
1865  }
1866  default:
1867  {
1868  ARM_COMPUTE_ERROR("Not supported");
1869  }
1870  }
1871  window_input.set(Window::DimX, Window::Dimension(window.x().start() * pool_stride_x, window.x().end() * pool_stride_x, window_x_inc));
1872  window_input.set(Window::DimY, Window::Dimension(window.y().start() * pool_stride_y, window.y().end() * pool_stride_y, pool_stride_y));
1873  }
1874  else
1875  {
1876  window_input.set(Window::DimX, Window::Dimension(window.x().start(), window.x().end(), _num_elems_processed_per_iteration));
1877  window_input.set(Window::DimY, Window::Dimension(0, _input->info()->dimension(1), pool_stride_x));
1878  window_input.set(Window::DimZ, Window::Dimension(0, _input->info()->dimension(2), pool_stride_y));
1879  }
1880 
1881  // Run function
1882  (this->*_func)(window_input, window, _pool_info.pool_type(), exclude_padding);
1883 }
bool exclude_padding() const
Check if padding is excluded in calculations.
Definition: Types.h:1281
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
1 channel, 1 F16 per channel
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
quantized, asymmetric fixed-point 8-bit number unsigned
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Definition: Types.h:733
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
Num samples, channels, height, width.
PadStrideInfo pad_stride_info() const
Get the padding and stride.
Definition: Types.h:1276
const Size2D & pool_size() const
Get the pooling size.
Definition: Types.h:1271
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
PoolingType pool_type() const
Get the pooling type.
Definition: Types.h:1266
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
Definition: Window.h:152
constexpr int end() const
Return the end of the dimension.
Definition: Window.h:97
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:92
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:143

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, Window::Dimension::end(), PoolingLayerInfo::exclude_padding(), arm_compute::F16, arm_compute::F32, ITensor::info(), arm_compute::test::validation::info, arm_compute::NCHW, PoolingLayerInfo::pad_stride_info(), PoolingLayerInfo::pool_size(), PoolingLayerInfo::pool_type(), arm_compute::QASYMM8, Window::set(), Window::Dimension::start(), PadStrideInfo::stride(), Size2D::width, IKernel::window(), Window::x(), and Window::y().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const PoolingLayerInfo pool_info 
)
static

Static function to check if given info will lead to a valid configuration of NEPoolingLayerKernel.

Note
F16 are supported for pool sizes 2 and 3 only
Parameters
[in]inputSource tensor. Data types supported: QASYMM8/F16/F32.
[in]outputDestination tensor. Data types supported: Same as input.
[in]pool_infoContains pooling operation information described in PoolingLayerInfo.
Returns
a status

Definition at line 1792 of file NEPoolingLayerKernel.cpp.

1793 {
1795 
1796  unsigned int pooled_w = 0;
1797  unsigned int pooled_h = 0;
1798  unsigned int num_elems_processed_per_iteration = 0;
1800 
1801  const bool is_global_pooling = pool_info.is_global_pooling();
1802  unsigned int pool_size_x = 0;
1803  unsigned int pool_size_y = 0;
1804 
1805  // Get data layout
1806  const DataLayout data_layout = input->data_layout();
1809 
1810  pool_size_x = is_global_pooling ? input->dimension(idx_width) : pool_info.pool_size().width;
1811  pool_size_y = is_global_pooling ? input->dimension(idx_height) : pool_info.pool_size().height;
1812 
1813  // Validate pool info before calling scaled_dimensions
1814  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_pool_info(pool_size_x, pool_size_y));
1815 
1816  // Check output dimensions
1817  std::tie(pooled_w, pooled_h) = scaled_dimensions(input->dimension(idx_width),
1818  input->dimension(idx_height),
1819  pool_size_x,
1820  pool_size_y,
1821  pool_info.pad_stride_info());
1822 
1823  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, pool_info, pooled_w, pooled_h));
1824  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), pool_info, num_elems_processed_per_iteration, border_size, pooled_w, pooled_h,
1825  pool_size_x, pool_size_y)
1826  .first);
1827 
1828  return Status{};
1829 }
BorderSize border_size() const override
The size of the border for that kernel.
const DataLayout data_layout
Definition: Im2Col.cpp:146
std::pair< unsigned int, unsigned int > scaled_dimensions(unsigned int width, unsigned int height, unsigned int kernel_width, unsigned int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode.
Definition: Utils.cpp:402
Container for 2D border size.
Definition: Types.h:268
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Status class.
Definition: Error.h:52
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:93
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
PadStrideInfo pad_stride_info() const
Get the padding and stride.
Definition: Types.h:1276
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
const Size2D & pool_size() const
Get the pooling size.
Definition: Types.h:1271
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:327
DataLayout
[DataLayout enum definition]
Definition: Types.h:116
bool is_global_pooling() const
Check if is global pooling.
Definition: Types.h:1291

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, NEPoolingLayerKernel::border_size(), ICloneable< T >::clone(), arm_compute::test::validation::data_layout, arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::input, PoolingLayerInfo::is_global_pooling(), PoolingLayerInfo::pad_stride_info(), PoolingLayerInfo::pool_size(), arm_compute::scaled_dimensions(), Size2D::width, and arm_compute::WIDTH.

Referenced by NEPoolingLayer::validate().


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