Compute Library
 22.08
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 40 of file CpuPool2d.cpp.

References arm_compute::NCHW.

41  : _pooling_layer_kernel(),
42  _asm_glue(),
43  _is_global_pooling_layer(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, 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 
66  if(run_optimised)
67  {
68  const CPUInfo &ci = NEScheduler::get().cpu_info();
69  const unsigned int num_threads = NEScheduler::get().num_threads();
70 
71  auto pooling_wrapper = std::make_unique<kernels::CpuPool2dAssemblyWrapperKernel>();
72  ARM_COMPUTE_ERROR_ON(pooling_wrapper == nullptr);
73  pooling_wrapper->configure(src, dst, pool_info, ci);
74 
75  // Get kernel's memory requirements
76  constexpr size_t alignment = 4096;
77  const size_t workspace_size = pooling_wrapper->get_working_size(num_threads);
78  _aux_mem[0] = MemoryInfo(TensorType::ACL_INT_0, MemoryLifetime::Temporary, workspace_size, alignment);
79 
80  _asm_glue = std::move(pooling_wrapper);
81  }
82  else
83  {
84  // Configure pooling kernel
85  auto k = std::make_unique<kernels::CpuPool2dKernel>();
86  k->configure(src, dst, pool_info, indices);
87  _pooling_layer_kernel = std::move(k);
88  }
89 }
#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:193
#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 103 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().

104 {
105  ARM_COMPUTE_ERROR_ON_MSG(tensors.empty(), "No tensors provided");
106 
107  if(_asm_glue)
108  {
109  const auto hints = (_is_global_pooling_layer) ? Window::DimX : Window::DimY;
110  NEScheduler::get().schedule_op(_asm_glue.get(), hints, _asm_glue->window(), tensors);
111  }
112  else
113  {
114  switch(_data_layout)
115  {
116  case DataLayout::NCHW:
117  NEScheduler::get().schedule_op(_pooling_layer_kernel.get(), _is_global_pooling_layer ? Window::DimZ : Window::DimY, _pooling_layer_kernel->window(), tensors);
118  break;
119  case DataLayout::NHWC:
120  NEScheduler::get().schedule_op(_pooling_layer_kernel.get(), Window::DimX, _pooling_layer_kernel->window(), tensors);
121  break;
122  default:
123  ARM_COMPUTE_ERROR("Data layout not supported");
124  }
125  }
126 }
#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 91 of file CpuPool2d.cpp.

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

Referenced by NEPoolingLayer::validate().

92 {
93  const bool run_optimised = bool(kernels::CpuPool2dAssemblyWrapperKernel::validate(src, dst, pool_info)) && (indices == nullptr);
94 
95  if(run_optimised)
96  {
97  return Status{};
98  }
99 
100  return kernels::CpuPool2dKernel::validate(src, dst, pool_info, indices);
101 }
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 128 of file CpuPool2d.cpp.

129 {
130  return _aux_mem;
131 }

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