MLBEDSW-7709: MLCE: Crash when rewriting split op
- A crash occurred due to NoneType subscriptable error when
rewriting a Slice op. The reason was that the Size tensor did
not contain any data.
- Added constraint pushing the Slice operator to the CPU if
begin or size tensor are empty.
- Added test to supported operators
- Updated SUPPORTED_OPS.md
Change-Id: Ide204cae24e5871f0e6ae1fdc98ac68d0ce4d3ae
Signed-off-by: Johan Alfven <johan.alfven@arm.com>
diff --git a/ethosu/vela/tflite_supported_operators.py b/ethosu/vela/tflite_supported_operators.py
index a24eebc..f965d2b 100644
--- a/ethosu/vela/tflite_supported_operators.py
+++ b/ethosu/vela/tflite_supported_operators.py
@@ -331,6 +331,9 @@
# Rsqrt specific checks
self.specific_constraints[Op.Rsqrt].append(TFLiteSupportedOperators.constraint_rsqrt_input_int8)
+ # Slice specific checks:
+ self.specific_constraints[Op.Slice].append(TFLiteSupportedOperators.constraint_slice_inputs_const)
+
def is_operator_supported(self, op):
ext_type = optype_to_builtintype(op.type)
if op.type not in TFLiteSupportedOperators.supported_operators:
@@ -942,3 +945,18 @@
ifm_dtype = op.ifm.dtype
valid = ifm_dtype == DataType.int8
return valid, f"Op has ifm_dtype={ifm_dtype}"
+
+ @staticmethod
+ def constraint_slice_inputs_const(op):
+ "Begin and Size Input tensors must be constant"
+ valid = True
+ extra = []
+ _, begin, sizes = op.inputs
+ if begin.values is None:
+ valid = False
+ extra.append(f"Begin tensor '{begin.name}'")
+ if sizes.values is None:
+ valid = False
+ extra.append(f"Size tensor '{sizes.name}'")
+ extra = ", ".join(extra)
+ return valid, f"Op has non-constant tensors: {extra}"