| 49 | #ifdef __aarch64__ |
| 50 | |
| 51 | std::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); |
nothing calls this directly
no test coverage detected