Compute Library
 21.02
NEScale Class Reference

Basic function to run NEScaleKernel. More...

#include <NEScale.h>

Collaboration diagram for NEScale:
[legend]

Public Member Functions

 NEScale ()
 Constructor. More...
 
void configure (ITensor *input, ITensor *output, const ScaleKernelInfo &info)
 Initialize the function's source, destination, interpolation type and border_mode. More...
 
- Public Member Functions inherited from INESimpleFunctionNoBorder
 INESimpleFunctionNoBorder (IRuntimeContext *ctx=nullptr)
 Constructor. More...
 
 INESimpleFunctionNoBorder (const INESimpleFunctionNoBorder &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 INESimpleFunctionNoBorder (INESimpleFunctionNoBorder &&)=default
 Default move constructor. More...
 
INESimpleFunctionNoBorderoperator= (const INESimpleFunctionNoBorder &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
INESimpleFunctionNoBorderoperator= (INESimpleFunctionNoBorder &&)=default
 Default move assignment operator. More...
 
 ~INESimpleFunctionNoBorder ()
 Default destructor. More...
 
void run () override final
 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 run NEScaleKernel.

Definition at line 37 of file NEScale.h.

Constructor & Destructor Documentation

◆ NEScale()

NEScale ( )

Constructor.

Initialize NEScale

Definition at line 99 of file NEScale.cpp.

100  : _offsets(), _dx(), _dy()
101 {
102 }

Member Function Documentation

◆ configure()

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

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

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 104 of file NEScale.cpp.

References ScaleKernelInfo::align_corners, TensorAllocator::allocate(), Tensor::allocator(), arm_compute::AREA, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::BILINEAR, arm_compute::scale_utils::calculate_resize_ratio(), arm_compute::test::validation::data_layout, ScaleKernelInfo::data_layout, ITensorInfo::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, TensorAllocator::init(), 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, NEScale::validate(), and arm_compute::WIDTH.

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

105 {
107  ARM_COMPUTE_ERROR_THROW_ON(NEScale::validate(input->info(), output->info(), info));
108 
110 
111  // Get data layout and width/height indices
112  const DataLayout data_layout = info.data_layout == DataLayout::UNKNOWN ? input->info()->data_layout() : info.data_layout;
115 
116  // Get the tensor shape
117  TensorShape shape(output->info()->dimension(idx_width));
118  shape.set(1, output->info()->dimension(idx_height), false);
119 
120  // Compute the ratio between source width/height and destination width/height
121  const auto wr = arm_compute::scale_utils::calculate_resize_ratio(input->info()->dimension(idx_width), output->info()->dimension(idx_width), is_align_corners_used);
122  const auto hr = arm_compute::scale_utils::calculate_resize_ratio(input->info()->dimension(idx_height), output->info()->dimension(idx_height), is_align_corners_used);
123 
124  // Area interpolation behaves as Nearest Neighbour in case of up-sampling
125  const auto policy_to_use = (info.interpolation_policy == InterpolationPolicy::AREA && wr <= 1.f && hr <= 1.f) ? InterpolationPolicy::NEAREST_NEIGHBOR : info.interpolation_policy;
126 
127  auto scale_kernel = std::make_unique<NEScaleKernel>();
128  switch(policy_to_use)
129  {
131  {
132  TensorInfo tensor_info_offsets(shape, Format::S32);
133  _offsets.allocator()->init(tensor_info_offsets);
134 
135  scale_kernel->configure(input, nullptr, nullptr, &_offsets, output, info);
136 
137  // Allocate once the configure methods have been called
138  _offsets.allocator()->allocate();
139 
140  // Pre-compute offsets for nearest interpolation
141  precompute_dx_dy_offsets(nullptr, nullptr, &_offsets, wr, hr, info.sampling_policy, is_align_corners_used);
142  break;
143  }
145  {
146  TensorInfo tensor_info_offsets(shape, Format::S32);
147  TensorInfo tensor_info_dxdy(shape, Format::F32);
148 
149  _offsets.allocator()->init(tensor_info_offsets);
150  _dx.allocator()->init(tensor_info_dxdy);
151  _dy.allocator()->init(tensor_info_dxdy);
152 
153  scale_kernel->configure(input, &_dx, &_dy, &_offsets, output, info);
154 
155  // Allocate once the configure methods have been called
156  _offsets.allocator()->allocate();
157  _dx.allocator()->allocate();
158  _dy.allocator()->allocate();
159 
160  // Pre-compute dx, dy and offsets for bilinear interpolation
161  precompute_dx_dy_offsets(&_dx, &_dy, &_offsets, wr, hr, info.sampling_policy, is_align_corners_used);
162  break;
163  }
165  {
166  scale_kernel->configure(input, nullptr, nullptr, nullptr, output, info);
167  break;
168  }
169  default:
170  ARM_COMPUTE_ERROR("Unsupported interpolation mode");
171  }
172  _kernel = std::move(scale_kernel);
173 }
InterpolationPolicy interpolation_policy
Interpolation type to use.
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
#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.
const DataLayout data_layout
Definition: Im2Col.cpp:151
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...
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
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
1 channel, 1 S32 per channel
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.
Definition: NEScale.cpp:175
SamplingPolicy sampling_policy
Sampling policy used by the interpolation.
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
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)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
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.
DataLayout
[DataLayout enum definition]
Definition: Types.h:120

◆ 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 175 of file NEScale.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::BILINEAR, arm_compute::CENTER, ICloneable< T >::clone(), arm_compute::test::validation::data_layout, ScaleKernelInfo::data_layout, ITensorInfo::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, arm_compute::test::validation::info, ScaleKernelInfo::interpolation_policy, arm_compute::NEAREST_NEIGHBOR, arm_compute::S32, ScaleKernelInfo::sampling_policy, arm_compute::test::validation::shape, arm_compute::TOP_LEFT, arm_compute::UNKNOWN, NEScaleKernel::validate(), and arm_compute::WIDTH.

Referenced by NEScale::configure(), and arm_compute::test::validation::TEST_CASE().

176 {
179 
180  ITensorInfo *offsets = nullptr;
181  ITensorInfo *dx = nullptr;
182  ITensorInfo *dy = nullptr;
183 
184  // Get data layout and width/height indices
188 
189  // Get the tensor shape of auxilary buffers
190  const TensorShape shape(output->dimension(idx_width), output->dimension(idx_height));
191 
192  TensorInfo tensor_info_offsets(shape, Format::S32);
193  TensorInfo tensor_info_dx(shape, Format::F32);
194  TensorInfo tensor_info_dy(shape, Format::F32);
195 
196  switch(info.interpolation_policy)
197  {
199  offsets = &tensor_info_offsets;
200  break;
202  offsets = &tensor_info_offsets;
203  dx = &tensor_info_dx;
204  dy = &tensor_info_dy;
205  break;
206  default:
207  break;
208  }
209 
210  ARM_COMPUTE_RETURN_ON_ERROR(NEScaleKernel::validate(input->clone().get(), dx, dy, offsets, output->clone().get(), info));
211  return Status{};
212 }
InterpolationPolicy interpolation_policy
Interpolation type to use.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
1 channel, 1 F32 per channel
Output values are defined by bilinear interpolation between the pixels.
const DataLayout data_layout
Definition: Im2Col.cpp:151
Output values are defined to match the source pixel whose center is nearest to the sample position...
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
Samples are taken at pixel center.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
1 channel, 1 S32 per channel
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.
SamplingPolicy sampling_policy
Sampling policy used by the interpolation.
Samples are taken at pixel top left corner.
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
DataLayout data_layout
Data layout to use.
DataLayout
[DataLayout enum definition]
Definition: Types.h:120

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