24.02.1
|
Go to the documentation of this file.
50 constexpr
auto window_step = 16;
67 inline float32x4x4_t load_value(
const T *input_ptr)
70 return arm_compute::convert_to_float32x4x4<Tx16_t>(
wrapper::vloadq(input_ptr));
74 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)
87 #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
89 template <
typename element_type>
90 using vector_type = wrapper::traits::neon_vector_t<element_type, window_step>;
92 template <
typename quantized_type>
93 vector_type<quantized_type> vquantize_qasymm8(
const float32x4x4_t &qv,
const UniformQuantizationInfo &qi);
96 vector_type<uint8_t> vquantize_qasymm8<uint8_t>(
const float32x4x4_t &qv,
const UniformQuantizationInfo &qi)
102 vector_type<int8_t> vquantize_qasymm8<int8_t>(
const float32x4x4_t &qv,
const UniformQuantizationInfo &qi)
114 static const std::map<std::string, QuantizeFunctionExecutorPtr> quant_map = {
115 {
"op_QASYMM8_QASYMM8", &CpuQuantizeKernel::run_quantize_qasymm8<uint8_t, uint8_t>},
116 {
"op_QASYMM8_QASYMM8_SIGNED", &CpuQuantizeKernel::run_quantize_qasymm8<uint8_t, int8_t>},
117 {
"op_QASYMM8_QASYMM16", &CpuQuantizeKernel::run_quantize_qasymm16<uint8_t>},
119 {
"op_QASYMM8_SIGNED_QASYMM8", &CpuQuantizeKernel::run_quantize_qasymm8<int8_t, uint8_t>},
120 {
"op_QASYMM8_SIGNED_QASYMM8_SIGNED", &CpuQuantizeKernel::run_quantize_qasymm8<int8_t, int8_t>},
121 {
"op_QASYMM8_SIGNED_QASYMM16", &CpuQuantizeKernel::run_quantize_qasymm16<int8_t>},
123 {
"op_F32_QSYMM8", &CpuQuantizeKernel::run_quantize_qsymm8<float, int8_t>},
125 {
"op_F32_QASYMM8", &CpuQuantizeKernel::run_quantize_qasymm8<float, uint8_t>},
126 {
"op_F32_QASYMM8_SIGNED", &CpuQuantizeKernel::run_quantize_qasymm8<float, int8_t>},
127 {
"op_F32_QASYMM16", &CpuQuantizeKernel::run_quantize_qasymm16<float>},
129 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
130 {
"op_F16_QASYMM8", &CpuQuantizeKernel::run_quantize_qasymm8<float16_t, uint8_t>},
131 {
"op_F16_QASYMM8_SIGNED", &CpuQuantizeKernel::run_quantize_qasymm8<float16_t, int8_t>},
132 {
"op_F16_QASYMM16", &CpuQuantizeKernel::run_quantize_qasymm16<float16_t>},
136 std::string function_to_call(
"op_");
140 auto it = quant_map.find(function_to_call);
142 if (it == quant_map.end())
150 ICpuKernel::configure(win_config);
159 template <
typename TIn,
typename TOut>
162 const auto window_start_x =
static_cast<int>(
window.
x().
start());
163 const auto window_end_x =
static_cast<int>(
window.
x().
end());
181 auto input_ptr =
reinterpret_cast<const TIn *
>(
input.ptr());
182 auto output_ptr =
reinterpret_cast<TOut *
>(output.ptr());
183 int x = window_start_x;
184 for (; x <= (window_end_x - window_step); x += window_step)
186 wrapper::vstore(&output_ptr[x], vquantize_qasymm8<TOut>(load_value(&input_ptr[x]), uqinfo));
189 for (; x < window_end_x; ++x)
197 template <
typename TIn,
typename TOut>
198 void CpuQuantizeKernel::run_quantize_qasymm8(
const ITensor *
src, ITensor *
dst,
const Window &window)
200 const auto window_start_x =
static_cast<int>(
window.
x().
start());
201 const auto window_end_x =
static_cast<int>(
window.
x().
end());
203 const UniformQuantizationInfo uqinfo_in =
src->info()->quantization_info().uniform();
204 UniformQuantizationInfo uqinfo =
dst->info()->quantization_info().uniform();
220 Iterator output(
dst, win_collapsed);
223 [&](
const Coordinates &)
225 auto input_ptr =
reinterpret_cast<const TIn *
>(
input.ptr());
226 auto output_ptr =
reinterpret_cast<TOut *
>(output.ptr());
228 int x = window_start_x;
229 for (; x <= (window_end_x - window_step); x += window_step)
231 wrapper::vstore(&output_ptr[x], vquantize_qasymm8<TOut>(load_value(&input_ptr[x]), uqinfo));
234 for (; x < window_end_x; ++x)
242 template <
typename T>
243 void CpuQuantizeKernel::run_quantize_qasymm16(
const ITensor *
src, ITensor *
dst,
const Window &window)
245 const auto window_start_x =
static_cast<int>(
window.
x().
start());
246 const auto window_end_x =
static_cast<int>(
window.
x().
end());
248 const UniformQuantizationInfo uqinfo_in =
src->info()->quantization_info().uniform();
249 UniformQuantizationInfo uqinfo =
dst->info()->quantization_info().uniform();
265 Iterator output(
dst, win_collapsed);
268 [&](
const Coordinates &)
270 auto input_ptr =
reinterpret_cast<const T *
>(
input.ptr());
271 auto output_ptr =
reinterpret_cast<uint16_t *
>(output.ptr());
273 int x = window_start_x;
274 for (; x <= (window_end_x - window_step); x += window_step)
277 vst1q_u16(&output_ptr[x], tmp.val[0]);
278 vst1q_u16(&output_ptr[x + 8], tmp.val[1]);
281 for (; x < window_end_x; ++x)
303 return "CpuQuantizeKernel";
Class to describe a number of elements in each dimension.
@ QASYMM16
quantized, asymmetric fixed-point 16-bit number
constexpr int start() const
Return the start of the dimension.
SimpleTensor< float > src
decltype(strategy::transforms) typedef type
void configure(const ITensorInfo *src, ITensorInfo *dst)
Set the input, output.
@ TO_NEAREST_EVEN
Rounds to nearest value; half rounds to nearest even.
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
uint16x8x2_t vquantize_qasymm16(const float32x4x4_t &qv, const UniformQuantizationInfo &qi)
Quantize to QASYMM16 a neon vector holding 16 floating point values.
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
int8_t quantize_qsymm8(float value, const QuantizationInfo &qinfo)
Quantize a value given a 8-bit symmetric quantization scheme.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
@ QSYMM8
quantized, symmetric fixed-point 8-bit number
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.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Interface for CPU tensor.
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
uint8x16_t vloadq(const uint8_t *ptr)
Includes all wrapper headers at once.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
UniformQuantizationInfo compute_requantization_scale_offset(const UniformQuantizationInfo &uqinfo_in, const UniformQuantizationInfo &uqinfo_out)
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
static QUANTIZED_TYPE quantize(float value, const UniformQuantizationInfo &qinfo)
Quantize a value given a 8-bit asymmetric quantization scheme.
RoundingPolicy
Rounding method.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
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...
Iterator updated by execute_window_loop for each window element.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
#define ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Describe one of the image's dimensions with a start, end and step.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
const Window & window() const
The maximum window the kernel can be executed on.
Information about executing thread and CPU.
void vstore(uint8_t *ptr, uint8x8_t val)
Describe a multidimensional execution window.
uint8x8_t vquantize(const float32x4x2_t &qv, const UniformQuantizationInfo &qi)
Quantize a neon vector holding 8 floating point values.
Copyright (c) 2017-2024 Arm Limited.
const char * name() const override
Name of the kernel.
@ TO_ZERO
Truncates the least significant values that are lost in operations.
@ F16
16-bit floating-point number
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
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.
uint8x8_t vload(const uint8_t *ptr)
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Store the tensor's metadata.
@ F32
32-bit floating-point number
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
constexpr int end() const
Return the end of the dimension.
int8x8_t vquantize_signed(const float32x4x2_t &qv, const UniformQuantizationInfo &qi)
Quantize a neon vector holding 8 floating point values.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.