24.02.1
|
Go to the documentation of this file.
64 if (
dst->total_size() != 0)
74 template <
bool is_bounded_relu>
75 void CpuGemmLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run_internal(
const ITensor *
src,
80 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(_result_offset_after_shift);
81 const uint8x16_t min_u8 = vdupq_n_u8(
static_cast<uint8_t
>(_min));
82 const uint8x16_t max_u8 = vdupq_n_u8(
static_cast<uint8_t
>(_max));
87 const int window_step_x = 16;
88 const auto window_start_x =
static_cast<int>(
window.
x().
start());
89 const auto window_end_x =
static_cast<int>(
window.
x().
end());
94 Iterator in(
src, win_collapsed);
95 Iterator out(
dst, win_collapsed);
99 win_biases.set(
Window::DimX, Window::Dimension(0, 1, 1));
100 win_biases.set(
Window::DimY, Window::Dimension(0, 1, 1));
102 Iterator bias_i(
bias, win_biases);
105 [&](
const Coordinates &)
108 int x = window_start_x;
109 for (; x <= (window_end_x - window_step_x); x += window_step_x)
111 int32x4x4_t in_s32 = {{vld1q_s32(
reinterpret_cast<const int32_t *
>(in.ptr()) + x + 0),
112 vld1q_s32(
reinterpret_cast<const int32_t *
>(in.ptr()) + x + 4),
113 vld1q_s32(
reinterpret_cast<const int32_t *
>(in.ptr()) + x + 8),
114 vld1q_s32(
reinterpret_cast<const int32_t *
>(in.ptr()) + x + 12)}};
116 const int32x4x4_t bias_s32 = {
117 {vld1q_s32(
reinterpret_cast<const int32_t *
>(bias_i.ptr()) + x + 0),
118 vld1q_s32(
reinterpret_cast<const int32_t *
>(bias_i.ptr()) + x + 4),
119 vld1q_s32(
reinterpret_cast<const int32_t *
>(bias_i.ptr()) + x + 8),
120 vld1q_s32(
reinterpret_cast<const int32_t *
>(bias_i.ptr()) + x + 12)}};
123 in_s32.val[0] = vaddq_s32(in_s32.val[0], bias_s32.val[0]);
124 in_s32.val[1] = vaddq_s32(in_s32.val[1], bias_s32.val[1]);
125 in_s32.val[2] = vaddq_s32(in_s32.val[2], bias_s32.val[2]);
126 in_s32.val[3] = vaddq_s32(in_s32.val[3], bias_s32.val[3]);
128 vst1q_u8(out.ptr() + x,
130 result_offset_after_shift_s32, min_u8, max_u8, is_bounded_relu));
134 for (; x < window_end_x; ++x)
136 const int32_t bias_value = *(
reinterpret_cast<const int32_t *
>(bias_i.ptr()) + x);
137 int32_t in_value = *(
reinterpret_cast<const int32_t *
>(in.ptr()) + x);
140 in_value += bias_value;
143 _result_offset_after_shift,
static_cast<uint8_t
>(_min),
144 static_cast<uint8_t
>(_max), is_bounded_relu);
153 [&](
const Coordinates &)
156 int x = window_start_x;
157 for (; x <= (window_end_x - window_step_x); x += window_step_x)
159 int32x4x4_t in_s32 = {{vld1q_s32(
reinterpret_cast<const int32_t *
>(in.ptr()) + x + 0),
160 vld1q_s32(
reinterpret_cast<const int32_t *
>(in.ptr()) + x + 4),
161 vld1q_s32(
reinterpret_cast<const int32_t *
>(in.ptr()) + x + 8),
162 vld1q_s32(
reinterpret_cast<const int32_t *
>(in.ptr()) + x + 12)}};
164 vst1q_u8(out.ptr() + x,
166 result_offset_after_shift_s32, min_u8, max_u8, is_bounded_relu));
170 for (; x < window_end_x; ++x)
172 const int32_t in_value = *(
reinterpret_cast<const int32_t *
>(in.ptr()) + x);
176 _result_offset_after_shift,
static_cast<uint8_t
>(_min),
177 static_cast<uint8_t
>(_max), is_bounded_relu);
187 int result_fixedpoint_multiplier,
189 int result_offset_after_shift,
198 _result_fixedpoint_multiplier = result_fixedpoint_multiplier;
199 _result_shift = result_shift;
200 _result_offset_after_shift = result_offset_after_shift;
209 ICpuKernel::configure(win_config);
212 const bool is_bounded_relu = !(min <= 0 && max >= 255);
213 _func = is_bounded_relu ? &CpuGemmLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run_internal<true>
214 : &CpuGemmLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run_internal<false>;
243 return "CpuGemmLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel";
Class to describe a number of elements in each dimension.
static Status validate(const ITensorInfo *src, const ITensorInfo *bias, const ITensorInfo *dst, int min=0, int max=0)
Static function to check if given info will lead to a valid configuration.
void configure(ITensorInfo *src, ITensorInfo *bias, ITensorInfo *dst, int result_fixedpoint_multiplier, int result_shift, int result_offset_after_shift, int min=0, int max=0)
Initialise the kernel's input and output.
constexpr int start() const
Return the start of the dimension.
SimpleTensor< float > src
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
bool empty() const
Checks if pack is empty.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
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 run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
const Window & window() const
The maximum window the kernel can be executed on.
Information about executing thread and CPU.
Describe a multidimensional execution window.
Copyright (c) 2017-2024 Arm Limited.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
@ S32
signed 32-bit number
const char * name() const override
Name of the kernel.
Store the tensor's metadata.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
uint8x16_t finalize_quantization(int32x4x4_t &in_s32, int result_fixedpoint_multiplier, int32_t result_shift, int32x4_t result_offset_after_shift_s32, uint8x16_t min_u8, uint8x16_t max_u8, bool is_bounded_relu)
Performs final quantization step on 16 elements.
constexpr int end() const
Return the end of the dimension.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.