Compute Library
 21.08
CpuScaleKernel Class Reference

Arm(R) Neon(TM) kernel to perform scaling on a tensor. More...

#include <CpuScaleKernel.h>

Collaboration diagram for CpuScaleKernel:
[legend]

Public Member Functions

 CpuScaleKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuScaleKernel)
 
void configure (const ITensorInfo *src, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *dst, const ScaleKernelInfo &info)
 Initialise the kernel's inputs, output and interpolation policy. More...
 
void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
const char * name () const override
 Name of the kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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...
 
- 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...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *src, const ITensorInfo *dx, const ITensorInfo *dy, const ITensorInfo *offsets, ITensorInfo *dst, const ScaleKernelInfo &info)
 Static function to check if given info will lead to a valid configuration. More...
 

Detailed Description

Arm(R) Neon(TM) kernel to perform scaling on a tensor.

Definition at line 38 of file CpuScaleKernel.h.

Constructor & Destructor Documentation

◆ CpuScaleKernel()

CpuScaleKernel ( )
default

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuScaleKernel  )

◆ configure()

void configure ( const ITensorInfo src,
const ITensorInfo dx,
const ITensorInfo dy,
const ITensorInfo offsets,
ITensorInfo dst,
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]srcSource tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/U8/S16/F16/F32.
[in]dxDistance x tensor info. Pixel's distance between the X real coordinate and the smallest X following integer. Data type supported: F32
[in]dyDistance y tensor info. Pixel's distance between the Y real coordinate and the smallest Y following integer. Data type supported: F32
[in]offsetsOffset tensor info. Offset to access the pixel with NEAREST interpolation or the top-left pixel with BILINEAR interpolation in the input tensor. Data type supported: S32.
[out]dstDestination tensor info. 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 202 of file CpuScaleKernel.cpp.

References ScaleKernelInfo::align_corners, arm_compute::AREA, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_UNUSED, 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(), arm_compute::scale_helpers::delta_bilinear(), Qasymm8QuantizationHelper< QUANTIZED_TYPE >::dequantize(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, arm_compute::test::validation::dst, arm_compute::execute_window_loop(), CPUInfo::get(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::idx_height, arm_compute::test::validation::idx_width, ITensor::info(), ScaleKernelInfo::interpolation_policy, BorderSize::left, arm_compute::NCHW, arm_compute::NEAREST_NEIGHBOR, ITensorInfo::num_dimensions(), ITensorInfo::padding(), arm_compute::scale_helpers::pixel_area_c1u8_clamp(), Iterator::ptr(), ITensor::ptr_to_element(), ITensorInfo::quantization_info(), arm_compute::REPLICATE, BorderSize::right, arm_compute::utils::rounding::round_half_away_from_zero(), ScaleKernelInfo::sampling_policy, scale_bilinear_nchw(), Window::set(), arm_compute::test::validation::src, ITensorInfo::strides_in_bytes(), arm_compute::string_from_data_layout(), arm_compute::string_from_data_type(), arm_compute::string_from_interpolation_policy(), type, arm_compute::U8, arm_compute::UNDEFINED, QuantizationInfo::uniform(), arm_compute::UNKNOWN, arm_compute::test::validation::w, arm_compute::WIDTH, Window::x(), and Window::y().

204 {
205  ARM_COMPUTE_UNUSED(dx, dy, offsets);
207  // Perform validation step
208  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src,
209  dx,
210  dy,
211  offsets,
212  dst,
213  info));
214 
215  const auto *uk = get_implementation(ScaleSelectorData{ src->data_type(), CPUInfo::get() });
217 
218  _run_method = uk->ukernel;
219  _name = std::string("CpuScaleKernel").append("/").append(uk->name).append("_").append(string_from_interpolation_policy(info.interpolation_policy));
220 
221  // Get data layout and width/height indices
222  _data_layout = info.data_layout == DataLayout::UNKNOWN ? src->data_layout() : info.data_layout;
225 
226  _policy = info.interpolation_policy;
227  _border_mode = info.border_mode;
228  _constant_border_value = info.constant_border_value;
229  _align_corners = info.align_corners;
230 
232  {
233  _sampling_offset = 0.5f;
234  }
235 
236  // Compute the ratio between source width/height and destination width/height
237  const auto wr = scale_utils::calculate_resize_ratio(src->dimension(idx_width), dst->dimension(idx_width), _align_corners);
238  const auto hr = scale_utils::calculate_resize_ratio(src->dimension(idx_height), dst->dimension(idx_height), _align_corners);
239 
240  // Area interpolation behaves as Nearest Neighbour in case of up-sampling
241  _policy = (_policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) ? InterpolationPolicy::NEAREST_NEIGHBOR : _policy;
242 
243  if(_border_mode == BorderMode::UNDEFINED)
244  {
245  _border_mode = BorderMode::CONSTANT;
246  _constant_border_value = PixelValue();
247  }
248 
249 #ifdef ENABLE_NCHW_KERNELS
250  // Configure scale function to run
251  if(_data_layout == DataLayout::NCHW)
252  {
253  std::string function_to_call("scale_");
254  function_to_call += string_from_data_type(src->data_type()) + "_";
255  function_to_call += string_from_data_layout(_data_layout) + "_";
256  function_to_call += string_from_interpolation_policy(_policy);
257 
258  static std::map<std::string, ScaleFunctionPtr> map_function =
259  {
260  { "scale_U8_NCHW_AREA_CONSTANT", &CpuScaleKernel::scale_area_nchw_u8 },
261 
262  { "scale_U8_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_nchw<uint8_t> },
263  { "scale_U8_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<uint8_t> },
264 
265  { "scale_QASYMM8_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_qasymm<uint8_t> },
266  { "scale_QASYMM8_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<uint8_t> },
267 
268  { "scale_QASYMM8_SIGNED_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_qasymm<int8_t> },
269  { "scale_QASYMM8_SIGNED_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<int8_t> },
270 
271  { "scale_S16_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_nchw<int16_t> },
272  { "scale_S16_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<int16_t> },
273 
274 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
275  { "scale_F16_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_nchw<float16_t> },
276  { "scale_F16_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<float16_t> },
277 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
278 
279  { "scale_F32_NCHW_BILINEAR", &CpuScaleKernel::scale_bilinear_nchw<float> },
280  { "scale_F32_NCHW_NEAREST_NEIGHBOUR", &CpuScaleKernel::scale_nearest_nchw<float> },
281  };
282  auto it = map_function.find(function_to_call);
283  if(it != map_function.end())
284  {
285  _func = it->second;
286  }
287  }
288 #endif // ENABLE_NCHW_KERNELS
289 
290  // Configure window
291  Window win = calculate_max_window(*dst, Steps());
292  ICpuKernel::configure(win);
293 }
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.
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...
SimpleTensor< float > src
Definition: DFT.cpp:155
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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
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:187
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.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
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
static CPUInfo & get()
Access the KernelLibrary singleton.
Definition: CPPTypes.cpp:39
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
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 617 of file CpuScaleKernel.cpp.

618 {
619  return _name.c_str();
620 }

◆ run_op()

void run_op ( ITensorPack tensors,
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]tensorsA vector containing the tensors to operate on.
[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 593 of file CpuScaleKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_INT_0, arm_compute::ACL_INT_1, arm_compute::ACL_INT_2, arm_compute::ACL_SRC, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::NCHW, arm_compute::NHWC, and IKernel::window().

594 {
598  ARM_COMPUTE_ERROR_ON(_func == nullptr && _data_layout == DataLayout::NCHW);
599  ARM_COMPUTE_ERROR_ON(_run_method == nullptr && _data_layout == DataLayout::NHWC);
600 
601  const auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
602  auto dst = tensors.get_tensor(TensorType::ACL_DST);
603  const auto dx = tensors.get_const_tensor(TensorType::ACL_INT_0);
604  const auto dy = tensors.get_const_tensor(TensorType::ACL_INT_1);
605  const auto offsets = tensors.get_const_tensor(TensorType::ACL_INT_2);
606 
607  if(_data_layout == DataLayout::NCHW)
608  {
609  (this->*_func)(src, dst, dx, dy, offsets, window);
610  }
611  else
612  {
613  _run_method(src, dst, offsets, dx, dy, _policy, _border_mode, _constant_border_value, _sampling_offset, _align_corners, window);
614  }
615 }
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:466
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
Num samples, channels, height, width.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Num samples, height, width, channels.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo dx,
const ITensorInfo dy,
const ITensorInfo offsets,
ITensorInfo dst,
const ScaleKernelInfo info 
)
static

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

Similar to CpuScaleKernel::configure()

Returns
a status

Definition at line 586 of file CpuScaleKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by CpuScale::validate().

588 {
589  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, dx, dy, offsets, output, info));
590  return Status{};
591 }
#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)

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