42 inline std::tuple<float, float> calculate_scale_factors(
const ITensorInfo *
src,
const ITensorInfo *
dst,
DataLayout data_layout,
bool align_corners)
48 const unsigned int src_width = src->dimension(idx_width);
49 const unsigned int src_height = src->dimension(idx_height);
50 const unsigned int dst_width = dst->dimension(idx_width);
51 const unsigned int dst_height = dst->dimension(idx_height);
56 return std::make_tuple(scale_x, scale_y);
73 std::tie(scale_x, scale_y) = calculate_scale_factors(src, dst, data_layout, info.align_corners);
104 std::tie(scale_x, scale_y) = calculate_scale_factors(src, dst, _data_layout, info.
align_corners);
117 const unsigned int src_width = src->
dimension(idx_width);
118 const unsigned int src_height = src->
dimension(idx_height);
119 const unsigned int dst_width = dst->
dimension(idx_width);
120 const unsigned int dst_channels = dst->
dimension(idx_channel);
121 unsigned int vec_size = 0;
122 unsigned int vec_size_leftover = 0;
128 vec_size_leftover = dst_channels % vec_size;
129 build_opts.
add_option(
"-DSRC_TENSOR_TYPE=BUFFER");
131 build_opts.
add_option(
"-DDST_TENSOR_TYPE=BUFFER");
147 vec_size_leftover = dst_width % vec_size;
162 if(is_qasymm_bilinear)
175 std::transform(interpolation_name.begin(), interpolation_name.end(), interpolation_name.begin(),
::tolower);
176 std::string
kernel_name =
"scale_" + interpolation_name +
"_";
183 ICLKernel::configure_internal(win);
191 _kernel.setArg<cl_float>(idx++,
scale_x);
192 _kernel.setArg<cl_float>(idx++,
scale_y);
195 _config_id =
"scale_";
198 _config_id += (is_nhwc ?
"nhwc" :
"nchw");
225 unsigned int idx = 0;
238 unsigned int idx = 0;
void add_4d_tensor_nhwc_argument(unsigned int &idx, const ICLTensor *tensor)
Add the passed NHWC 4D tensor's parameters to the object's kernel's arguments by passing strides...
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Window first_slice_window_2D() const
First 2D slice of the window.
BorderMode border_mode
Border mode policy.
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
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.
InterpolationPolicy interpolation_policy
Interpolation type to use.
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(...)
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
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.
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.
bool align_corners
Align corners of input and output.
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.
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
SimpleTensor< float > src
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Copyright (c) 2017-2023 Arm Limited.
1 channel, 1 F16 per channel
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.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
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.
SamplingPolicy sampling_policy
Sampling policy used by the interpolation.
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
quantized, asymmetric fixed-point 8-bit number unsigned
Class to describe a number of elements in each dimension.
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.
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
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.
Elementwise CL kernel type.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue...
void configure(const CLCompileContext &compile_context, ITensorInfo *src, ITensorInfo *dst, const ScaleKernelInfo &info)
Initialise the kernel's inputs, output and interpolation policy.
#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.
static constexpr unsigned int num_arguments_per_4d_tensor_nhwc()
Returns the number of arguments enqueued per NHWC 4D Tensor object.
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)
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
Pixels outside the image are assumed to have the same value as the closest image pixel.
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.
Window first_slice_window_4D() const
First 4D slice of the window.
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.
unsigned int adjust_vec_size(unsigned int vec_size, size_t dim0)
Returns the adjusted vector size in case it is less than the input's first dimension, getting rounded down to its closest valid vector size.
quantized, asymmetric fixed-point 8-bit number signed
DataLayout data_layout
Data layout to use.
DataLayout
[DataLayout enum definition]
Describe a multidimensional execution window.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
#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.