aboutsummaryrefslogtreecommitdiff
path: root/ethosu/vela/tflite_supported_operators.py
diff options
context:
space:
mode:
authorJohan Alfvén <johan.alfven@arm.com>2022-09-06 20:33:22 +0200
committerFredrik Svedberg <fredrik.svedberg@arm.com>2022-09-12 08:02:11 +0000
commit059166304f9ef47f0b916c1325700ed826f25581 (patch)
tree49200e8bc2014e2cdbae52ba49a9e9b5b2ed776f /ethosu/vela/tflite_supported_operators.py
parentd6efcd3cdcd8295fbbe7dd47a7074be39eaf03e4 (diff)
downloadethos-u-vela-059166304f9ef47f0b916c1325700ed826f25581.tar.gz
MLBEDSW-6909: Use int32 acc for the Mean op
Changed acc type from int16 to int32. This will solve saturation problems and the constraint added in commit "MLBEDSW-5029: Output diff for Mean op" can be removed. Signed-off-by: Johan Alfven <johan.alfven@arm.com> Change-Id: I05ec8835b43313b1a264d61a2b147fa62da123fe
Diffstat (limited to 'ethosu/vela/tflite_supported_operators.py')
-rw-r--r--ethosu/vela/tflite_supported_operators.py46
1 files changed, 6 insertions, 40 deletions
diff --git a/ethosu/vela/tflite_supported_operators.py b/ethosu/vela/tflite_supported_operators.py
index f01a6690..24cc26e0 100644
--- a/ethosu/vela/tflite_supported_operators.py
+++ b/ethosu/vela/tflite_supported_operators.py
@@ -796,9 +796,10 @@ class TFLiteSupportedOperators:
max_prod = cls.mean_kernel_product
return h * w <= max_prod, f"Product of height and width is {h * w}"
- @staticmethod
- def constraint_mean_height_width_product_int8(op):
- """Number of IFM height and width elements might cause accumulator saturation when;
+ @classmethod
+ @docstring_format_args([mean_kernel_product_int8])
+ def constraint_mean_height_width_product_int8(cls, op):
+ """Product of IFM height and width must be no greater than {} when:
The IFM shape has 4 dimensions; and
The axis indices specify reduction across 2 dimensions; and
The axis indices correspond to the width and height dimensions of the IFM; and
@@ -817,43 +818,8 @@ class TFLiteSupportedOperators:
return True, ""
h = shape[-3]
w = shape[-2]
-
- ifmq, ofmq = op.ifm.quantization, op.ofm.quantization
-
- # Scale factor
- real_scale = ifmq.scale_f32 / ofmq.scale_f32
-
- # Min and max value
- ifm_min_val = np.iinfo(np.int8).min - ifmq.zero_point
- ifm_max_val = np.iinfo(np.int8).max - ifmq.zero_point
-
- # Accumulator limits
- min_acc_limit = np.iinfo(np.int16).min
- max_acc_limit = np.iinfo(np.int16).max
-
- # Theoretical max/min value that accumulator need to store
- min_acc_sum = h * w * ifm_min_val * real_scale + ofmq.zero_point
- max_acc_sum = h * w * ifm_max_val * real_scale + ofmq.zero_point
-
- # Max product of heigth and width that will not saturate the accumulator
- ifm_min_val = 1 if ifm_min_val == 0 else ifm_min_val
- ifm_max_val = 1 if ifm_max_val == 0 else ifm_max_val
- if max_acc_sum > abs(min_acc_sum):
- max_hw = int((max_acc_limit - ofmq.zero_point) / real_scale / ifm_max_val)
- else:
- max_hw = int((min_acc_limit - ofmq.zero_point) / real_scale / ifm_min_val)
-
- extra = []
-
- extra.append(f" Possible accumulator range is ({min_acc_sum} - {max_acc_sum})\n")
- extra.append(f" Maximum accumulator range is ({min_acc_limit} - {max_acc_limit})\n")
- extra.append(
- f" Based on the IFM and OFM quantization the IFM height and width must be no greater than {max_hw}"
- )
-
- extra = "".join(extra)
-
- return (min_acc_sum >= min_acc_limit and max_acc_sum <= max_acc_limit, f"\n{extra}")
+ max_prod = cls.mean_kernel_product_int8
+ return h * w <= max_prod, f"Product of height and width is {h * w}"
@classmethod
@docstring_format_args([filter_height_range[1], dilated_height_range[1]])