49 Status validate_arguments(
const ITensorInfo *
src,
const ITensorInfo *bias,
const ITensorInfo *
dst,
int min,
int max)
63 if(dst->total_size() != 0)
73 template <
bool is_bounded_relu>
74 void CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel::run_internal(
const ITensor *src,
const ITensor *bias, ITensor *dst,
const Window &window)
76 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(_result_offset_after_shift);
77 const int8x16_t min_s8 = vdupq_n_s8(static_cast<int8_t>(_min));
78 const int8x16_t max_s8 = vdupq_n_s8(static_cast<int8_t>(_max));
82 const int window_step_x = 16;
83 const auto window_start_x =
static_cast<int>(window.x().start());
84 const auto window_end_x =
static_cast<int>(window.x().end());
86 Window win_collapsed = window.collapse_if_possible(window,
Window::DimZ);
87 win_collapsed.set(
Window::DimX, Window::Dimension(0, 1, 1));
89 Iterator in(src, win_collapsed);
90 Iterator out(dst, win_collapsed);
94 win_biases.set(
Window::DimX, Window::Dimension(0, 1, 1));
95 win_biases.set(
Window::DimY, Window::Dimension(0, 1, 1));
97 Iterator bias_i(bias, win_biases);
101 int x = window_start_x;
102 for(; x <= (window_end_x - window_step_x); x += window_step_x)
107 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 0),
108 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 4),
109 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 8),
110 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 12)
114 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)
125 in_s32.val[0] = vaddq_s32(in_s32.val[0], bias_s32.val[0]);
126 in_s32.val[1] = vaddq_s32(in_s32.val[1], bias_s32.val[1]);
127 in_s32.val[2] = vaddq_s32(in_s32.val[2], bias_s32.val[2]);
128 in_s32.val[3] = vaddq_s32(in_s32.val[3], bias_s32.val[3]);
130 vst1q_s8(reinterpret_cast<int8_t *>(out.ptr() + x),
131 finalize_quantization(in_s32, _result_fixedpoint_multiplier, _result_shift, result_offset_after_shift_s32, min_s8, max_s8, is_bounded_relu));
135 for(; x < window_end_x; ++x)
137 const int32_t bias_value = *(
reinterpret_cast<const int32_t *
>(bias_i.ptr()) + x);
138 int32_t in_value = *(
reinterpret_cast<const int32_t *
>(in.ptr()) + x);
141 in_value += bias_value;
143 *
reinterpret_cast<int8_t *
>(out.ptr() + x) =
finalize_quantization(in_value, _result_fixedpoint_multiplier, _result_shift, _result_offset_after_shift,
144 static_cast<int8_t>(_min),
static_cast<int8_t
>(_max), is_bounded_relu);
154 int x = window_start_x;
155 for(; x <= (window_end_x - window_step_x); x += window_step_x)
160 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 0),
161 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 4),
162 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 8),
163 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 12)
167 vst1q_s8(reinterpret_cast<int8_t *>(out.ptr() + x),
168 finalize_quantization(in_s32, _result_fixedpoint_multiplier, _result_shift, result_offset_after_shift_s32, min_s8, max_s8, is_bounded_relu));
172 for(; x < window_end_x; ++x)
174 const int32_t in_value = *(
reinterpret_cast<const int32_t *
>(in.ptr()) + x);
177 *
reinterpret_cast<int8_t *
>(out.ptr() + x) =
finalize_quantization(in_value, _result_fixedpoint_multiplier, _result_shift, _result_offset_after_shift,
178 static_cast<int8_t>(_min),
static_cast<int8_t
>(_max), is_bounded_relu);
186 int result_offset_after_shift,
int min,
int max)
193 _result_fixedpoint_multiplier = result_fixedpoint_multiplier;
194 _result_shift = result_shift;
195 _result_offset_after_shift = result_offset_after_shift;
204 ICpuKernel::configure(win_config);
207 const bool is_bounded_relu = !(min <= -128 && max >= 127);
208 _func = is_bounded_relu ? &CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel::run_internal<true> :
209 &CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel::run_internal<false>;
230 (this->*_func)(src, bias, dst, window);
235 return "CpuGemmLowpQuantizeDownInt32ToInt8ScaleByFixedPointKernel";
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
const Window & window() const
The maximum window the kernel can be executed on.
bool empty() const
Checks if pack is empty.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 S32 per channel
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.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Class to describe a number of elements in each dimension.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
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...
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
const char * name() const override
Name of the kernel.
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.
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.
Information about executing thread and CPU.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
#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_ERROR_ON_NULLPTR(...)
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...
quantized, asymmetric fixed-point 8-bit number signed
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.
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)