47 Status
validate_arguments(
const ITensorInfo *
input,
const ITensorInfo *bias,
const ITensorInfo *output,
int min,
int max)
60 if(output->total_size() != 0)
69 std::pair<Status, Window> validate_and_configure_window(ITensorInfo *
input, ITensorInfo *output)
79 return std::make_pair(Status{}, win);
88 template <
bool is_bounded_relu>
91 const int32x4_t result_offset_after_shift_s32 = vdupq_n_s32(_result_offset_after_shift);
92 const uint8x16_t min_u8 = vdupq_n_u8(static_cast<uint8_t>(_min));
93 const uint8x16_t max_u8 = vdupq_n_u8(static_cast<uint8_t>(_max));
98 const int window_step_x = 16;
99 const auto window_start_x = static_cast<int>(
window.
x().
start());
100 const auto window_end_x = static_cast<int>(
window.
x().
end());
106 Iterator out(_output, win_collapsed);
117 int x = window_start_x;
118 for(; x <= (window_end_x - window_step_x); x += window_step_x)
123 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 0),
124 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 4),
125 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 8),
126 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 12)
130 const int32x4x4_t bias_s32 =
133 vld1q_s32(reinterpret_cast<const int32_t *>(bias.ptr()) + x + 0),
134 vld1q_s32(reinterpret_cast<const int32_t *>(bias.ptr()) + x + 4),
135 vld1q_s32(reinterpret_cast<const int32_t *>(bias.ptr()) + x + 8),
136 vld1q_s32(reinterpret_cast<const int32_t *>(bias.ptr()) + x + 12)
141 in_s32.val[0] = vaddq_s32(in_s32.val[0], bias_s32.val[0]);
142 in_s32.val[1] = vaddq_s32(in_s32.val[1], bias_s32.val[1]);
143 in_s32.val[2] = vaddq_s32(in_s32.val[2], bias_s32.val[2]);
144 in_s32.val[3] = vaddq_s32(in_s32.val[3], bias_s32.val[3]);
146 vst1q_u8(out.ptr() + x,
finalize_quantization(in_s32, _result_fixedpoint_multiplier, _result_shift, result_offset_after_shift_s32, min_u8, max_u8, is_bounded_relu));
150 for(; x < window_end_x; ++x)
152 const int32_t bias_value = *(reinterpret_cast<const int32_t *>(bias.ptr()) + x);
153 int32_t in_value = *(reinterpret_cast<const int32_t *>(in.ptr()) + x);
156 in_value += bias_value;
158 *(out.ptr() + x) =
finalize_quantization(in_value, _result_fixedpoint_multiplier, _result_shift, _result_offset_after_shift, static_cast<uint8_t>(_min), static_cast<uint8_t>(_max), is_bounded_relu);
168 int x = window_start_x;
169 for(; x <= (window_end_x - window_step_x); x += window_step_x)
174 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 0),
175 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 4),
176 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 8),
177 vld1q_s32(reinterpret_cast<const int32_t *>(in.ptr()) + x + 12)
181 vst1q_u8(out.ptr() + x,
finalize_quantization(in_s32, _result_fixedpoint_multiplier, _result_shift, result_offset_after_shift_s32, min_u8, max_u8, is_bounded_relu));
185 for(; x < window_end_x; ++x)
187 const int32_t in_value = *(reinterpret_cast<const int32_t *>(in.ptr()) + x);
190 *(out.ptr() + x) =
finalize_quantization(in_value, _result_fixedpoint_multiplier, _result_shift, _result_offset_after_shift, static_cast<uint8_t>(_min), static_cast<uint8_t>(_max), is_bounded_relu);
198 : _func(nullptr), _input(nullptr), _bias(nullptr), _output(nullptr), _result_fixedpoint_multiplier(0), _result_shift(0), _result_offset_after_shift(0), _min(0), _max(0)
203 int result_offset_after_shift,
int min,
int max)
212 _result_fixedpoint_multiplier = result_fixedpoint_multiplier;
213 _result_shift = result_shift;
214 _result_offset_after_shift = result_offset_after_shift;
219 auto win_config = validate_and_configure_window(
input->info(), output->
info());
221 INEKernel::configure(win_config.second);
224 const bool is_bounded_relu = !(min <= 0 && max >= 255);
225 _func = is_bounded_relu ? &NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run<true> : &NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel::run<false>;
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.
void configure(const ITensor *input, const ITensor *bias, ITensor *output, 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.
NEGEMMLowpQuantizeDownInt32ToUint8ScaleByFixedPointKernel()
Constructor.
#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)
Describe one of the image's dimensions with a start, end and step.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Interface for CPU tensor.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 S32 per channel
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
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.
quantized, asymmetric fixed-point 8-bit number unsigned
static Status validate(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, int min=0, int max=0)
Static function to check if given info will lead to a valid configuration of NEGEMMLowpQuantizeDownIn...
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.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
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,...)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#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...
constexpr int end() const
Return the end of the dimension.
Iterator updated by execute_window_loop for each window element.
constexpr int start() const
Return the start of the dimension.
Describe a multidimensional execution window.
wrapper::traits::neon_vector< T, 16 >::type finalize_quantization(int32x4x4_t &in_s32, int32x4_t result_shift_s32, typename wrapper::traits::neon_vector< T, 16 >::type min, typename wrapper::traits::neon_vector< T, 16 >::type max)
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
constexpr const Dimension & x() const
Alias to access the first dimension of the window.