MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / q8_prepare_lut

Function q8_prepare_lut

src/cpu/kernels/CpuElementwiseUnaryKernel.cpp:51–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49#ifdef __aarch64__
50
51std::unique_ptr<uint8_t[]> q8_prepare_lut(ElementWiseUnary op, const ITensorInfo *src, const ITensorInfo *dst)
52{
53 ARM_COMPUTE_ERROR_ON(src->data_type() != dst->data_type());
54 ARM_COMPUTE_ERROR_ON(!is_data_type_quantized(src->data_type()));
55 ARM_COMPUTE_ERROR_ON(src->element_size() != 1);
56
57 auto lut = std::unique_ptr<uint8_t[]>(new uint8_t[256]);
58 const auto is_signed = src->data_type() == DataType::QASYMM8_SIGNED;
59 const auto src_qi = src->quantization_info().uniform();
60 const auto dst_qi = dst->quantization_info().uniform();
61
62 const auto dst_min_fp = (((is_signed) ? -128 : 0) - dst_qi.offset) * dst_qi.scale;
63 const auto dst_max_fp = (((is_signed) ? 127 : 255) - dst_qi.offset) * dst_qi.scale;
64
65 for (int i = 0; i < 256; ++i)
66 {
67 const auto in =
68 (is_signed) ? dequantize_qasymm8_signed(static_cast<int8_t>(i), src_qi) : dequantize_qasymm8(i, src_qi);
69 float result = 0;
70
71 switch (op)
72 {
73 case ElementWiseUnary::RSQRT:
74 result = 1 / sqrt(in);
75 break;
76
77 case ElementWiseUnary::EXP:
78 result = std::exp(in);
79 break;
80
81 case ElementWiseUnary::NEG:
82 result = -in;
83 break;
84
85 case ElementWiseUnary::LOG:
86 result = std::log(in);
87 break;
88
89 case ElementWiseUnary::ABS:
90 result = std::abs(in);
91 break;
92
93 case ElementWiseUnary::ROUND:
94 result = support::cpp11::nearbyint(in);
95 break;
96
97 case ElementWiseUnary::SIN:
98 result = std::sin(in);
99 break;
100
101 default:
102 ARM_COMPUTE_ERROR("NOT_SUPPORTED!");
103 }
104
105 result = utility::clamp(result, dst_min_fp, dst_max_fp);
106
107 const auto out = (is_signed) ? static_cast<uint8_t>(quantize_qasymm8_signed(result, dst_qi))
108 : quantize_qasymm8(result, dst_qi);

Callers

nothing calls this directly

Calls 15

is_data_type_quantizedFunction · 0.85
sqrtFunction · 0.85
expFunction · 0.85
logFunction · 0.85
absFunction · 0.85
sinFunction · 0.85
clampFunction · 0.85
quantize_qasymm8_signedFunction · 0.85
dequantize_qasymm8Function · 0.50
nearbyintFunction · 0.50
quantize_qasymm8Function · 0.50

Tested by

no test coverage detected