46 constexpr
auto window_step = 16;
61 inline float32x4x4_t load_value(
const T *input_ptr)
64 return arm_compute::convert_to_float32x4x4<Tx16_t>(
wrapper::vloadq(input_ptr));
68 inline float32x4x4_t load_value(
const float *input_ptr)
75 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 77 inline float32x4x4_t load_value(
const float16_t *input_ptr)
85 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 87 template <
typename element_type>
88 using vector_type = wrapper::traits::neon_vector_t<element_type, window_step>;
90 template <
typename quantized_type>
91 vector_type<quantized_type> vquantize_qasymm8(
const float32x4x4_t &qv,
const UniformQuantizationInfo &qi);
94 vector_type<uint8_t> vquantize_qasymm8<uint8_t>(
const float32x4x4_t &qv,
const UniformQuantizationInfo &qi)
100 vector_type<int8_t> vquantize_qasymm8<int8_t>(
const float32x4x4_t &qv,
const UniformQuantizationInfo &qi)
108 : _input(nullptr), _output(nullptr), _func(nullptr)
120 static const std::map<std::string, QuantizationFunctionExecutorPtr> quant_map =
122 {
"op_QASYMM8_QASYMM8", &NEQuantizationLayerKernel::run_quantize_qasymm8<uint8_t, uint8_t> },
123 {
"op_QASYMM8_QASYMM8_SIGNED", &NEQuantizationLayerKernel::run_quantize_qasymm8<uint8_t, int8_t> },
124 {
"op_QASYMM8_QASYMM16", &NEQuantizationLayerKernel::run_quantize_qasymm16<uint8_t> },
126 {
"op_QASYMM8_SIGNED_QASYMM8", &NEQuantizationLayerKernel::run_quantize_qasymm8<int8_t, uint8_t> },
127 {
"op_QASYMM8_SIGNED_QASYMM8_SIGNED", &NEQuantizationLayerKernel::run_quantize_qasymm8<int8_t, int8_t> },
128 {
"op_QASYMM8_SIGNED_QASYMM16", &NEQuantizationLayerKernel::run_quantize_qasymm16<int8_t> },
130 {
"op_F32_QASYMM8", &NEQuantizationLayerKernel::run_quantize_qasymm8<float, uint8_t> },
131 {
"op_F32_QASYMM8_SIGNED", &NEQuantizationLayerKernel::run_quantize_qasymm8<float, int8_t> },
132 {
"op_F32_QASYMM16", &NEQuantizationLayerKernel::run_quantize_qasymm16<float> },
134 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 135 {
"op_F16_QASYMM8", &NEQuantizationLayerKernel::run_quantize_qasymm8<float16_t, uint8_t> },
136 {
"op_F16_QASYMM8_SIGNED", &NEQuantizationLayerKernel::run_quantize_qasymm8<float16_t, int8_t> },
137 {
"op_F16_QASYMM16", &NEQuantizationLayerKernel::run_quantize_qasymm16<float16_t> },
141 std::string function_to_call(
"op_");
145 auto it = quant_map.find(function_to_call);
147 if(it == quant_map.end())
160 INEKernel::configure(win_config);
169 template <
typename TIn,
typename TOut>
170 void NEQuantizationLayerKernel::run_quantize_qasymm8(
const Window &
window)
172 const auto window_start_x =
static_cast<int>(window.
x().
start());
173 const auto window_end_x =
static_cast<int>(window.
x().
end());
192 Iterator output(_output, win_collapsed);
195 auto input_ptr =
reinterpret_cast<const TIn *
>(input.
ptr());
196 auto output_ptr =
reinterpret_cast<TOut *
>(output.
ptr());
198 int x = window_start_x;
199 for(; x <= (window_end_x - window_step); x += window_step)
201 wrapper::vstore(&output_ptr[x], vquantize_qasymm8<TOut>(load_value(&input_ptr[x]), uqinfo));
204 for(; x < window_end_x; ++x)
212 template <
typename T>
213 void NEQuantizationLayerKernel::run_quantize_qasymm16(
const Window &window)
215 const auto window_start_x =
static_cast<int>(window.
x().
start());
216 const auto window_end_x =
static_cast<int>(window.
x().
end());
235 Iterator output(_output, win_collapsed);
238 auto input_ptr =
reinterpret_cast<const T *
>(input.
ptr());
239 auto output_ptr =
reinterpret_cast<uint16_t *
>(output.
ptr());
241 int x = window_start_x;
242 for(; x <= (window_end_x - window_step); x += window_step)
245 vst1q_u16(&output_ptr[x], tmp.val[0]);
246 vst1q_u16(&output_ptr[x + 8], tmp.val[1]);
249 for(; x < window_end_x; ++x)
264 (this->*_func)(window);
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)
const Window & window() const
The maximum window the kernel can be executed on.
uint16x8x2_t vquantize_qasymm16(const float32x4x4_t &qv, const UniformQuantizationInfo &qi)
Quantize to QASYMM16 a neon vector holding 16 floating point values.
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
void configure(const ITensor *input, ITensor *output)
Set the input, output.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
uint8x16_t vloadq(const uint8_t *ptr)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NEQuantizationLayerKerne...
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
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.
quantized, asymmetric fixed-point 16-bit number
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
decltype(strategy::transforms) typedef type
Interface for Neon tensor.
Copyright (c) 2017-2021 Arm Limited.
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
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.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
quantized, asymmetric fixed-point 8-bit number unsigned
Class to describe a number of elements in each dimension.
NEQuantizationLayerKernel()
Default constructor.
UniformQuantizationInfo uniform() const
Return per layer quantization info.
RoundingPolicy
Rounding method.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
constexpr uint8_t * ptr() const
Return a pointer to the current pixel.
UniformQuantizationInfo compute_requantization_scale_offset(const UniformQuantizationInfo &uqinfo_in, const UniformQuantizationInfo &uqinfo_out)
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Rounds to nearest value; half rounds to nearest even.
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_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
uint8x8_t vquantize(const float32x4x2_t &qv, const UniformQuantizationInfo &qi)
Quantize a neon vector holding 8 floating point values.
uint8x8_t vload(const uint8_t *ptr)
void vstore(uint8_t *ptr, uint8x8_t val)
#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...
void set_num_dimensions(size_t num_dimensions)
Set number of dimensions.
quantized, asymmetric fixed-point 8-bit number signed
Includes all wrapper headers at once.
int8x8_t vquantize_signed(const float32x4x2_t &qv, const UniformQuantizationInfo &qi)
Quantize a neon vector holding 8 floating point values.
Container for valid region of a window.
constexpr int end() const
Return the end of the dimension.
Iterator updated by execute_window_loop for each window element.
static QUANTIZED_TYPE quantize(float value, const UniformQuantizationInfo &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given a 8-bit asymmetric quantization scheme.
Truncates the least significant values that are lost in operations.
constexpr int start() const
Return the start of the dimension.
Describe a multidimensional execution window.
uint16_t quantize_qasymm16(float value, const UniformQuantizationInfo &qinfo, RoundingPolicy rounding_policy=RoundingPolicy::TO_NEAREST_UP)
Quantize a value given a 16-bit asymmetric quantization scheme.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
constexpr const Dimension & x() const
Alias to access the first dimension of the window.