Compute Library
 22.05
NEScale Class Reference

Basic function to compute Scale. More...

#include <NEScale.h>

Collaboration diagram for NEScale:
[legend]

Public Member Functions

 NEScale ()
 Constructor. More...
 
 NEScale (const NEScale &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEScale (NEScale &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
NEScaleoperator= (const NEScale &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEScaleoperator= (NEScale &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
 ~NEScale ()
 Destructor. More...
 
void configure (ITensor *input, ITensor *output, const ScaleKernelInfo &info)
 Initialize the function's source, destination, interpolation type and border_mode. 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 ScaleKernelInfo &info)
 Static function to check if given info will lead to a valid configuration of NEScale. More...
 

Detailed Description

Basic function to compute Scale.

Definition at line 40 of file NEScale.h.

Constructor & Destructor Documentation

◆ NEScale() [1/3]

NEScale ( )

Constructor.

Definition at line 45 of file NEScale.cpp.

References NEScale::~NEScale().

46  : _impl(std::make_unique<Impl>())
47 {
48 }

◆ NEScale() [2/3]

NEScale ( const NEScale )
delete

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

◆ NEScale() [3/3]

NEScale ( NEScale &&  )
delete

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ ~NEScale()

~NEScale ( )
default

Destructor.

Referenced by NEScale::NEScale().

Member Function Documentation

◆ configure()

void configure ( ITensor input,
ITensor output,
const ScaleKernelInfo info 
)

Initialize the function's source, destination, interpolation type and border_mode.

Valid data layouts:

  • NHWC
  • NCHW

Valid data type configurations:

src dst
QASYMM8 QASYMM8
QASYMM8_SIGNED QASYMM8_SIGNED
F16 F16
F32 F32
U8 U8
S16 S16
Parameters
[in,out]inputSource tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/U8/S16/F16/F32. (Written to only for border_mode != UNDEFINED)
[out]outputDestination tensor. Data type 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 be used for configuration

Definition at line 51 of file NEScale.cpp.

References ScaleKernelInfo::align_corners, arm_compute::AREA, ARM_COMPUTE_ERROR, ARM_COMPUTE_LOG_PARAMS, arm_compute::BILINEAR, arm_compute::scale_utils::calculate_resize_ratio(), ScaleKernelInfo::data_layout, ITensorInfo::data_layout(), arm_compute::test::validation::data_layout, ITensorInfo::dimension(), arm_compute::F32, 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, arm_compute::scale_utils::is_align_corners_allowed_sampling_policy(), arm_compute::NEAREST_NEIGHBOR, arm_compute::S32, ScaleKernelInfo::sampling_policy, arm_compute::test::validation::shape, arm_compute::UNKNOWN, and arm_compute::WIDTH.

Referenced by arm_compute::test::validation::DATA_TEST_CASE().

52 {
54 
55  _impl->src = input;
56  _impl->dst = output;
57  _impl->op = std::make_unique<cpu::CpuScale>();
58  _impl->op->configure(input->info(), output->info(), info);
59 
60  // Configure for size of allocation of internal tensors
61  // Get data layout and width/height indices
62  const DataLayout data_layout = info.data_layout == DataLayout::UNKNOWN ? input->info()->data_layout() : info.data_layout;
65 
66  // Compute the ratio between source width/height and destination width/height
68  const auto wr = arm_compute::scale_utils::calculate_resize_ratio(input->info()->dimension(idx_width), output->info()->dimension(idx_width), is_align_corners_used);
69  const auto hr = arm_compute::scale_utils::calculate_resize_ratio(input->info()->dimension(idx_height), output->info()->dimension(idx_height), is_align_corners_used);
70 
71  // Area interpolation behaves as Nearest Neighbour in case of up-sampling
73 
74  // Get the tensor shape
75  TensorShape shape(output->info()->dimension(idx_width));
76  shape.set(1, output->info()->dimension(idx_height), false);
77 
78  const TensorInfo tensor_info_dxdy(shape, Format::F32);
79  const TensorInfo tensor_info_offsets(shape, Format::S32);
80 
81  _impl->dx.allocator()->init(tensor_info_dxdy);
82  _impl->dy.allocator()->init(tensor_info_dxdy);
83  _impl->offsets.allocator()->init(tensor_info_offsets);
84  switch(policy_to_use)
85  {
87  {
88  // Allocate once the configure methods have been called
89  _impl->offsets.allocator()->allocate();
90  break;
91  }
93  {
94  // Allocate once the configure methods have been called
95  _impl->dx.allocator()->allocate();
96  _impl->dy.allocator()->allocate();
97  _impl->offsets.allocator()->allocate();
98  break;
99  }
101  {
102  break;
103  }
104  default:
105  ARM_COMPUTE_ERROR("Unsupported interpolation mode");
106  }
107 }
InterpolationPolicy
Interpolation method.
Definition: Types.h:411
InterpolationPolicy interpolation_policy
Interpolation type to use.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 F32 per channel
Output values are defined by bilinear interpolation between the pixels.
bool align_corners
Align corners of input and output.
Output values are defined to match the source pixel whose center is nearest to the sample position...
bool is_align_corners_allowed_sampling_policy(SamplingPolicy sampling_policy)
Returns if aligned corners are allowed for the given sampling policy.
Definition: ScaleUtils.h:52
1 channel, 1 S32 per channel
SamplingPolicy sampling_policy
Sampling policy used by the interpolation.
Output values are determined by averaging the source pixels whose areas fall under the area of the de...
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
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
#define ARM_COMPUTE_LOG_PARAMS(...)
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
DataLayout data_layout
Data layout to use.
DataLayout
[DataLayout enum definition]
Definition: Types.h:113

◆ operator=() [1/2]

NEScale& operator= ( const NEScale )
delete

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

◆ operator=() [2/2]

NEScale& operator= ( NEScale &&  )
delete

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For CPU 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 114 of file NEScale.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, ITensorPack::add_tensor(), and arm_compute::test::validation::pack.

115 {
116  ITensorPack pack;
117  pack.add_tensor(TensorType::ACL_SRC, _impl->src);
118  pack.add_tensor(TensorType::ACL_DST, _impl->dst);
119  pack.add_tensor(TensorType::ACL_INT_0, &_impl->dx);
120  pack.add_tensor(TensorType::ACL_INT_1, &_impl->dy);
121  pack.add_tensor(TensorType::ACL_INT_2, &_impl->offsets);
122  _impl->op->run(pack);
123 }
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:39

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const ScaleKernelInfo info 
)
static

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

Parameters
[in]inputSource tensor. Data type supported: QASYMM8/QASYMM8_SIGNED/U8/S16/F16/F32. (Written to only for border_mode != UNDEFINED)
[in]outputDestination tensor. Data type 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 be used for validation
Returns
a status

Definition at line 109 of file NEScale.cpp.

References CpuScale::validate().

Referenced by arm_compute::test::validation::TEST_CASE().

110 {
111  return cpu::CpuScale::validate(input, output, info);
112 }
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const ScaleKernelInfo &info)
Static function to check if given info will lead to a valid configuration.
Definition: CpuScale.cpp:149
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)

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