MLBEDSW-5717 Fix for sigmoid int16
Fixed issue with sigmoid int16 with 1/2048 scaling.
Signed-off-by: Patrik Gustavsson <patrik.gustavsson@arm.com>
Change-Id: I32718757e3776e6be89fe94a9b38368c78f0006b
diff --git a/ethosu/vela/register_command_stream_generator.py b/ethosu/vela/register_command_stream_generator.py
index d74f4d2..fd32b65 100644
--- a/ethosu/vela/register_command_stream_generator.py
+++ b/ethosu/vela/register_command_stream_generator.py
@@ -656,8 +656,11 @@
rounded_log2 = int(round(x_log2))
is_power_of_two = abs(x_log2 - rounded_log2) < 0.001
shift = rounded_log2 + 12
- if is_power_of_two and shift in (0, 1):
- # Special handling if input scale is 1/2048 or 1/4096
+ if is_power_of_two and (
+ (pool_op.activation.op_type == NpuActivationOp.TANH and shift in (0, 1))
+ or (pool_op.activation.op_type == NpuActivationOp.SIGMOID and shift == 0)
+ ):
+ # Special handling if input scale is 1/2048 (tanh/sigmoid) or 1/4096 (tanh)
scale = 3 << shift
shift = 0
else: