Compute Library
 19.08
NEScaleKernel Class Reference

NEON kernel to perform scaling on a tensor. More...

#include <NEScaleKernel.h>

Collaboration diagram for NEScaleKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEScaleKernel ()
 Default constructor. More...
 
 NEScaleKernel (const NEScaleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEScaleKerneloperator= (const NEScaleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEScaleKernel (NEScaleKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEScaleKerneloperator= (NEScaleKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEScaleKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, const ITensor *dx, const ITensor *dy, const ITensor *offsets, ITensor *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value=PixelValue(), SamplingPolicy sampling_policy=SamplingPolicy::CENTER, bool use_padding=true)
 Initialise the kernel's inputs, output and interpolation policy. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
BorderSize border_size () const override
 The size of the border for that kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. 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...
 
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 *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *output, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value=PixelValue(), SamplingPolicy sampling_policy=SamplingPolicy::CENTER, bool use_padding=true)
 Static function to check if given info will lead to a valid configuration of NEScaleKernel. More...
 

Detailed Description

NEON kernel to perform scaling on a tensor.

Definition at line 35 of file NEScaleKernel.h.

Constructor & Destructor Documentation

◆ NEScaleKernel() [1/3]

Default constructor.

Definition at line 328 of file NEScaleKernel.cpp.

329  : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr), _policy(), _border_size(1), _border_mode(), _constant_border_value(PixelValue()),
330  _sampling_offset(0), _use_padding(true)
331 {
332 }

◆ NEScaleKernel() [2/3]

NEScaleKernel ( const NEScaleKernel )
delete

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

◆ NEScaleKernel() [3/3]

NEScaleKernel ( NEScaleKernel &&  )
default

Allow instances of this class to be moved.

◆ ~NEScaleKernel()

~NEScaleKernel ( )
default

Default destructor.

Member Function Documentation

◆ border_size()

BorderSize border_size ( ) const
overridevirtual

The size of the border for that kernel.

Returns
The width in number of elements of the border.

Reimplemented from IKernel.

Definition at line 334 of file NEScaleKernel.cpp.

335 {
336  return _border_size;
337 }

Referenced by NEScale::configure(), NEScaleKernel::configure(), and NEScaleKernel::validate().

◆ configure()

void configure ( const ITensor input,
const ITensor dx,
const ITensor dy,
const ITensor offsets,
ITensor output,
InterpolationPolicy  policy,
BorderMode  border_mode,
PixelValue  constant_border_value = PixelValue(),
SamplingPolicy  sampling_policy = SamplingPolicy::CENTER,
bool  use_padding = true 
)

Initialise the kernel's inputs, output and interpolation policy.

Note
dx, dy and offsets have the same dimensions (width and height) of the output tensor
Using policy Area only supports data layout NCHW and input data type U8.
Parameters
[in]inputSource tensor. Data types supported: U8/S16/F16/F32.
[in]dxPixel's distance between the X real coordinate and the smallest X following integer. Data type supported: F32
[in]dyPixel's distance between the Y real coordinate and the smallest Y following integer. Data type supported: F32
[in]offsetsOffset to access the pixel with NEAREST interpolation or the top-left pixel with BILINEAR interpolation in the input tensor. Data type supported: S32.
[out]outputDestination tensor. Data types supported: Same as input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane.
[in]policyInterpolation type to use
[in]border_modeBorder mode policy
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT and use_padding is set to false.
[in]sampling_policy(Optional) Sampling policy used by the interpolation. Defaults to SamplingPolicy::CENTER
[in]use_padding(Optional) Is padding in use or not. Defaults to true.

Definition at line 339 of file NEScaleKernel.cpp.

342 {
343  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
344  // Perform validation step
345  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(),
346  dx != nullptr ? dx->info() : nullptr,
347  dy != nullptr ? dy->info() : nullptr,
348  offsets != nullptr ? offsets->info() : nullptr,
349  output->info(),
350  policy, border_mode, constant_border_value, sampling_policy, use_padding));
351 
352  // Get data layout and width/height indices
353  const DataLayout data_layout = input->info()->data_layout();
356 
357  _input = input;
358  _output = output;
359  _offsets = offsets;
360  _dx = dx;
361  _dy = dy;
362  _policy = policy;
363  _border_size = BorderSize(1);
364  _border_mode = border_mode;
365  _constant_border_value = constant_border_value;
366  _use_padding = use_padding;
367 
368  if(sampling_policy == SamplingPolicy::CENTER)
369  {
370  _sampling_offset = 0.5f;
371  }
372 
373  // Compute the ratio between source width/height and destination width/height
374  const auto wr = static_cast<float>(input->info()->dimension(idx_width)) / static_cast<float>(output->info()->dimension(idx_width));
375  const auto hr = static_cast<float>(input->info()->dimension(idx_height)) / static_cast<float>(output->info()->dimension(idx_height));
376 
377  // Add constant border only on top in case of NHWC layout
379  {
380  _border_size = (border_mode != BorderMode::REPLICATE && policy == InterpolationPolicy::BILINEAR && use_padding) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
381  }
382 
383  // Area interpolation behaves as Nearest Neighbour in case of up-sampling
384  if(policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f)
385  {
387  }
388 
389  // Select interpolation function
390  switch(policy)
391  {
393  {
394  _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_nearest_nchw : &NEScaleKernel::scale_nhwc;
395  break;
396  }
398  {
399  _func = (data_layout == DataLayout::NCHW) ? &NEScaleKernel::scale_bilinear_nchw : &NEScaleKernel::scale_nhwc;
400  break;
401  }
403  {
404  _func = &NEScaleKernel::scale_area_nchw;
405  break;
406  }
407  default:
408  ARM_COMPUTE_ERROR("Unsupported interpolation mode");
409  }
410 
411  // Configure window
412  std::pair<Status, Window> win_config = validate_and_configure_window(input->info(),
413  dx != nullptr ? dx->info() : nullptr,
414  dy != nullptr ? dy->info() : nullptr,
415  offsets != nullptr ? offsets->info() : nullptr,
416  output->info(),
417  policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size(), use_padding);
418 
419  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
420  INEKernel::configure(win_config.second);
421 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
const DataLayout data_layout
Definition: Im2Col.cpp:146
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
Output values are defined by bilinear interpolation between the pixels.
BorderSize border_size() const override
The size of the border for that kernel.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
Output values are defined to match the source pixel whose center is nearest to the sample position.
Samples are taken at pixel center.
Output values are determined by averaging the source pixels whose areas fall under the area of the de...
Num samples, channels, height, width.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Borders are left undefined.
Pixels outside the image are assumed to have the same value as the closest image pixel.
Num samples, height, width, channels.
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:326
DataLayout
[DataLayout enum definition]
Definition: Types.h:114

References arm_compute::AREA, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::BILINEAR, arm_compute::test::validation::border_mode, NEScaleKernel::border_size(), arm_compute::CENTER, arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::dimension(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, ITensor::info(), arm_compute::NCHW, arm_compute::NEAREST_NEIGHBOR, arm_compute::NHWC, arm_compute::test::validation::policy, arm_compute::REPLICATE, arm_compute::UNDEFINED, arm_compute::validate_and_configure_window(), and arm_compute::WIDTH.

Referenced by NEScale::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 38 of file NEScaleKernel.h.

39  {
40  return "NEScaleKernel";
41  }

◆ operator=() [1/2]

NEScaleKernel& operator= ( const NEScaleKernel )
delete

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

◆ operator=() [2/2]

NEScaleKernel& operator= ( NEScaleKernel &&  )
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.

Implements ICPPKernel.

Definition at line 1017 of file NEScaleKernel.cpp.

1018 {
1022  ARM_COMPUTE_ERROR_ON(_func == nullptr);
1023 
1024  (this->*_func)(window);
1025 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::info, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo dx,
const ITensorInfo dy,
const ITensorInfo offsets,
ITensorInfo output,
InterpolationPolicy  policy,
BorderMode  border_mode,
PixelValue  constant_border_value = PixelValue(),
SamplingPolicy  sampling_policy = SamplingPolicy::CENTER,
bool  use_padding = true 
)
static

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

Note
dx, dy and offsets have the same dimensions (width and height) of the output tensor
Using policy Area only supports data layout NCHW and input data type U8.
Parameters
[in]inputSource tensor. Data types supported: U8/S16/F16/F32.
[in]dxPixel's distance between the X real coordinate and the smallest X following integer. Data type supported: F32
[in]dyPixel's distance between the Y real coordinate and the smallest Y following integer. Data type supported: F32
[in]offsetsOffset to access the pixel with NEAREST interpolation or the top-left pixel with BILINEAR interpolation in the input tensor. Data type supported: S32.
[in]outputDestination tensor. Data types supported: Same as input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane.
[in]policyInterpolation type to use
[in]border_modeBorder mode policy
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT and use_padding is set to false.
[in]sampling_policy(Optional) Sampling policy used by the interpolation. Defaults to SamplingPolicy::CENTER
[in]use_padding(Optional) Is padding in use or not. Defaults to true.

Definition at line 995 of file NEScaleKernel.cpp.

998 {
999  BorderSize border_size(1);
1000  if(input->data_layout() == DataLayout::NHWC)
1001  {
1002  border_size = (border_mode == BorderMode::CONSTANT && policy == InterpolationPolicy::BILINEAR) ? BorderSize(1, 0, 0, 0) : BorderSize(0);
1003  }
1004 
1005  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, dx, dy, offsets, output, policy, border_mode, constant_border_value, sampling_policy, use_padding));
1007  dx != nullptr ? dx->clone().get() : nullptr,
1008  dy != nullptr ? dy->clone().get() : nullptr,
1009  offsets != nullptr ? offsets->clone().get() : nullptr,
1010  output->clone().get(),
1011  policy, border_mode == BorderMode::UNDEFINED, sampling_policy, border_size, use_padding)
1012  .first);
1013 
1014  return Status{};
1015 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
Output values are defined by bilinear interpolation between the pixels.
BorderSize border_size() const override
The size of the border for that kernel.
Borders are left undefined.
Num samples, height, width, channels.

References ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::BILINEAR, arm_compute::test::validation::border_mode, NEScaleKernel::border_size(), ICloneable< T >::clone(), arm_compute::CONSTANT, ITensorInfo::data_layout(), arm_compute::NHWC, arm_compute::test::validation::policy, arm_compute::UNDEFINED, and arm_compute::validate_and_configure_window().

Referenced by NEScale::validate().


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