50 constexpr
auto window_step = 16;
52 Status validate_arguments(
const ITensorInfo *
src,
const ITensorInfo *
dst)
65 inline float32x4x4_t load_value(
const T *input_ptr)
68 return arm_compute::convert_to_float32x4x4<Tx16_t>(
wrapper::vloadq(input_ptr));
72 inline float32x4x4_t load_value(
const float *input_ptr)
79 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 81 inline float32x4x4_t load_value(
const float16_t *input_ptr)
89 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 91 template <
typename element_type>
92 using vector_type = wrapper::traits::neon_vector_t<element_type, window_step>;
94 template <
typename quantized_type>
95 vector_type<quantized_type> vquantize_qasymm8(
const float32x4x4_t &qv,
const UniformQuantizationInfo &qi);
98 vector_type<uint8_t> vquantize_qasymm8<uint8_t>(
const float32x4x4_t &qv,
const UniformQuantizationInfo &qi)
104 vector_type<int8_t> vquantize_qasymm8<int8_t>(
const float32x4x4_t &qv,
const UniformQuantizationInfo &qi)
116 static const std::map<std::string, QuantizeFunctionExecutorPtr> quant_map =
118 {
"op_QASYMM8_QASYMM8", &CpuQuantizeKernel::run_quantize_qasymm8<uint8_t, uint8_t> },
119 {
"op_QASYMM8_QASYMM8_SIGNED", &CpuQuantizeKernel::run_quantize_qasymm8<uint8_t, int8_t> },
120 {
"op_QASYMM8_QASYMM16", &CpuQuantizeKernel::run_quantize_qasymm16<uint8_t> },
122 {
"op_QASYMM8_SIGNED_QASYMM8", &CpuQuantizeKernel::run_quantize_qasymm8<int8_t, uint8_t> },
123 {
"op_QASYMM8_SIGNED_QASYMM8_SIGNED", &CpuQuantizeKernel::run_quantize_qasymm8<int8_t, int8_t> },
124 {
"op_QASYMM8_SIGNED_QASYMM16", &CpuQuantizeKernel::run_quantize_qasymm16<int8_t> },
126 {
"op_F32_QASYMM8", &CpuQuantizeKernel::run_quantize_qasymm8<float, uint8_t> },
127 {
"op_F32_QASYMM8_SIGNED", &CpuQuantizeKernel::run_quantize_qasymm8<float, int8_t> },
128 {
"op_F32_QASYMM16", &CpuQuantizeKernel::run_quantize_qasymm16<float> },
130 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 131 {
"op_F16_QASYMM8", &CpuQuantizeKernel::run_quantize_qasymm8<float16_t, uint8_t> },
132 {
"op_F16_QASYMM8_SIGNED", &CpuQuantizeKernel::run_quantize_qasymm8<float16_t, int8_t> },
133 {
"op_F16_QASYMM16", &CpuQuantizeKernel::run_quantize_qasymm16<float16_t> },
137 std::string function_to_call(
"op_");
141 auto it = quant_map.find(function_to_call);
143 if(it == quant_map.end())
151 ICpuKernel::configure(win_config);
160 template <
typename TIn,
typename TOut>
163 const auto window_start_x =
static_cast<int>(window.
x().
start());
164 const auto window_end_x =
static_cast<int>(window.
x().
end());
183 Iterator output(dst, win_collapsed);
186 auto input_ptr =
reinterpret_cast<const TIn *
>(input.
ptr());
187 auto output_ptr =
reinterpret_cast<TOut *
>(output.
ptr());
189 int x = window_start_x;
190 for(; x <= (window_end_x - window_step); x += window_step)
192 wrapper::vstore(&output_ptr[x], vquantize_qasymm8<TOut>(load_value(&input_ptr[x]), uqinfo));
195 for(; x < window_end_x; ++x)
203 template <
typename T>
204 void CpuQuantizeKernel::run_quantize_qasymm16(
const ITensor *src,
ITensor *dst,
const Window &window)
206 const auto window_start_x =
static_cast<int>(window.
x().
start());
207 const auto window_end_x =
static_cast<int>(window.
x().
end());
226 Iterator output(dst, win_collapsed);
229 auto input_ptr =
reinterpret_cast<const T *
>(input.
ptr());
230 auto output_ptr =
reinterpret_cast<uint16_t *
>(output.
ptr());
232 int x = window_start_x;
233 for(; x <= (window_end_x - window_step); x += window_step)
236 vst1q_u16(&output_ptr[x], tmp.val[0]);
237 vst1q_u16(&output_ptr[x + 8], tmp.val[1]);
240 for(; x < window_end_x; ++x)
257 (this->*_func)(src, dst, window);
262 return "CpuQuantizeKernel";
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)
#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.
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
1 channel, 1 F32 per channel
#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 CPU tensor.
SimpleTensor< float > src
Copyright (c) 2017-2021 Arm Limited.
static QUANTIZED_TYPE quantize(float value, const UniformQuantizationInfo &qinfo)
Quantize a value given a 8-bit asymmetric quantization scheme.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
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.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
quantized, asymmetric fixed-point 8-bit number unsigned
Class to describe a number of elements in each dimension.
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)
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
Rounds to nearest value; half rounds to nearest even.
Information about executing thread and CPU.
const char * name() const override
Name of the kernel.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
void configure(const ITensorInfo *src, ITensorInfo *dst)
Set the input, output.
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,...)
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...
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.
constexpr int end() const
Return the end of the dimension.
Iterator updated by execute_window_loop for each window element.
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.