Compute Library
 21.02
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, const ScaleKernelInfo &info)
 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...
 
- 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 *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *output, const ScaleKernelInfo &info)
 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 193 of file NEScaleKernel.cpp.

Referenced by NEScaleKernel::name().

194  : _func(nullptr), _offsets(nullptr), _dx(nullptr), _dy(nullptr), _input(nullptr), _output(nullptr), _policy(), _border_mode(), _constant_border_value(PixelValue()), _sampling_offset(0),
195  _align_corners(false), _data_layout(DataLayout::UNKNOWN)
196 {
197 }

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

Referenced by NEScaleKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
const ITensor dx,
const ITensor dy,
const ITensor offsets,
ITensor output,
const ScaleKernelInfo info 
)

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: QASYMM8/QASYMM8_SIGNED/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]infoScaleKernelInfo to use for configuration

Definition at line 199 of file NEScaleKernel.cpp.

References ScaleKernelInfo::align_corners, arm_compute::AREA, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ScaleKernelInfo::border_mode, arm_compute::calculate_max_window(), arm_compute::scale_utils::calculate_resize_ratio(), arm_compute::CENTER, arm_compute::CONSTANT, ScaleKernelInfo::constant_border_value, ScaleKernelInfo::data_layout, ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, arm_compute::execute_window_loop(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, ITensor::info(), arm_compute::test::validation::info, arm_compute::test::validation::input, ScaleKernelInfo::interpolation_policy, BorderSize::left, arm_compute::NCHW, arm_compute::NEAREST_NEIGHBOR, ITensorInfo::num_dimensions(), ITensorInfo::padding(), Iterator::ptr(), BorderSize::right, arm_compute::utils::rounding::round_half_away_from_zero(), ScaleKernelInfo::sampling_policy, Window::set(), Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), arm_compute::string_from_data_layout(), arm_compute::string_from_data_type(), arm_compute::string_from_interpolation_policy(), ITensorInfo::tensor_shape(), arm_compute::UNDEFINED, arm_compute::UNKNOWN, arm_compute::validate_arguments(), arm_compute::WIDTH, IKernel::window(), Window::x(), and Window::y().

Referenced by NEScaleKernel::name().

201 {
203  // Perform validation step
205  dx != nullptr ? dx->info() : nullptr,
206  dy != nullptr ? dy->info() : nullptr,
207  offsets != nullptr ? offsets->info() : nullptr,
208  output->info(),
209  info));
210 
211  // Get data layout and width/height indices
212  _data_layout = info.data_layout == DataLayout::UNKNOWN ? input->info()->data_layout() : info.data_layout;
215 
216  _input = input;
217  _output = output;
218  _offsets = offsets;
219  _dx = dx;
220  _dy = dy;
221  _policy = info.interpolation_policy;
222  _border_mode = info.border_mode;
223  _constant_border_value = info.constant_border_value;
224  _align_corners = info.align_corners;
225 
227  {
228  _sampling_offset = 0.5f;
229  }
230 
231  // Compute the ratio between source width/height and destination width/height
232  const auto wr = scale_utils::calculate_resize_ratio(input->info()->dimension(idx_width), output->info()->dimension(idx_width), _align_corners);
233  const auto hr = scale_utils::calculate_resize_ratio(input->info()->dimension(idx_height), output->info()->dimension(idx_height), _align_corners);
234 
235  // Area interpolation behaves as Nearest Neighbour in case of up-sampling
236  _policy = (_policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) ? InterpolationPolicy::NEAREST_NEIGHBOR : _policy;
237 
238  if(_border_mode == BorderMode::UNDEFINED)
239  {
240  _border_mode = BorderMode::CONSTANT;
241  _constant_border_value = PixelValue();
242  }
243 
244  // Configure scale function to run
245  if(_data_layout == DataLayout::NCHW)
246  {
247  std::string function_to_call("scale_");
248  function_to_call += string_from_data_type(_input->info()->data_type()) + "_";
249  function_to_call += string_from_data_layout(_data_layout) + "_";
250  function_to_call += string_from_interpolation_policy(_policy);
251 
252  static std::map<std::string, ScaleFunctionPtr> map_function =
253  {
254  { "scale_U8_NCHW_AREA_CONSTANT", &NEScaleKernel::scale_area_nchw_u8 },
255 
256  { "scale_U8_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_nchw<uint8_t> },
257  { "scale_U8_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<uint8_t> },
258 
259  { "scale_QASYMM8_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_qasymm<uint8_t> },
260  { "scale_QASYMM8_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<uint8_t> },
261 
262  { "scale_QASYMM8_SIGNED_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_qasymm<int8_t> },
263  { "scale_QASYMM8_SIGNED_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<int8_t> },
264 
265  { "scale_S16_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_nchw<int16_t> },
266  { "scale_S16_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<int16_t> },
267 
268 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
269  { "scale_F16_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_nchw<float16_t> },
270  { "scale_F16_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<float16_t> },
271 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
272 
273  { "scale_F32_NCHW_BILINEAR", &NEScaleKernel::scale_bilinear_nchw<float> },
274  { "scale_F32_NCHW_NEAREST_NEIGHBOUR", &NEScaleKernel::scale_nearest_nchw<float> },
275  };
276  auto it = map_function.find(function_to_call);
277  if(it != map_function.end())
278  {
279  _func = it->second;
280  }
281  }
282 
283  // Configure window
284  Window win = calculate_max_window(*output->info(), Steps());
285  Coordinates coord;
286  coord.set_num_dimensions(output->info()->num_dimensions());
287  output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape()));
288  INEKernel::configure(win);
289 }
BorderMode border_mode
Border mode policy.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
InterpolationPolicy interpolation_policy
Interpolation type to use.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
bool align_corners
Align corners of input and output.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
Output values are defined to match the source pixel whose center is nearest to the sample position...
Samples are taken at pixel center.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
SamplingPolicy sampling_policy
Sampling policy used by the interpolation.
const std::string & string_from_interpolation_policy(InterpolationPolicy policy)
Translates a given interpolation policy to a string.
Definition: Utils.cpp:212
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Output values are determined by averaging the source pixels whose areas fall under the area of the de...
Num samples, channels, height, width.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
Definition: Utils.cpp:123
Borders are left undefined.
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
PixelValue constant_border_value
Constant value to use for constant border mode policy.
float calculate_resize_ratio(size_t input_size, size_t output_size, bool align_corners=false)
Returns resize ratio between input and output with consideration of aligned corners.
Definition: ScaleUtils.cpp:27
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
DataLayout data_layout
Data layout to use.

◆ name()

const char* name ( ) const
inlineoverridevirtual

◆ operator=() [1/2]

NEScaleKernel& operator= ( const NEScaleKernel )
delete

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

Referenced by NEScaleKernel::name().

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

Reimplemented from ICPPKernel.

Definition at line 583 of file NEScaleKernel.cpp.

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

Referenced by NEScaleKernel::name().

584 {
588  ARM_COMPUTE_ERROR_ON(_func == nullptr && _data_layout == DataLayout::NCHW);
589 
590  if(_data_layout == DataLayout::NCHW)
591  {
592  (this->*_func)(window);
593  }
594  else
595  {
596  const auto *uk = get_implementation(ScaleSelectorData{ _input->info()->data_type() });
597  uk->ukernel(_input, _output, _offsets, _dx, _dy, _policy, _border_mode, _constant_border_value, _sampling_offset, _align_corners, window);
598  }
599 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
Num samples, channels, height, width.
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 dx,
const ITensorInfo dy,
const ITensorInfo offsets,
ITensorInfo output,
const ScaleKernelInfo info 
)
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: QASYMM8/QASYMM8_SIGNED/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]infoScaleKernelInfo to use for validation

Definition at line 576 of file NEScaleKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

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

578 {
579  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, dx, dy, offsets, output, info));
580  return Status{};
581 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
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: