From d7911c44323f2704157cfde6e413136b070f5d4b Mon Sep 17 00:00:00 2001 From: Louis Verhaard Date: Tue, 25 Aug 2020 13:36:41 +0200 Subject: MLBEDSW-2688: LUT calculation with different in/out scale Enables LUT for LeakyRelu with int8/uint8 even if input scale is different from the output scale. Fusing LUT with a previous operator for this situation requires further work. Change-Id: I9eddfe36f457e763d44eb3e05fbe240eac7cfec9 Signed-off-by: Louis Verhaard --- ethosu/vela/fp_math.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ethosu/vela/fp_math.py') diff --git a/ethosu/vela/fp_math.py b/ethosu/vela/fp_math.py index 2055879a..eaeb84a1 100644 --- a/ethosu/vela/fp_math.py +++ b/ethosu/vela/fp_math.py @@ -136,3 +136,13 @@ def exp_on_negative_values(a): return np.iinfo(np.int32).max else: return result + + +def multiply_by_quantized_multiplier(x, scale, shift): + # Multiplies x (int32) by (scale, shift) which have obtained by a call to scaling.quantize_scale, + # returns rounded result + shift = 31 - shift + left_shift = shift if shift > 0 else 0 + right_shift = -shift if shift < 0 else 0 + mul = saturating_rounding_mul(x * (1 << left_shift), scale) + return rounding_divide_by_pot(mul, right_shift) -- cgit v1.2.1