Compute Library
 21.02
CpuPooling Class Reference

Basic function to simulate a pooling layer with the specified pooling operation. More...

#include <CpuPooling.h>

Collaboration diagram for CpuPooling:
[legend]

Public Member Functions

 CpuPooling (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Constructor. More...
 
 CpuPooling (const CpuPooling &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CpuPoolingoperator= (const CpuPooling &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CpuPooling (CpuPooling &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
CpuPoolingoperator= (CpuPooling &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
 ~CpuPooling ()
 Default destructor. More...
 
void configure (ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &pool_info, ITensorInfo *indices=nullptr)
 Set the src and dst tensors. More...
 
void run (ITensorPack &tensors) override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from INEOperator
 INEOperator (IRuntimeContext *ctx=nullptr)
 Constructor. More...
 
 INEOperator (const INEOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 INEOperator (INEOperator &&)=default
 Default move constructor. More...
 
INEOperatoroperator= (const INEOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
INEOperatoroperator= (INEOperator &&)=default
 Default move assignment operator. More...
 
 ~INEOperator ()
 Default destructor. More...
 
void prepare (ITensorPack &constants) override
 Prepare the function for executing. More...
 
MemoryRequirements workspace () const override
 Return the memory requirements required by the workspace. More...
 
- Public Member Functions inherited from IOperator
virtual ~IOperator ()=default
 Destructor. 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 CpuPooling. More...
 

Detailed Description

Basic function to simulate a pooling layer with the specified pooling operation.

This function calls the following Neon kernels:

  1. NEFillBorderKernel (executed if padding size is different from zero)
  2. kernels::CpuPoolingKernel
  3. CpuPoolingAssemblyDispatch

Definition at line 49 of file CpuPooling.h.

Constructor & Destructor Documentation

◆ CpuPooling() [1/3]

CpuPooling ( std::shared_ptr< IMemoryManager memory_manager = nullptr)

Constructor.

Definition at line 36 of file CpuPooling.cpp.

References arm_compute::NCHW, and CpuPooling::~CpuPooling().

37  : _memory_manager(std::move(memory_manager)), _pooling_layer_kernel(), _border_handler(), _asm_glue(), _is_global_pooling_layer(false), _data_layout(DataLayout::NCHW)
38 {
39 }
Num samples, channels, height, width.

◆ CpuPooling() [2/3]

CpuPooling ( const CpuPooling )
delete

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

◆ CpuPooling() [3/3]

CpuPooling ( CpuPooling &&  )
delete

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ ~CpuPooling()

~CpuPooling ( )
default

Default destructor.

Referenced by CpuPooling::CpuPooling().

Member Function Documentation

◆ configure()

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

Set the src and dst tensors.

Note
F16 is supported for pool sizes 2 and 3 only
Parameters
[in,out]srcSource tensor info. (Written to only when padding != 0) 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 43 of file CpuPooling.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, arm_compute::test::validation::b, arm_compute::CONSTANT, ITensorInfo::data_layout(), PoolingLayerInfo::data_layout, ITensorInfo::data_type(), ITensorInfo::dimension(), PoolingLayerInfo::exclude_padding, Size2D::height, arm_compute::is_data_type_quantized_asymmetric(), arm_compute::MAX, arm_compute::NCHW, arm_compute::NHWC, PoolingLayerInfo::pool_size, PoolingLayerInfo::pool_type, ITensorInfo::quantization_info(), arm_compute::REPLICATE, arm_compute::UNKNOWN, CpuPoolingAssemblyDispatch::validate(), and Size2D::width.

44 {
45  // Check if we can run assembly kernels. Currently, indices are not supported by those kernels
46  const bool run_optimised = bool(CpuPoolingAssemblyDispatch::validate(input, output, pool_info)) && (indices == nullptr);
47 
48  if(run_optimised)
49  {
50  _asm_glue = std::make_unique<CpuPoolingAssemblyDispatch>(_memory_manager);
51  _asm_glue->configure(input, output, pool_info);
52  ARM_COMPUTE_ERROR_ON(!_asm_glue->is_configured());
53  }
54  else
55  {
56  // Check if we have Global Pooling Layer
57  _is_global_pooling_layer = (input->dimension(0) == pool_info.pool_size.width) && (input->dimension(1) == pool_info.pool_size.height);
58 
59  // Get data layout
60  _data_layout = pool_info.data_layout == DataLayout::UNKNOWN ? input->data_layout() : pool_info.data_layout;
61 
62  // Configure pooling kernel
63  auto k = std::make_unique<kernels::CpuPoolingKernel>();
64  k->configure(input, output, pool_info, indices);
65  _pooling_layer_kernel = std::move(k);
66 
67  switch(_data_layout)
68  {
69  case DataLayout::NCHW:
70  {
71  // Configure border depending on operation required (quantize border in case of asymmetric data_type)
72  BorderMode border_mode = (!indices && pool_info.pool_type == PoolingType::MAX) ? BorderMode::REPLICATE : BorderMode::CONSTANT;
73  PixelValue zero_value((indices) ? std::numeric_limits<int>::min() : 0.f);
74  if(is_data_type_quantized_asymmetric(input->data_type()) && !pool_info.exclude_padding)
75  {
76  zero_value = PixelValue(0, input->data_type(), input->quantization_info());
77  }
78  auto b = std::make_unique<NEFillBorderKernel>();
79  b->configure(input, _pooling_layer_kernel->border_size(), border_mode, zero_value);
80  _border_handler = std::move(b);
81  break;
82  }
83  case DataLayout::NHWC:
84  break;
85  default:
86  ARM_COMPUTE_ERROR("Data layout not supported");
87  }
88  }
89 }
BorderMode
Methods available to handle borders.
Definition: Types.h:265
SimpleTensor< float > b
Definition: DFT.cpp:157
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &info)
Indicates whether or not this function can be used to process the given parameters.
#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
Num samples, channels, height, width.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:1190
Pixels outside the image are assumed to have the same value as the closest image pixel.
Num samples, height, width, channels.

◆ operator=() [1/2]

CpuPooling& operator= ( const CpuPooling )
delete

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

◆ operator=() [2/2]

CpuPooling& operator= ( CpuPooling &&  )
delete

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ run()

void run ( ITensorPack tensors)
overridevirtual

Run the kernels contained in the function.

Parameters
[in]tensorsVector that contains the tensors to operate on.

Reimplemented from INEOperator.

Definition at line 103 of file CpuPooling.cpp.

References ARM_COMPUTE_ERROR, Window::DimX, Window::DimY, Window::DimZ, Scheduler::get(), arm_compute::NCHW, arm_compute::NHWC, and IScheduler::schedule_op().

104 {
105  if(_asm_glue && _asm_glue->is_configured())
106  {
107  _asm_glue->run(tensors);
108  }
109  else
110  {
111  switch(_data_layout)
112  {
113  case DataLayout::NCHW:
114  // Fill border
115  NEScheduler::get().schedule_op(_border_handler.get(), Window::DimY, _border_handler->window(), tensors);
116 
117  // Run pooling layer
118  NEScheduler::get().schedule_op(_pooling_layer_kernel.get(), _is_global_pooling_layer ? Window::DimZ : Window::DimY, _pooling_layer_kernel->window(), tensors);
119  break;
120  case DataLayout::NHWC:
121  // Run pooling layer
122  NEScheduler::get().schedule_op(_pooling_layer_kernel.get(), Window::DimX, _pooling_layer_kernel->window(), tensors);
123  break;
124  default:
125  ARM_COMPUTE_ERROR("Data layout not supported");
126  }
127  }
128 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
virtual void schedule_op(ICPPKernel *kernel, const Hints &hints, const Window &window, ITensorPack &tensors)=0
Runs the kernel in the same thread as the caller synchronously.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
Num samples, channels, height, width.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Num samples, height, width, channels.
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94

◆ 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 CpuPooling.

Note
F16 is supported for pool sizes 2 and 3 only
Parameters
[in]srcSource tensor info. (Written to only when padding != 0) 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) Tensor info of the indices of the maximal values. Data type supported: U32.
Returns
a status

Definition at line 91 of file CpuPooling.cpp.

References CpuPoolingKernel::validate(), and CpuPoolingAssemblyDispatch::validate().

Referenced by NEPoolingLayer::validate().

92 {
93  const bool run_optimised = bool(CpuPoolingAssemblyDispatch::validate(input, output, pool_info)) && (indices == nullptr);
94 
95  if(run_optimised)
96  {
97  return Status{};
98  }
99 
100  return kernels::CpuPoolingKernel::validate(input, output, pool_info, indices);
101 }
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &info)
Indicates whether or not this function can be used to process the given parameters.
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.

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