Compute Library
 21.08
CpuPool2dKernel Class Reference

Interface for the pooling layer kernel. More...

#include <CpuPool2dKernel.h>

Collaboration diagram for CpuPool2dKernel:
[legend]

Public Member Functions

 CpuPool2dKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuPool2dKernel)
 
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...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. 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. More...
 

Detailed Description

Interface for the pooling layer kernel.

Definition at line 38 of file CpuPool2dKernel.h.

Constructor & Destructor Documentation

◆ CpuPool2dKernel()

CpuPool2dKernel ( )
default

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuPool2dKernel  )

◆ 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 377 of file CpuPool2dKernel.cpp.

378 {
379  return _border_size;
380 }

◆ 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 382 of file CpuPool2dKernel.cpp.

References ARM_COMPUTE_ERROR_ON, 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::data_type(), 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, PoolingLayerInfo::pad_stride_info, pool_size, PoolingLayerInfo::pool_size, PadStrideInfo::stride(), arm_compute::UNKNOWN, Size2D::width, and arm_compute::WIDTH.

383 {
385  const PadStrideInfo pad_stride_info = pool_info.pad_stride_info;
386  const bool is_global_pooling = pool_info.is_global_pooling;
387 
388  // Get data layout
389  const auto data_layout = pool_info.data_layout == DataLayout::UNKNOWN ? src->data_layout() : pool_info.data_layout;
392 
393  // Update pool size in case of global pooling
394  const Size2D pool_size(
395  is_global_pooling ? src->dimension(idx_width) : pool_info.pool_size.width,
396  is_global_pooling ? src->dimension(idx_height) : pool_info.pool_size.height);
397 
398  // Perform validation step
399  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst, pool_info, indices, pool_size));
400 
401  const auto *uk = get_implementation(src->data_type(), src->data_layout(), pad_stride_info.stride().first, pool_size);
402  ARM_COMPUTE_ERROR_ON(uk == nullptr);
403 
404  // Set instance variables
405  _pool_info = pool_info;
406  _data_layout = src->data_layout();
407  _pool_size = pool_size;
408  _pool_stride_x = pad_stride_info.stride().first;
409  _run_method = uk->ukernel;
410  _name = std::string("CpuPool2dKernel").append("/").append(uk->name);
411 
412  if(_data_layout == DataLayout::NHWC)
413  {
414  // Configure kernel window
415  Window win = calculate_max_window(*dst, Steps());
416  ICpuKernel::configure(win);
417  }
418  else
419  {
420  // Configure kernel window
421  auto win_config = validate_and_configure_window(src, dst, indices, pool_info, _num_elems_processed_per_iteration,
422  _border_size, pool_size.x(), pool_size.y());
423  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
424  ICpuKernel::configure(win_config.second);
425  }
426 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#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
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
Size2D pool_size
Num samples, height, width, channels.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
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 510 of file CpuPool2dKernel.cpp.

511 {
512  return _name.c_str();
513 }

◆ 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 454 of file CpuPool2dKernel.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().

455 {
459  ARM_COMPUTE_ERROR_ON(_run_method == nullptr);
460 
461  const ITensor *src = tensors.get_const_tensor(TensorType::ACL_SRC_0);
462  ITensor *dst = tensors.get_tensor(TensorType::ACL_DST_0);
463  ITensor *indices = tensors.get_tensor(TensorType::ACL_DST_1);
464 
465  const unsigned int pool_stride_x = _pool_info.pad_stride_info.stride().first;
466  const unsigned int pool_stride_y = _pool_info.pad_stride_info.stride().second;
467  const unsigned int pool_size = _pool_info.pool_size.width;
468 
469  Window window_src(window);
470  if(_data_layout == DataLayout::NCHW)
471  {
472  // Set step for src in x and y direction for the src
473  unsigned int window_x_inc = 0;
474  switch(src->info()->data_type())
475  {
476  case DataType::QASYMM8:
478  {
479  window_x_inc = pool_stride_x;
480  if((pool_size == 2 || pool_size == 3) && pool_stride_x < 3)
481  {
482  window_x_inc = (pool_stride_x == 2) ? _num_elems_processed_per_iteration * 2 : _num_elems_processed_per_iteration;
483  }
484  break;
485  }
486 
487  case DataType::F16:
488  case DataType::F32:
489  {
490  window_x_inc = pool_stride_x;
491  break;
492  }
493  default:
494  {
495  ARM_COMPUTE_ERROR("Not supported");
496  }
497  }
498  window_src.set(Window::DimX, Window::Dimension(window.x().start() * pool_stride_x, window.x().end() * pool_stride_x, window_x_inc));
499  window_src.set(Window::DimY, Window::Dimension(window.y().start() * pool_stride_y, window.y().end() * pool_stride_y, pool_stride_y));
500  }
501  else
502  {
503  window_src.set(Window::DimX, Window::Dimension(0, 1, 1));
504  window_src.set(Window::DimY, Window::Dimension(0, src->info()->dimension(1), pool_stride_x));
505  window_src.set(Window::DimZ, Window::Dimension(0, src->info()->dimension(2), pool_stride_y));
506  }
507  _run_method(src, dst, indices, _pool_info, window_src, window);
508 }
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
1 channel, 1 F16 per channel
Size2D pool_size
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:695
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
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:1227
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
int pool_stride_x
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
Definition: Window.h:154
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:201
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.

Similar to CpuPool2dKernel::configure()

Returns
a status

Definition at line 428 of file CpuPool2dKernel.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::pool_size, arm_compute::UNKNOWN, Size2D::width, and arm_compute::WIDTH.

Referenced by CpuPool2d::validate().

429 {
431 
432  unsigned int num_elems_processed_per_iteration = 0;
433  BorderSize border_size(0);
434 
435  const bool is_global_pooling = pool_info.is_global_pooling;
436 
437  // Get data layout
438  const auto data_layout = pool_info.data_layout == DataLayout::UNKNOWN ? src->data_layout() : pool_info.data_layout;
441 
442  unsigned int pool_size_x = is_global_pooling ? src->dimension(idx_width) : pool_info.pool_size.width;
443  unsigned int pool_size_y = is_global_pooling ? src->dimension(idx_height) : pool_info.pool_size.height;
444 
445  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, dst, pool_info, indices, Size2D(pool_size_x, pool_size_y)));
446  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(src->clone().get(), dst->clone().get(),
447  (indices) ? indices->clone().get() : nullptr, pool_info, num_elems_processed_per_iteration, border_size,
448  pool_size_x, pool_size_y)
449  .first);
450 
451  return Status{};
452 }
BorderSize border_size() const override
The size of the border for that kernel.
#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
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
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: