From 1b14c75c0d591c4abe4d2d41b7e4e165fbf58382 Mon Sep 17 00:00:00 2001 From: Sheri Zhang Date: Mon, 9 Mar 2020 14:29:52 +0000 Subject: COMPMID-2968: Add support for QASYMM8_SIGNED in CLGEMMLowpQuantizeDownInt32ToUint8ScaleByFloatKernel Signed-off-by: Sheri Zhang Change-Id: I37e6e76dbd5546c0eaedfacd01ea905c37148e8a Signed-off-by: Sheri Zhang Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/2861 Comments-Addressed: Arm Jenkins Reviewed-by: Michele Di Giorgio Tested-by: Arm Jenkins --- tests/validation/reference/GEMMLowp.cpp | 63 +++++++++++++++++++++++++++++++++ tests/validation/reference/GEMMLowp.h | 8 +++++ 2 files changed, 71 insertions(+) (limited to 'tests/validation/reference') diff --git a/tests/validation/reference/GEMMLowp.cpp b/tests/validation/reference/GEMMLowp.cpp index 99d08e34f1..61617c8aae 100644 --- a/tests/validation/reference/GEMMLowp.cpp +++ b/tests/validation/reference/GEMMLowp.cpp @@ -131,6 +131,39 @@ void quantize_down_scale_by_fixedpoint(const SimpleTensor *in, const Simple std::min(std::numeric_limits::max(), result))); } } + +template +void quantize_down_scale_by_float(const SimpleTensor *in, const SimpleTensor *bias, SimpleTensor *dst, std::vector result_real_multiplier, + int32_t result_offset, int32_t min, int32_t max) +{ + const int cols_in = in->shape().x(); + const bool is_per_channel = result_real_multiplier.size() > 1; + + for(int i = 0; i < in->num_elements(); ++i) + { + TIn result = (*in)[i]; + + if(bias != nullptr) + { + result += (*bias)[i % cols_in]; + } + + // Float multiplication + const float_t multiplier = (is_per_channel) ? result_real_multiplier[i % cols_in] : result_real_multiplier[0]; + + float_t result_f = static_cast(result) * multiplier + static_cast(result_offset); + result = static_cast(std::round(result_f)); + + // Bounded ReLu + if(min != max) + { + result = std::max(min, std::min(max, result)); + } + + (*dst)[i] = static_cast(std::max(std::numeric_limits::lowest(), + std::min(std::numeric_limits::max(), result))); + } +} } // namespace template @@ -237,6 +270,36 @@ SimpleTensor gemmlowp_quantize_down_scale_by_fixedpoint(const SimpleTensor return dst; } +template +SimpleTensor gemmlowp_quantize_down_scale_by_float(const SimpleTensor &in, const SimpleTensor &bias, + std::vector result_real_multiplier, int32_t result_offset, int32_t min, int32_t max) +{ + SimpleTensor dst(in.shape(), DataTypeExtractor::data_type()); + + quantize_down_scale_by_float(&in, &bias, &dst, result_real_multiplier, result_offset, min, max); + + return dst; +} + +template +SimpleTensor gemmlowp_quantize_down_scale_by_float(const SimpleTensor &in, + std::vector result_real_multiplier, int32_t result_offset, int32_t min, int32_t max) +{ + SimpleTensor dst(in.shape(), DataTypeExtractor::data_type()); + + quantize_down_scale_by_float(&in, nullptr, &dst, result_real_multiplier, result_offset, min, max); + + return dst; +} + +template SimpleTensor gemmlowp_quantize_down_scale_by_float(const SimpleTensor &a, const SimpleTensor &b, + std::vector result_real_multiplier, int32_t result_offset, int32_t min, int32_t max); +template SimpleTensor gemmlowp_quantize_down_scale_by_float(const SimpleTensor &a, + std::vector result_real_multiplier, int32_t result_offset, int32_t min, int32_t max); +template SimpleTensor gemmlowp_quantize_down_scale_by_float(const SimpleTensor &a, const SimpleTensor &b, + std::vector result_real_multiplier, int32_t result_offset, int32_t min, int32_t max); +template SimpleTensor gemmlowp_quantize_down_scale_by_float(const SimpleTensor &a, + std::vector result_real_multiplier, int32_t result_offset, int32_t min, int32_t max); template SimpleTensor gemmlowp_quantize_down_scale_by_fixedpoint(const SimpleTensor &a, std::vector result_fixedpoint_multiplier, std::vector result_shift, int32_t result_offset_after_shift, int32_t min, int32_t max); template SimpleTensor gemmlowp_quantize_down_scale_by_fixedpoint(const SimpleTensor &a, const SimpleTensor &b, diff --git a/tests/validation/reference/GEMMLowp.h b/tests/validation/reference/GEMMLowp.h index 7d711263e8..5de48dab52 100644 --- a/tests/validation/reference/GEMMLowp.h +++ b/tests/validation/reference/GEMMLowp.h @@ -59,6 +59,14 @@ SimpleTensor gemmlowp_quantize_down_scale_by_fixedpoint(const SimpleTensor template SimpleTensor gemmlowp_quantize_down_scale_by_fixedpoint(const SimpleTensor &in, const SimpleTensor &bias, std::vector result_fixedpoint_multiplier, std::vector result_shift, int32_t result_offset_after_shift, int32_t min = 0, int32_t max = 0); + +template +SimpleTensor gemmlowp_quantize_down_scale_by_float(const SimpleTensor &in, const SimpleTensor &bias, + std::vector result_real_multiplier, int32_t result_offset, int32_t min = 0, int32_t max = 0); + +template +SimpleTensor gemmlowp_quantize_down_scale_by_float(const SimpleTensor &in, + std::vector result_real_multiplier, int32_t result_offset, int32_t min = 0, int32_t max = 0); } // namespace reference } // namespace validation } // namespace test -- cgit v1.2.1