Compute Library
 21.02
ClPooling Class Reference

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

#include <ClPooling.h>

Collaboration diagram for ClPooling:
[legend]

Public Member Functions

 ClPooling ()=default
 Constructor. More...
 
void configure (const ClCompileContext &compile_context, ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &info, ITensorInfo *indices=nullptr)
 Configure operator for a given list of arguments. More...
 
void run (ITensorPack &tensors) override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from ICLOperator
 ICLOperator (IRuntimeContext *ctx=nullptr)
 Constructor. More...
 
 ICLOperator (const ICLOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICLOperator (ICLOperator &&)=default
 Default move constructor. More...
 
ICLOperatoroperator= (const ICLOperator &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICLOperatoroperator= (ICLOperator &&)=default
 Default move assignment operator. 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 &info, const ITensorInfo *indices=nullptr)
 Static function to check if given info will lead to a valid configuration of ClPooling. More...
 

Detailed Description

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

This function calls the following OpenCL kernels:

  1. CLFillBorderKernel (executed if padding size is different from zero)
  2. opencl::ClPooling

Definition at line 41 of file ClPooling.h.

Constructor & Destructor Documentation

◆ ClPooling()

ClPooling ( )
default

Constructor.

Member Function Documentation

◆ configure()

void configure ( const ClCompileContext compile_context,
ITensorInfo src,
ITensorInfo dst,
const PoolingLayerInfo info,
ITensorInfo indices = nullptr 
)

Configure operator for a given list of arguments.

Parameters
[in]compile_contextThe compile context to be used.
[in]srcSource tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
[out]dstDestination tensor info. Data type supported: same as src
[in]infoPooling layer parameters.
[out]indices(optional) The indices info of the maximal values. Data type supported: U32.

Definition at line 36 of file ClPooling.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::test::validation::b, arm_compute::CONSTANT, arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), PoolingLayerInfo::data_layout, arm_compute::test::validation::data_type, ITensorInfo::data_type(), PoolingLayerInfo::exclude_padding, CLScheduler::get(), arm_compute::get_min_max(), arm_compute::is_data_type_quantized(), arm_compute::is_data_type_quantized_asymmetric(), arm_compute::support::cpp11::lowest(), arm_compute::MAX, arm_compute::NCHW, arm_compute::NHWC, PoolingLayerInfo::pool_type, ITensorInfo::quantization_info(), arm_compute::REPLICATE, CLScheduler::tune_kernel_static(), and arm_compute::UNKNOWN.

37 {
39  // Configure pooling kernel
40  auto k = std::make_unique<kernels::ClPoolingKernel>();
41  k->set_target(CLScheduler::get().target());
42  k->configure(compile_context, src, dst, info, indices);
43  _pooling = std::move(k);
44 
45  const DataType data_type = src->data_type();
46 
47  // Configure border depending on operation required (quantize border in case of asymmetric data_type)
48  BorderMode border_mode{};
49  PixelValue pixel_value(0.f);
50  if(is_data_type_quantized_asymmetric(data_type) && !info.exclude_padding)
51  {
52  pixel_value = PixelValue(0, data_type, src->quantization_info());
53  }
54 
55  // Data layout
56  const auto data_layout = info.data_layout == DataLayout::UNKNOWN ? src->data_layout() : info.data_layout;
57 
58  switch(data_layout)
59  {
60  case DataLayout::NCHW:
61  border_mode = (PoolingType::MAX == info.pool_type) ? BorderMode::REPLICATE : BorderMode::CONSTANT;
62  break;
63  case DataLayout::NHWC:
64  border_mode = BorderMode::CONSTANT;
65  if(PoolingType::MAX == info.pool_type)
66  {
67  if(is_data_type_quantized(data_type))
68  {
69  std::tie(pixel_value, std::ignore) = get_min_max(data_type);
70  }
71  else
72  {
73  pixel_value = PixelValue(std::numeric_limits<float>::lowest());
74  }
75  }
76  break;
77  default:
78  ARM_COMPUTE_ERROR("Data layout not supported");
79  }
80  auto b = std::make_unique<CLFillBorderKernel>();
81  b->configure(compile_context, src, _pooling->border_size(), border_mode, pixel_value);
82  _border_handler = std::move(b);
83 
84  // Tune kernels
86 }
BorderMode
Methods available to handle borders.
Definition: Types.h:265
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:1168
SimpleTensor< float > b
Definition: DFT.cpp:157
static CLScheduler & get()
Access the scheduler singleton.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
const DataLayout data_layout
Definition: Im2Col.cpp:151
SimpleTensor< float > src
Definition: DFT.cpp:155
const DataType data_type
Definition: Im2Col.cpp:150
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
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Pixels outside the image are assumed to have the same value as the closest image pixel.
Num samples, height, width, channels.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
void tune_kernel_static(ICLKernel &kernel)
Tunes OpenCL kernel.
Definition: CLScheduler.cpp:84
DataLayout data_layout
Data layout to use.
DataType
Available data types.
Definition: Types.h:77
std::tuple< PixelValue, PixelValue > get_min_max(DataType dt)
Compute the mininum and maximum values a data type can take.
Definition: Utils.h:564

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

Definition at line 93 of file ClPooling.cpp.

References ARM_COMPUTE_ERROR_ON_MSG, ITensorPack::empty(), CLScheduler::enqueue_op(), and CLScheduler::get().

94 {
95  ARM_COMPUTE_ERROR_ON_MSG(tensors.empty(), "No inputs provided");
96 
97  CLScheduler::get().enqueue_op(*_border_handler.get(), tensors, false);
98  CLScheduler::get().enqueue_op(*_pooling.get(), tensors, false);
99 }
static CLScheduler & get()
Access the scheduler singleton.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
void enqueue_op(ICLKernel &kernel, ITensorPack &tensors, bool flush=true)
Schedule the execution of the passed kernel if possible.

◆ validate()

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

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

Parameters
[in]srcSource tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
[out]dstDestination tensor info. Data type supported: same as src
[in]infoPooling layer parameters.
[out]indices(optional) The indices info of the maximal values. Data type supported: U32.
Returns
a status

Definition at line 88 of file ClPooling.cpp.

References ClPoolingKernel::validate().

Referenced by CLPoolingLayer::validate().

89 {
91 }
SimpleTensor< float > src
Definition: DFT.cpp:155
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
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 ClPoolingKernel.

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