diff options
author | Johan Alfven <johan.alfven@arm.com> | 2023-08-16 12:18:09 +0200 |
---|---|---|
committer | Johan Alfven <johan.alfven@arm.com> | 2023-08-16 12:24:35 +0200 |
commit | 3db30ff556fab8a6041a63e4d34a82e2b64f6a51 (patch) | |
tree | 36c41ccbb9d269717f0107c8310086d35716b518 | |
parent | 75d3402204145731c2ebe0131ee47d966fd95562 (diff) | |
download | ethos-u-vela-3db30ff556fab8a6041a63e4d34a82e2b64f6a51.tar.gz |
MLBEDSW-7884: Fix crash for RSQRT3.9.0.rc2
- RSQRT is only defined for positive numbers and
therefore the zeropoint and actual input value
will have an impact
- Clamp the range to avoid crashing. As long as the actual
input is within valid range everything works. If the input
is not valid the reference will crash and not generating
any output
Change-Id: I1082b508d9cd85ad4b017e7b786cfff730585172
Signed-off-by: Johan Alfven <johan.alfven@arm.com>
-rw-r--r-- | ethosu/vela/lut.py | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/ethosu/vela/lut.py b/ethosu/vela/lut.py index e8759d9..ab440e6 100644 --- a/ethosu/vela/lut.py +++ b/ethosu/vela/lut.py @@ -295,9 +295,6 @@ def create_lut_rsqrt_int8_op(op): zp_in = op.ifm.quantization.zero_point zp_out = op.ofm.quantization.zero_point - # Make sure zero point is valid - assert (-128 - zp_in) >= 0, f"Rsqrt is only defined for positive values, zeropoint is {zp_in}" - scale = np.double(1) / np.double(np.sqrt(ifm_scale) * ofm_scale) output_multiplier, output_shift = quantise_scale(scale) @@ -314,7 +311,8 @@ def create_lut_rsqrt_int8_op(op): if x == -128: # Value already populated above continue - x_real = x - zp_in + # Rsqrt is only defined for positive values + x_real = max(0, x - zp_in) val = RSQRT_LUT[x_real] val = fp_math.multiply_by_quantized_multiplier(val, output_multiplier, output_shift - kshift) + zp_out lut_result = min(quantized_max, max(quantized_min, val)) |