24 #ifndef SRC_CORE_NEON_KERNELS_SCALE_LIST_H 25 #define SRC_CORE_NEON_KERNELS_SCALE_LIST_H 40 #define DECLARE_SCALE_KERNEL(func_name) \ 41 void func_name(const ITensor *src, ITensor *dst, const ITensor *offsets, const ITensor *dx, const ITensor *dy, \ 42 InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, float sampling_offset, \ 43 bool align_corners, const Window &window) 48 #undef DECLARE_SCALE_KERNEL 52 bool align_corners,
const Window &window)
54 const size_t in_stride_c =
src->info()->dimension(0) +
src->info()->padding().left +
src->info()->padding().right;
55 const size_t in_stride_w =
src->info()->dimension(1) +
src->info()->padding().top +
src->info()->padding().bottom;
56 const size_t in_stride_wc = in_stride_w * in_stride_c;
57 const size_t in_dim_h =
src->info()->dimension(2);
61 const auto window_start_x = static_cast<int32_t>(window.
x().
start());
62 const auto window_end_x = static_cast<int32_t>(window.
x().
end());
63 const int window_step_x = 16 /
sizeof(T);
69 const uint8_t *in_ptr_start =
src->buffer() +
src->info()->offset_first_element_in_bytes();
70 const unsigned int in_stride_bytes_hwc =
src->info()->strides_in_bytes()[3];
76 const int offset_row = in_hi * in_stride_wc;
77 int32_t x = window_start_x;
78 const T *in_ptr = reinterpret_cast<const T *>(in_ptr_start + in_stride_bytes_hwc *
id[3]);
80 for(; x <= window_end_x - window_step_x; x += window_step_x)
85 for(; x < window_end_x; ++x)
87 *(reinterpret_cast<T *>(out.
ptr()) + x) = *(in_ptr +
offset + offset_row + x);
96 bool align_corners,
const Window &window)
102 const int in_stride_c =
src->info()->dimension(0) +
src->info()->padding().left +
src->info()->padding().right;
103 const int in_dim_w =
src->info()->dimension(1);
104 const int in_dim_h =
src->info()->dimension(2);
105 const int in_stride_wc = in_stride_c * (in_dim_w +
src->info()->padding().top +
src->info()->padding().bottom);
116 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 117 using ConstType =
typename std::conditional<std::is_same<T, float16_t>::value,
half, T>
::type;
121 const T const_border_value = static_cast<T>(constant_border_value.
get<ConstType>());
127 const int32_t in_hi = std::floor((
id.z() + sampling_offset) * hr - sampling_offset);
128 const T *in_ptr = reinterpret_cast<const T *>(in.
ptr()) +
offset * in_stride_c + in_hi * in_stride_wc;
130 const auto a00 = (0 <=
offset &&
offset < in_dim_w && 0 <= in_hi && in_hi < in_dim_h) ? *in_ptr : const_border_value;
131 const auto a01 = (-1 <=
offset &&
offset < in_dim_w - 1 && 0 <= in_hi && in_hi < in_dim_h) ? *(in_ptr + in_stride_c) : const_border_value;
132 const auto a10 = (0 <=
offset &&
offset < in_dim_w && -1 <= in_hi && in_hi < in_dim_h - 1) ? *(in_ptr + in_stride_wc) : const_border_value;
133 const auto a11 = (-1 <=
offset &&
offset < in_dim_w - 1 && -1 <= in_hi && in_hi < in_dim_h - 1) ? *(in_ptr + in_stride_c + in_stride_wc) : const_border_value;
146 const int in_hi = std::floor((
id.z() + sampling_offset) * hr - sampling_offset);
148 auto clamped_w = utility::clamp<int>(
offset, 0, in_dim_w - 1);
149 auto clamped_w1 = utility::clamp<int>(
offset + 1, 0, in_dim_w - 1);
150 auto clamped_h = utility::clamp<int>(in_hi, 0, in_dim_h - 1);
151 auto clamped_h1 = utility::clamp<int>(in_hi + 1, 0, in_dim_h - 1);
153 const auto a00 = *(reinterpret_cast<const T *>(in.
ptr()) + clamped_w * in_stride_c + clamped_h * in_stride_wc);
154 const auto a01 = *(reinterpret_cast<const T *>(in.
ptr()) + clamped_w1 * in_stride_c + clamped_h * in_stride_wc);
155 const auto a10 = *(reinterpret_cast<const T *>(in.
ptr()) + clamped_w * in_stride_c + clamped_h1 * in_stride_wc);
156 const auto a11 = *(reinterpret_cast<const T *>(in.
ptr()) + clamped_w1 * in_stride_c + clamped_h1 * in_stride_wc);
168 template <
typename T>
171 bool align_corners,
const Window &window)
175 bilinear_neon_scale<T>(
src,
dst, offsets, dx, dy, border_mode, constant_border_value, sampling_offset, align_corners, window);
179 nearest_neon_scale<T>(
src,
dst, offsets, sampling_offset, align_corners, window);
BorderMode
Methods available to handle borders.
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Class describing the value of a pixel for any image format.
InterpolationPolicy
Interpolation method.
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
void get(uint8_t &v) const
Interpret the pixel value as a U8.
uint8x16_t vloadq(const uint8_t *ptr)
half_float::half half
16-bit floating point type
Output values are defined by bilinear interpolation between the pixels.
Describe one of the image's dimensions with a start, end and step.
void nearest_neon_scale(const ITensor *src, ITensor *dst, const ITensor *offsets, float sampling_offset, bool align_corners, const Window &window)
T round_half_away_from_zero(T value)
Round floating-point value with half value rounding away from zero.
Output values are defined to match the source pixel whose center is nearest to the sample position.
decltype(strategy::transforms) typedef type
Interface for CPU tensor.
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
void qasymm8_signed_neon_scale(const ITensor *src, ITensor *dst, const ITensor *offsets, const ITensor *dx, const ITensor *dy, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, float sampling_offset, bool align_corners, const Window &window)
#define DECLARE_SCALE_KERNEL(func_name)
constexpr uint8_t * ptr() const
Return a pointer to the current pixel.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
void bilinear_neon_scale(const ITensor *src, ITensor *dst, const ITensor *offsets, const ITensor *dx, const ITensor *dy, BorderMode border_mode, PixelValue constant_border_value, float sampling_offset, bool align_corners, const Window &window)
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Pixels outside the image are assumed to have the same value as the closest image pixel.
void vstore(uint8_t *ptr, uint8x8_t val)
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
void common_neon_scale(const ITensor *src, ITensor *dst, const ITensor *offsets, const ITensor *dx, const ITensor *dy, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, float sampling_offset, bool align_corners, const Window &window)
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.
Includes all wrapper headers at once.
constexpr int end() const
Return the end of the dimension.
Iterator updated by execute_window_loop for each window element.
float delta_bilinear(float a00, float a01, float a10, float a11, float dx_val, float dy_val)
Computes bilinear interpolation using the top-left, top-right, bottom-left, bottom-right pixels and t...
constexpr int start() const
Return the start of the dimension.
void qasymm8_neon_scale(const ITensor *src, ITensor *dst, const ITensor *offsets, const ITensor *dx, const ITensor *dy, InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value, float sampling_offset, bool align_corners, const Window &window)
Describe a multidimensional execution window.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.