From 4a434cba156cdfb2613b7ebe4d4a4ec9f85ba616 Mon Sep 17 00:00:00 2001 From: Fredrik Svedberg Date: Tue, 27 Sep 2022 14:13:01 +0200 Subject: MLBEDSW-6969 Remove RescaleAdd and RescaleMul operators Removed RescaleAdd and RescaleMul operators in favour of Operation.explicit_scale and removed Operation.rescale. Signed-off-by: Fredrik Svedberg Change-Id: Idccd8851731d4bb8d4e84970e0fd6b409d7d4e45 --- ethosu/vela/register_command_stream_generator.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'ethosu/vela/register_command_stream_generator.py') diff --git a/ethosu/vela/register_command_stream_generator.py b/ethosu/vela/register_command_stream_generator.py index 5680c96f..99ac32d5 100644 --- a/ethosu/vela/register_command_stream_generator.py +++ b/ethosu/vela/register_command_stream_generator.py @@ -707,6 +707,7 @@ def generate_ofm_scaling_for_pooling(emit: CommandStreamEmitter, pool_op: NpuPoo shift = explicit_scaling.shift[0] else: # for ResizeBilinear/NearestNeighbor operations with rescale + # Note: this is not used, but part of the public API rescale = pool_op.rescale rescale_bits = len(bin(round_up_to_int(rescale))) - 2 + 1 scale, shift = scaling.quantise_pooling_scale(kernel.height * kernel.width, rescale_bits) @@ -759,25 +760,30 @@ def generate_scaling_for_elementwise(emit: CommandStreamEmitter, npu_op: NpuElem else: ofm_scale, shift = scaling.elementwise_mul_scale(input_scale, input2_scale, output_scale) else: # Add/Sub - opa_scale: float - opb_scale: float + # Default operand scaling is no scaling + opa_scale = opb_scale = 1 + opa_shift = 0 bitdepth = npu_op.ifm.data_type.size_in_bits() use_advanced_scaling = False - if None in (input_scale, input2_scale, output_scale): - opa_scale = opb_scale = ofm_scale = 1 - opa_shift = shift = 0 - if npu_op.rescale is not None: - ofm_scale, shift = npu_op.rescale + if npu_op.rescale is not None: + # Explicit ofm scaling + ofm_scale, shift = npu_op.rescale + elif None in (input_scale, input2_scale, output_scale): + # No ofm scaling + ofm_scale = 1 + shift = 0 elif input_scale == input2_scale and bitdepth == 16: + # int16 same scaling opa_scale, opb_scale, ofm_scale, shift = scaling.simplified_elementwise_add_sub_scale( input_scale, input2_scale, output_scale ) # align the double rounding with that of advanced scaling - opa_scale /= 2 - opb_scale /= 2 + opa_scale //= 2 + opb_scale //= 2 shift -= 1 opa_shift = 0 # Unused for this case elif input_scale == input2_scale: + # Same scaling opa_scale, opb_scale, ofm_scale, shift = scaling.simplified_elementwise_add_sub_scale( input_scale, input2_scale, output_scale ) -- cgit v1.2.1