From e3dd2f3c4e09488776d45e8884123385b3e93e2a Mon Sep 17 00:00:00 2001 From: Patrik Gustavsson Date: Thu, 2 Dec 2021 09:08:26 +0100 Subject: MLBEDSW-5717 Fix for sigmoid int16 Fixed issue with sigmoid int16 with 1/2048 scaling. Signed-off-by: Patrik Gustavsson Change-Id: I32718757e3776e6be89fe94a9b38368c78f0006b --- ethosu/vela/register_command_stream_generator.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ethosu/vela/register_command_stream_generator.py b/ethosu/vela/register_command_stream_generator.py index d74f4d24..fd32b655 100644 --- a/ethosu/vela/register_command_stream_generator.py +++ b/ethosu/vela/register_command_stream_generator.py @@ -656,8 +656,11 @@ def generate_ofm_scaling_for_pooling(emit: CommandStreamEmitter, pool_op: NpuPoo 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: -- cgit v1.2.1