48 inline std::pair<float, float> calculate_scale_factors(
const ITensorInfo &
input,
const ITensorInfo &output,
const ScaleKernelInfo &
info)
55 const unsigned int input_width = input.dimension(idx_width);
56 const unsigned int input_height = input.dimension(idx_height);
57 const unsigned int output_width = output.dimension(idx_width);
58 const unsigned int output_height = output.dimension(idx_height);
63 return std::make_pair(wr, hr);
66 Status
validate_arguments(
const ITensorInfo *input,
const ITensorInfo *output,
const ScaleKernelInfo &info)
78 std::tie(wr, hr) = calculate_scale_factors(*input, *output, info);
85 std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output,
const ScaleKernelInfo &info, BorderSize &border)
88 bool window_changed{};
98 border = BorderSize(0);
101 num_elems_processed_per_iteration = 4;
104 AccessWindowStatic input_access(input,
105 -border.left, -border.top,
106 input->dimension(0) + border.right,
107 input->dimension(1) + border.bottom);
108 AccessWindowHorizontal output_access(output, 0, num_elems_processed_per_iteration);
111 output->tensor_shape(),
112 info.interpolation_policy,
113 info.sampling_policy,
130 return std::make_pair(err, win);
177 std::tie(wr, hr) = calculate_scale_factors(*input->
info(), *output->
info(),
info);
188 auto interpolation_policy_to_use = _interpolation_policy;
196 auto win_config = validate_and_configure_window(input->
info(), output->
info(),
info, border);
198 ICLKernel::configure_internal(win_config.second);
209 if(call_quantized_kernel)
216 std::transform(interpolation_name.begin(), interpolation_name.end(), interpolation_name.begin(),
::tolower);
217 std::string
kernel_name =
"scale_" + interpolation_name;
218 kernel_name += call_quantized_kernel ?
"_quantized_" :
"_";
224 const unsigned int input_width = input->
info()->
dimension(idx_width);
225 const unsigned int input_height = input->
info()->
dimension(idx_height);
229 _kernel.setArg<
float>(idx++, wr);
230 _kernel.setArg<
float>(idx++, hr);
233 _config_id =
"scale_";
236 _config_id += (is_nhwc ?
"nhwc" :
"nchw");
263 unsigned int idx = 0;
276 unsigned int idx = 0;
Window first_slice_window_2D() const
First 2D slice of the window.
BorderMode border_mode
Border mode policy.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
const Window & window() const
The maximum window the kernel can be executed on.
void configure(const ICLTensor *input, ICLTensor *output, const ScaleKernelInfo &info)
Initialise the kernel's inputs, output and interpolation policy.
InterpolationPolicy interpolation_policy
Interpolation type to use.
void enqueue(IGCKernel &kernel, const Window &window, const gles::NDRange &lws=gles::NDRange(1U, 1U, 1U))
Add the kernel to the command queue with the given window.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
Container for 2D border size.
BorderSize border_size() const override
The size of the border for that kernel.
const StringSet & options() const
Gets the current options list set.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
1 channel, 1 U8 per channel
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
Output values are defined by bilinear interpolation between the pixels.
const size_t input_height
std::string string_from_pixel_value(const PixelValue &value, const DataType data_type)
Convert a PixelValue to a string, represented through the specific data type.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
const DataLayout data_layout
bool align_corners
Align corners of input and output.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Output values are defined to match the source pixel whose center is nearest to the sample position...
std::string lower_string(const std::string &val)
Lower a given string.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 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 CLScaleKernel.
Samples are taken at pixel center.
bool is_align_corners_allowed_sampling_policy(SamplingPolicy sampling_policy)
Returns if aligned corners are allowed for the given sampling policy.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
void add_option(std::string option)
Adds option to the existing build option list.
Window collapse(const Window &full_window, size_t first, size_t last=Coordinates::num_max_dimensions) const
Collapse the dimensions between first and last.
std::string tolower(std::string string)
Convert string to lower case.
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
SamplingPolicy sampling_policy
Sampling policy used by the interpolation.
quantized, asymmetric fixed-point 8-bit number unsigned
const std::string & string_from_interpolation_policy(InterpolationPolicy policy)
Translates a given interpolation policy to a string.
UniformQuantizationInfo uniform() const
Return per layer quantization info.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
static constexpr unsigned int num_arguments_per_4D_tensor()
Returns the number of arguments enqueued per 4D tensor object.
const ICLTensor * output() const
Output tensor accessor.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
unsigned int right
right of the border
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
1 channel, 1 S16 per channel
Output values are determined by averaging the source pixels whose areas fall under the area of the de...
bool has_padding_changed(const std::unordered_map< const ITensorInfo *, PaddingSize > &padding_map)
Check if the previously stored padding info has changed after configuring a kernel.
Num samples, channels, height, width.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
ValidRegion calculate_valid_region_scale(const ITensorInfo &src_info, const TensorShape &dst_shape, InterpolationPolicy interpolate_policy, SamplingPolicy sampling_policy, bool border_undefined)
Helper function to calculate the Valid Region for Scale.
void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx...
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Interface for OpenCL tensor.
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)
Creates an error with a given message.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Borders are left undefined.
Pixels outside the image are assumed to have the same value as the closest image pixel.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context...
const QuantizationInfo qinfo
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Num samples, height, width, channels.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo *> infos)
Stores padding information before configuring a kernel.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
Wrapper to configure the Khronos OpenCL C++ header.
Window first_slice_window_4D() const
First 4D slice of the window.
unsigned int num_elems_processed_per_iteration
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue...
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.
quantized, asymmetric fixed-point 8-bit number signed
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
const ICLTensor * input() const
Input tensor accessor.
DataLayout data_layout
Data layout to use.
void add_4D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx...
DataLayout
[DataLayout enum definition]
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
void add_option_if_else(bool cond, std::string option_true, std::string option_false)
Adds first option if condition is true else the second one.