Compute Library
 21.02
CpuPoolingKernel Class Reference

Interface for the pooling layer kernel. More...

#include <CpuPoolingKernel.h>

Collaboration diagram for CpuPoolingKernel:
[legend]

Public Member Functions

 CpuPoolingKernel ()=default
 Default constructor. More...
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuPoolingKernel)
 
void configure (ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &pool_info, ITensorInfo *indices=nullptr)
 Configure kernel for a given list of arguments. More...
 
void run_op (ITensorPack &tensors, 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...
 
const char * name () const override
 Name of the kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version 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 *src, const ITensorInfo *dst, const PoolingLayerInfo &pool_info, const ITensorInfo *indices=nullptr)
 Static function to check if given info will lead to a valid configuration of CpuPoolingKernel. More...
 

Detailed Description

Interface for the pooling layer kernel.

Definition at line 38 of file CpuPoolingKernel.h.

Constructor & Destructor Documentation

◆ CpuPoolingKernel()

CpuPoolingKernel ( )
default

Default constructor.

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuPoolingKernel  )

◆ 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 380 of file CpuPoolingKernel.cpp.

381 {
382  return _border_size;
383 }

◆ configure()

void configure ( ITensorInfo src,
ITensorInfo dst,
const PoolingLayerInfo pool_info,
ITensorInfo indices = nullptr 
)

Configure kernel for a given list of arguments.

Note
F16 are supported for pool sizes 2 and 3 only
Parameters
[in]srcSource tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
[out]dstDestination tensor info. Data types supported: Same as src.
[in]pool_infoContains pooling operation information described in PoolingLayerInfo.
[out]indices(optional) The indices of the maximal values. Data type supported: U32.

Definition at line 385 of file CpuPoolingKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::calculate_max_window(), arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), PoolingLayerInfo::data_layout, ITensorInfo::dimension(), arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, PoolingLayerInfo::is_global_pooling, arm_compute::NHWC, ITensorInfo::num_dimensions(), PoolingLayerInfo::pad_stride_info, pool_size, PoolingLayerInfo::pool_size, arm_compute::scaled_dimensions(), Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), PadStrideInfo::stride(), ITensorInfo::tensor_shape(), arm_compute::UNKNOWN, arm_compute::validate_arguments(), Size2D::width, and arm_compute::WIDTH.

386 {
388  const PadStrideInfo pad_stride_info = pool_info.pad_stride_info;
389  const bool is_global_pooling = pool_info.is_global_pooling;
390 
391  // Get data layout
392  const auto data_layout = pool_info.data_layout == DataLayout::UNKNOWN ? src->data_layout() : pool_info.data_layout;
395 
396  // Update pool size in case of global pooling
397  const Size2D pool_size(
398  is_global_pooling ? src->dimension(idx_width) : pool_info.pool_size.width,
399  is_global_pooling ? src->dimension(idx_height) : pool_info.pool_size.height);
400 
401  // Validate pool info before calling scaled_dimensions
402  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments_pool_info(pool_size.x(), pool_size.y()));
403 
404  // Check dst dimensions
405  unsigned int pooled_w;
406  unsigned int pooled_h;
407  std::tie(pooled_w, pooled_h) = scaled_dimensions(src->dimension(idx_width),
408  src->dimension(idx_height),
409  pool_size.x(),
410  pool_size.y(),
411  pad_stride_info);
412 
413  // Perform validation step
414  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst, pool_info, pooled_w, pooled_h, indices, pool_size));
415 
416  // Set instance variables
417  _pool_info = pool_info;
418  _data_layout = src->data_layout();
419  _pool_size = pool_size;
420  _pool_stride_x = pad_stride_info.stride().first;
421 
422  if(_data_layout == DataLayout::NHWC)
423  {
424  // Configure kernel window
425  Window win = calculate_max_window(*dst, Steps());
426  Coordinates coord;
427  coord.set_num_dimensions(dst->num_dimensions());
428  dst->set_valid_region(ValidRegion(coord, dst->tensor_shape()));
429  ICpuKernel::configure(win);
430  }
431  else
432  {
433  // Configure kernel window
434  auto win_config = validate_and_configure_window(src, dst, indices, pool_info, _num_elems_processed_per_iteration,
435  _border_size, pooled_w, pooled_h, pool_size.x(), pool_size.y());
436  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
437  ICpuKernel::configure(win_config.second);
438  }
439 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
const DataLayout data_layout
Definition: Im2Col.cpp:151
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
SimpleTensor< float > src
Definition: DFT.cpp:155
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, 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:419
Num samples, height, width, channels.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
Size2D pool_size
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
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:193

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 540 of file CpuPoolingKernel.cpp.

541 {
542  return "CpuPoolingKernel";
543 }

◆ run_op()

void run_op ( ITensorPack tensors,
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]tensorsA vector containing the tensors to operate on.
[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.

Reimplemented from ICPPKernel.

Definition at line 481 of file CpuPoolingKernel.cpp.

References arm_compute::ACL_DST_0, arm_compute::ACL_DST_1, arm_compute::ACL_SRC_0, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, arm_compute::test::validation::dst, Window::Dimension::end(), arm_compute::F16, arm_compute::F32, ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), ITensor::info(), arm_compute::NCHW, pool_size, pool_stride_x, arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, Window::set(), arm_compute::test::validation::src, Window::Dimension::start(), IKernel::window(), Window::x(), and Window::y().

482 {
486 
487  const ITensor *src = tensors.get_const_tensor(TensorType::ACL_SRC_0);
488  ITensor *dst = tensors.get_tensor(TensorType::ACL_DST_0);
489  ITensor *indices = tensors.get_tensor(TensorType::ACL_DST_1);
490 
491  const unsigned int pool_stride_x = _pool_info.pad_stride_info.stride().first;
492  const unsigned int pool_stride_y = _pool_info.pad_stride_info.stride().second;
493  const unsigned int pool_size = _pool_info.pool_size.width;
494 
495  Window window_src(window);
496  if(_data_layout == DataLayout::NCHW)
497  {
498  // Set step for src in x and y direction for the src
499  unsigned int window_x_inc = 0;
500  switch(src->info()->data_type())
501  {
502  case DataType::QASYMM8:
504  {
505  window_x_inc = pool_stride_x;
506  if((pool_size == 2 || pool_size == 3) && pool_stride_x < 3)
507  {
508  window_x_inc = (pool_stride_x == 2) ? _num_elems_processed_per_iteration * 2 : _num_elems_processed_per_iteration;
509  }
510  break;
511  }
512 
513  case DataType::F16:
514  case DataType::F32:
515  {
516  window_x_inc = pool_stride_x;
517  break;
518  }
519  default:
520  {
521  ARM_COMPUTE_ERROR("Not supported");
522  }
523  }
524  window_src.set(Window::DimX, Window::Dimension(window.x().start() * pool_stride_x, window.x().end() * pool_stride_x, window_x_inc));
525  window_src.set(Window::DimY, Window::Dimension(window.y().start() * pool_stride_y, window.y().end() * pool_stride_y, pool_stride_y));
526  }
527  else
528  {
529  window_src.set(Window::DimX, Window::Dimension(0, 1, 1));
530  window_src.set(Window::DimY, Window::Dimension(0, src->info()->dimension(1), pool_stride_x));
531  window_src.set(Window::DimZ, Window::Dimension(0, src->info()->dimension(2), pool_stride_y));
532  }
533 
534  const auto *uk = get_implementation(src->info()->data_type(), _data_layout, _pool_stride_x, _pool_size);
535  ARM_COMPUTE_ERROR_ON(uk == nullptr || uk->ukernel == nullptr);
536 
537  uk->ukernel(src, dst, indices, _pool_info, window_src, window);
538 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
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
SimpleTensor< float > src
Definition: DFT.cpp:155
int pool_stride_x
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:770
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
Num samples, channels, height, width.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
PadStrideInfo pad_stride_info
Definition: Types.h:1302
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:89
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
Definition: Window.h:154
Size2D pool_size
quantized, asymmetric fixed-point 8-bit number signed
constexpr int end() const
Return the end of the dimension.
Definition: Window.h:99
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:94
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo dst,
const PoolingLayerInfo pool_info,
const ITensorInfo indices = nullptr 
)
static

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

Note
F16 are supported for pool sizes 2 and 3 only
Parameters
[in]srcSource tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
[in]dstDestination tensor info. Data types supported: Same as src.
[in]pool_infoContains pooling operation information described in PoolingLayerInfo.
[in]indices(optional) The indices of the maximal values. Data type supported: U32.
Returns
a status

Definition at line 441 of file CpuPoolingKernel.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), PoolingLayerInfo::data_layout, ITensorInfo::dimension(), arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, PoolingLayerInfo::is_global_pooling, num_elems_processed_per_iteration, PoolingLayerInfo::pad_stride_info, PoolingLayerInfo::pool_size, arm_compute::scaled_dimensions(), arm_compute::UNKNOWN, arm_compute::validate_arguments(), Size2D::width, and arm_compute::WIDTH.

Referenced by CpuPooling::validate().

442 {
444 
445  unsigned int pooled_w = 0;
446  unsigned int pooled_h = 0;
447  unsigned int num_elems_processed_per_iteration = 0;
448  BorderSize border_size(0);
449 
450  const bool is_global_pooling = pool_info.is_global_pooling;
451  unsigned int pool_size_x = 0;
452  unsigned int pool_size_y = 0;
453 
454  // Get data layout
455  const auto data_layout = pool_info.data_layout == DataLayout::UNKNOWN ? src->data_layout() : pool_info.data_layout;
458 
459  pool_size_x = is_global_pooling ? src->dimension(idx_width) : pool_info.pool_size.width;
460  pool_size_y = is_global_pooling ? src->dimension(idx_height) : pool_info.pool_size.height;
461 
462  // Validate pool info before calling scaled_dimensions
463  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_pool_info(pool_size_x, pool_size_y));
464 
465  // Check dst dimensions
466  std::tie(pooled_w, pooled_h) = scaled_dimensions(src->dimension(idx_width),
467  src->dimension(idx_height),
468  pool_size_x,
469  pool_size_y,
470  pool_info.pad_stride_info);
471 
472  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, dst, pool_info, pooled_w, pooled_h, indices, Size2D(pool_size_x, pool_size_y)));
473  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(src->clone().get(), dst->clone().get(),
474  (indices) ? indices->clone().get() : nullptr, pool_info, num_elems_processed_per_iteration, border_size, pooled_w, pooled_h,
475  pool_size_x, pool_size_y)
476  .first);
477 
478  return Status{};
479 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
const DataLayout data_layout
Definition: Im2Col.cpp:151
SimpleTensor< float > src
Definition: DFT.cpp:155
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, 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:419
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
BorderSize border_size() const override
The size of the border for that kernel.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
unsigned int num_elems_processed_per_iteration
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:193

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