diff options
author | Louis Verhaard <louis.verhaard@arm.com> | 2020-08-25 13:36:41 +0200 |
---|---|---|
committer | tim.hall <tim.hall@arm.com> | 2020-08-28 16:48:54 +0000 |
commit | d7911c44323f2704157cfde6e413136b070f5d4b (patch) | |
tree | 9983d34f204a17a6e4d094909f2222e9de828997 /ethosu/vela/fp_math.py | |
parent | 7201932246734b8b5db016106ad8df108d2513d0 (diff) | |
download | ethos-u-vela-d7911c44323f2704157cfde6e413136b070f5d4b.tar.gz |
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 <louis.verhaard@arm.com>
Diffstat (limited to 'ethosu/vela/fp_math.py')
-rw-r--r-- | ethosu/vela/fp_math.py | 10 |
1 files changed, 10 insertions, 0 deletions
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) |