From 8896cf7cb7df34c699e7453a0f0c683d1202ed15 Mon Sep 17 00:00:00 2001 From: Mohammed Suhail Munshi Date: Tue, 16 Jan 2024 15:52:39 +0000 Subject: Fix minor issue, clean lut code Resolves: [COMPMID-6799] Signed-off-by: Mohammed Suhail Munshi Change-Id: I47baeeea75f1d03609d1fa1e9a10d2f53d5694f7 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/10969 Benchmark: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Viet-Hoa Do Comments-Addressed: Arm Jenkins --- src/core/helpers/LUTManager.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/core/helpers/LUTManager.cpp b/src/core/helpers/LUTManager.cpp index 2f1746e31e..06e35eed8c 100644 --- a/src/core/helpers/LUTManager.cpp +++ b/src/core/helpers/LUTManager.cpp @@ -29,17 +29,22 @@ namespace arm_compute #ifdef __aarch64__ namespace { + void init_lut_fp16(ActivationLayerInfo::LookupTable65536 *lut) { - for (uint16_t i = 0; i < lut->size() - 1; ++i) + union Element + { + uint16_t i = 0; + float16_t fp; + } item; + // Fill lut by iterating over all 16 bit values using the union. + while (true) { - const float16_t *v = reinterpret_cast(&i); - (*lut)[i] = 1.f / (1.f + std::exp(-*v)); + (*lut)[item.i] = 1.f / (1.f + std::exp(-item.fp)); + if (item.i == 65535) + break; + item.i++; } - // Final value should be filled outside of loop to avoid overflows. - const uint16_t i = lut->size() - 1; - const float16_t *v = reinterpret_cast(&i); - (*lut)[i] = 1.f / (1.f + std::exp(-*v)); } } // namespace -- cgit v1.2.1