Compute Library
 23.05
CpuPool2d Class Reference

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

#include <CpuPool2d.h>

Collaboration diagram for CpuPool2d:
[legend]

Public Member Functions

 CpuPool2d ()
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuPool2d)
 
 ~CpuPool2d ()
 
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...
 
experimental::MemoryRequirements workspace () const override
 Return the memory requirements required by the workspace. 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...
 
- 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. More...
 

Detailed Description

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

This function calls the following kernels:

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

Definition at line 46 of file CpuPool2d.h.

Constructor & Destructor Documentation

◆ CpuPool2d()

CpuPool2d ( )

Definition at line 39 of file CpuPool2d.cpp.

References arm_compute::NCHW.

40  : _pooling_layer_kernel(),
41  _asm_glue(),
42  _is_global_pooling_layer(false),
43  _use_kernel_indices(false),
44  _data_layout(DataLayout::NCHW),
45  _aux_mem(1)
46 {
47 }
Num samples, channels, height, width.

◆ ~CpuPool2d()

~CpuPool2d ( )
default

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuPool2d  )

◆ 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 51 of file CpuPool2d.cpp.

References arm_compute::ACL_INT_0, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_LOG_PARAMS, ci, IScheduler::cpu_info(), ITensorInfo::data_layout(), PoolingLayerInfo::data_layout, ITensorInfo::dimension(), Scheduler::get(), arm_compute::get_data_layout_dimension_index(), Size2D::height, arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, arm_compute::test::validation::k, IScheduler::num_threads(), PoolingLayerInfo::pool_size, arm_compute::UNKNOWN, PoolingLayerInfo::use_kernel_indices, CpuPool2dAssemblyWrapperKernel::validate(), Size2D::width, and arm_compute::WIDTH.

52 {
53  ARM_COMPUTE_LOG_PARAMS(src, dst, pool_info, indices);
54 
55  // Check if we can run assembly kernels. Currently, indices are not supported by those kernels
56  const bool run_optimised = bool(kernels::CpuPool2dAssemblyWrapperKernel::validate(src, dst, pool_info)) && (indices == nullptr);
57 
58  // Get data layout
59  _data_layout = pool_info.data_layout == DataLayout::UNKNOWN ? src->data_layout() : pool_info.data_layout;
60 
61  // Check if we have Global Pooling Layer
62  const unsigned int idx_width = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH);
64  _is_global_pooling_layer = (src->dimension(idx_width) == pool_info.pool_size.width) && (src->dimension(idx_height) == pool_info.pool_size.height);
65  _use_kernel_indices = pool_info.use_kernel_indices;
66 
67  if(run_optimised)
68  {
69  const CPUInfo &ci = NEScheduler::get().cpu_info();
70  const unsigned int num_threads = NEScheduler::get().num_threads();
71 
72  auto pooling_wrapper = std::make_unique<kernels::CpuPool2dAssemblyWrapperKernel>();
73  ARM_COMPUTE_ERROR_ON(pooling_wrapper == nullptr);
74  pooling_wrapper->configure(src, dst, pool_info, ci);
75 
76  // Get kernel's memory requirements
77  constexpr size_t alignment = 4096;
78  const size_t workspace_size = pooling_wrapper->get_working_size(num_threads);
79  _aux_mem[0] = MemoryInfo(TensorType::ACL_INT_0, MemoryLifetime::Temporary, workspace_size, alignment);
80 
81  _asm_glue = std::move(pooling_wrapper);
82  }
83  else
84  {
85  // Configure pooling kernel
86  auto k = std::make_unique<kernels::CpuPool2dKernel>();
87  k->configure(src, dst, pool_info, indices);
88  _pooling_layer_kernel = std::move(k);
89  }
90 }
#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
CPUInfo & cpu_info()
Get CPU info.
Definition: IScheduler.cpp:41
SimpleTensor< float > src
Definition: DFT.cpp:155
const CPUInfo & ci
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:203
#define ARM_COMPUTE_LOG_PARAMS(...)
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &info)
Static function to check if given info will lead to a valid configuration.
virtual unsigned int num_threads() const =0
Returns the number of threads that the SingleThreadScheduler has in its pool.
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94

◆ 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 104 of file CpuPool2d.cpp.

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

105 {
106  ARM_COMPUTE_ERROR_ON_MSG(tensors.empty(), "No tensors provided");
107 
108  if(_asm_glue)
109  {
110  const auto hints = (_is_global_pooling_layer) ? Window::DimX : Window::DimY;
111  NEScheduler::get().schedule_op(_asm_glue.get(), hints, _asm_glue->window(), tensors);
112  }
113  else
114  {
115  switch(_data_layout)
116  {
117  case DataLayout::NCHW:
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  NEScheduler::get().schedule_op(_pooling_layer_kernel.get(), (_use_kernel_indices ? Window::DimY : Window::DimX), _pooling_layer_kernel->window(), tensors);
122  break;
123  default:
124  ARM_COMPUTE_ERROR("Data layout not supported");
125  }
126  }
127 }
#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
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
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.

Similar to CpuPool2d::configure()

Returns
a status

Definition at line 92 of file CpuPool2d.cpp.

References CpuPool2dKernel::validate(), and CpuPool2dAssemblyWrapperKernel::validate().

Referenced by NEPoolingLayer::validate().

93 {
94  const bool run_optimised = bool(kernels::CpuPool2dAssemblyWrapperKernel::validate(src, dst, pool_info)) && (indices == nullptr);
95 
96  if(run_optimised)
97  {
98  return Status{};
99  }
100 
101  return kernels::CpuPool2dKernel::validate(src, dst, pool_info, indices);
102 }
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.
SimpleTensor< float > src
Definition: DFT.cpp:155
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &info)
Static function to check if given info will lead to a valid configuration.

◆ workspace()

experimental::MemoryRequirements workspace ( ) const
overridevirtual

Return the memory requirements required by the workspace.

Reimplemented from INEOperator.

Definition at line 129 of file CpuPool2d.cpp.

130 {
131  return _aux_mem;
132 }

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