Compute Library
 21.02
CLPadLayer Class Reference

Basic function to pad a tensor. More...

#include <CLPadLayer.h>

Collaboration diagram for CLPadLayer:
[legend]

Public Member Functions

 CLPadLayer ()
 Default constructor. More...
 
 CLPadLayer (const CLPadLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLPadLayer (CLPadLayer &&)=default
 Default move constructor. More...
 
CLPadLayeroperator= (const CLPadLayer &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLPadLayeroperator= (CLPadLayer &&)=default
 Default move assignment operator. More...
 
 ~CLPadLayer ()
 Default destructor. More...
 
void configure (ICLTensor *input, ICLTensor *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)
 Initialize the function. More...
 
void configure (const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)
 Initialize the function. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)
 Static function to check if given info will lead to a valid configuration of CLPadLayer. More...
 

Detailed Description

Basic function to pad a tensor.

This function calls the following OpenCL functions/kernels:

  1. CLPadLayerKernel if there is padding to be added
  2. CLCopy otherwise

Definition at line 44 of file CLPadLayer.h.

Constructor & Destructor Documentation

◆ CLPadLayer() [1/3]

Default constructor.

Definition at line 29 of file CLPadLayer.cpp.

References CLPadLayer::~CLPadLayer().

30  : _pad_kernel(std::make_unique<CLPadLayerKernel>()),
31  _copy(),
32  _perform_pad(false)
33 {
34 }

◆ CLPadLayer() [2/3]

CLPadLayer ( const CLPadLayer )
delete

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

◆ CLPadLayer() [3/3]

CLPadLayer ( CLPadLayer &&  )
default

Default move constructor.

◆ ~CLPadLayer()

~CLPadLayer ( )
default

Default destructor.

Referenced by CLPadLayer::CLPadLayer().

Member Function Documentation

◆ configure() [1/2]

void configure ( ICLTensor input,
ICLTensor output,
const PaddingList padding,
PixelValue  constant_value = PixelValue(),
PaddingMode  mode = PaddingMode::CONSTANT 
)

Initialize the function.

Parameters
[in]inputSource tensor. Data types supported: All.
[out]outputOutput tensor. Data type supported: same as input
[in]paddingThe padding for each spatial dimension of the input tensor. The pair padding[i] specifies the front and the end padding in the i-th dimension.
[in]constant_value(Optional) Constant value to be used for the padding.
[in]mode(Optional) Controls whether the padding should be filled with constant_value using CONSTANT, or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT).

Definition at line 38 of file CLPadLayer.cpp.

References CLKernelLibrary::get().

Referenced by CLFFTConvolutionLayer::configure().

39 {
40  configure(CLKernelLibrary::get().get_compile_context(), input, output, padding, constant_value, mode);
41 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(ICLTensor *input, ICLTensor *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)
Initialize the function.
Definition: CLPadLayer.cpp:38

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
ICLTensor input,
ICLTensor output,
const PaddingList padding,
PixelValue  constant_value = PixelValue(),
PaddingMode  mode = PaddingMode::CONSTANT 
)

Initialize the function.

Parameters
[in]compile_contextThe compile context to be used.
[in]inputSource tensor. Data types supported: All.
[out]outputOutput tensor. Data type supported: same as input
[in]paddingThe padding for each spatial dimension of the input tensor. The pair padding[i] specifies the front and the end padding in the i-th dimension.
[in]constant_value(Optional) Constant value to be used for the padding.
[in]mode(Optional) Controls whether the padding should be filled with constant_value using CONSTANT, or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT).

Definition at line 43 of file CLPadLayer.cpp.

References ARM_COMPUTE_ERROR_THROW_ON, CLCopy::configure(), ITensor::info(), arm_compute::test::validation::info, clang_tidy_rules::mode, and CLPadLayer::validate().

44 {
45  ARM_COMPUTE_ERROR_THROW_ON(validate(input->info(), output->info(), padding, constant_value, mode));
46 
47  _perform_pad = std::any_of(padding.begin(), padding.end(), [](PaddingInfo info)
48  {
49  return info.first > 0 || info.second > 0;
50  });
51 
52  if(_perform_pad)
53  {
54  _pad_kernel->configure(compile_context, input, output, padding, constant_value, mode);
55  }
56  else
57  {
58  // Copy the input to the whole output if no padding is applied
59  _copy.configure(compile_context, input, output);
60  }
61 }
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)
Static function to check if given info will lead to a valid configuration of CLPadLayer.
Definition: CLPadLayer.cpp:62
void configure(ICLTensor *input, ICLTensor *output, Window *dst_window=nullptr)
Initialise the function&#39;s source and destination.
Definition: CLCopy.cpp:52
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
std::pair< uint32_t, uint32_t > PaddingInfo
Padding information as a pair of unsigned int start/end.
Definition: Types.h:478

◆ operator=() [1/2]

CLPadLayer& operator= ( const CLPadLayer )
delete

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

◆ operator=() [2/2]

CLPadLayer& operator= ( CLPadLayer &&  )
default

Default move assignment operator.

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For Neon kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 79 of file CLPadLayer.cpp.

References CLScheduler::enqueue(), CLScheduler::get(), and CLCopy::run().

Referenced by CLFFTConvolutionLayer::prepare(), and CLFFTConvolutionLayer::run().

80 {
81  if(_perform_pad)
82  {
83  CLScheduler::get().enqueue(*_pad_kernel);
84  }
85  else
86  {
87  _copy.run();
88  }
89 }
static CLScheduler & get()
Access the scheduler singleton.
void run() override
Run the kernels contained in the function.
Definition: CLCopy.cpp:73
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const PaddingList padding,
PixelValue  constant_value = PixelValue(),
PaddingMode  mode = PaddingMode::CONSTANT 
)
static

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

Parameters
[in]inputSource tensor info. Data types supported: All.
[in]outputOutput tensor info. Data type supported: same as input
[in]paddingThe padding for each spatial dimension of the input tensor. The pair padding[i] specifies the front and the end padding in the i-th dimension.
[in]constant_value(Optional) Constant value to be used for the padding
[in]mode(Optional) Controls whether the padding should be filled with constant_value using CONSTANT, or reflect the input, either including the border values (SYMMETRIC) or not (REFLECT).

Definition at line 62 of file CLPadLayer.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::test::validation::info, CLCopy::validate(), and CLPadLayerKernel::validate().

Referenced by CLPadLayer::configure(), and arm_compute::test::validation::DATA_TEST_CASE().

63 {
64  bool perform_pad = std::any_of(padding.begin(), padding.end(), [](PaddingInfo info)
65  {
66  return info.first > 0 || info.second > 0;
67  });
68 
69  if(perform_pad)
70  {
71  ARM_COMPUTE_RETURN_ON_ERROR(CLPadLayerKernel::validate(input, output, padding, constant_value, mode));
72  }
73  else
74  {
76  }
77  return Status{};
78 }
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, PixelValue constant_value=PixelValue(), PaddingMode mode=PaddingMode::CONSTANT)
Static function to check if given info will lead to a valid configuration of CLPadLayerKernel.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
static Status validate(const ITensorInfo *input, const ITensorInfo *output, Window *dst_window=nullptr)
Static function to check if given info will lead to a valid configuration of CLCopy.
Definition: CLCopy.cpp:68
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
std::pair< uint32_t, uint32_t > PaddingInfo
Padding information as a pair of unsigned int start/end.
Definition: Types.h:478

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