Skip to content

Commit 3c9c4e2

Browse files
committed
Arm backend: Fix mult and scale calculation for int48_t
Signed-off-by: Per Åstrand <[email protected]> Change-Id: Ibe158d8d35a632547290f1b9a055d061ae267d77
1 parent e866b73 commit 3c9c4e2

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

backends/arm/tosa/quant_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ def compute_multiplier_and_shift(
262262
if shift > 62:
263263
multiplier = multiplier >> min(31, shift - 62)
264264
shift = 62
265+
266+
assert multiplier >= 0, "Multiplier should be non-negative"
267+
assert shift >= 2 and shift <= 62, "Shift should be in range [2, 62]"
265268
multipliers.append(multiplier)
266269
shifts.append(shift)
267270
return multipliers, shifts
@@ -315,8 +318,8 @@ def build_rescale(
315318
import serializer.tosa_serializer as ts # type: ignore
316319
import tosa.Op as TosaOp # type: ignore
317320

318-
scaleWidth = 32
319-
is_scale32 = True
321+
scaleWidth = 16 if input_node.dtype == ts.DType.INT48 else 32
322+
is_scale32 = False if input_node.dtype == ts.DType.INT48 else True
320323
multipliers, shifts = compute_multiplier_and_shift(scale, scaleWidth)
321324
rescale_inputs = create_const_ops_for_rescale(
322325
tosa_fb,

0 commit comments

Comments
 (0)