Compute Library
 21.02
NEPadLayerKernel Class Reference

Neon kernel to add padding to a tensor. More...

#include <NEPadLayerKernel.h>

Collaboration diagram for NEPadLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEPadLayerKernel ()
 Default constructor. More...
 
 NEPadLayerKernel (const NEPadLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEPadLayerKerneloperator= (const NEPadLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEPadLayerKernel (NEPadLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEPadLayerKerneloperator= (NEPadLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEPadLayerKernel ()=default
 Default destructor. More...
 
void configure (ITensor *input, ITensor *output, const PaddingList &padding, const PixelValue constant_value=PixelValue(), const PaddingMode mode=PaddingMode::CONSTANT)
 Initialize the function. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Static Public Member Functions

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

Detailed Description

Neon kernel to add padding to a tensor.

Add padding given padding information

Definition at line 37 of file NEPadLayerKernel.h.

Constructor & Destructor Documentation

◆ NEPadLayerKernel() [1/3]

Default constructor.

Definition at line 181 of file NEPadLayerKernel.cpp.

Referenced by NEPadLayerKernel::name().

182  : _func(), _input(nullptr), _output(nullptr), _padding(), _constant_value(), _mode()
183 {
184 }

◆ NEPadLayerKernel() [2/3]

NEPadLayerKernel ( const NEPadLayerKernel )
delete

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

◆ NEPadLayerKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEPadLayerKernel()

~NEPadLayerKernel ( )
default

Default destructor.

Referenced by NEPadLayerKernel::name().

Member Function Documentation

◆ configure()

void configure ( ITensor input,
ITensor output,
const PaddingList padding,
const PixelValue  constant_value = PixelValue(),
const 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. Only CONSTANT padding mode is currently supported

Definition at line 186 of file NEPadLayerKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), arm_compute::misc::shape_calculator::compute_padded_shape(), arm_compute::CONSTANT, ITensorInfo::element_size(), ITensorInfo::has_padding(), ITensor::info(), arm_compute::test::validation::input, clang_tidy_rules::mode, ITensorInfo::num_dimensions(), Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), ITensorInfo::tensor_shape(), and arm_compute::validate_arguments().

Referenced by NEPadLayerKernel::name().

187 {
189  // Auto-init
190  const TensorShape expected_output_shape = arm_compute::misc::shape_calculator::compute_padded_shape(input->info()->tensor_shape(), padding);
191  const TensorInfo expected_output_info = input->info()->clone()->set_tensor_shape(expected_output_shape);
192  auto_init_if_empty(*output->info(), expected_output_info);
193 
194  // Perform validation step
195  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), padding, mode));
196 
197  _input = input;
198  _output = output;
199  _padding = padding;
200  _constant_value = constant_value;
201  _mode = mode;
202 
203  if(_mode == PaddingMode::CONSTANT)
204  {
205  switch(_input->info()->element_size())
206  {
207  case 1:
208  if(_input->info()->num_dimensions() == 3 && // Is 3D
209  padding.size() <= 3 && // Has 3D padding
210  !_input->info()->has_padding() && !_output->info()->has_padding()) // Input & Output have no padding
211  {
212  _func = &NEPadLayerKernel::run_pad_constant_uint8_3Dinput_3Dpad;
213  }
214  else
215  {
216  _func = &NEPadLayerKernel::run_pad_constant<uint8_t>;
217  }
218  break;
219  case 2:
220  _func = &NEPadLayerKernel::run_pad_constant<uint16_t>;
221  break;
222  case 4:
223  _func = &NEPadLayerKernel::run_pad_constant<uint32_t>;
224  break;
225  default:
226  ARM_COMPUTE_ERROR("Element size not supported");
227  break;
228  }
229  }
230  else
231  {
232  ARM_COMPUTE_ERROR("Padding mode not supported");
233  }
234 
235  // Configure kernel window
236  Window win = calculate_max_window(*output->info(), Steps());
237 
238  // The NEPad doesn't need padding so update_window_and_padding() can be skipped
239  Coordinates coord;
240  coord.set_num_dimensions(output->info()->num_dimensions());
241  output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape()));
242 
243  ICPPKernel::configure(win);
244 }
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
TensorShape compute_padded_shape(const TensorShape &input_shape, const PaddingList &padding)
Calculate the padded shape of a tensor.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
virtual bool has_padding() const =0
Checks if the tensor has been allocated with padding or not.

◆ name()

◆ operator=() [1/2]

NEPadLayerKernel& operator= ( const NEPadLayerKernel )
delete

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

Referenced by NEPadLayerKernel::name().

◆ operator=() [2/2]

NEPadLayerKernel& operator= ( NEPadLayerKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Reimplemented from ICPPKernel.

Definition at line 253 of file NEPadLayerKernel.cpp.

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and IKernel::window().

Referenced by NEPadLayerKernel::name().

254 {
258 
259  if(_func != nullptr)
260  {
261  (this->*_func)(window);
262  }
263 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

◆ validate()

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

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

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. Only CONSTANT padding mode is currently supported
Returns
a status

Definition at line 246 of file NEPadLayerKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, ARM_COMPUTE_UNUSED, and arm_compute::validate_arguments().

Referenced by NEPadLayerKernel::name(), and NEPadLayer::validate().

247 {
248  ARM_COMPUTE_UNUSED(constant_value);
250  return Status{};
251 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

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