aboutsummaryrefslogtreecommitdiff
path: root/ethosu
diff options
context:
space:
mode:
authorJohan Alfven <johan.alfven@arm.com>2023-06-15 09:24:01 +0200
committerJohan Alfven <johan.alfven@arm.com>2023-06-16 16:01:05 +0200
commit85b77901b72865cc0071f294bd9177288c0bc4e3 (patch)
tree5bc2e96bc4521f2c1e8e33201d181cb5ec796caa /ethosu
parent3e7157ba59f12aa0d277a9b3a7cb3f8a19267338 (diff)
downloadethos-u-vela-85b77901b72865cc0071f294bd9177288c0bc4e3.tar.gz
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>
Diffstat (limited to 'ethosu')
-rw-r--r--ethosu/vela/test/test_tflite_supported_operators.py17
-rw-r--r--ethosu/vela/tflite_supported_operators.py18
2 files changed, 35 insertions, 0 deletions
diff --git a/ethosu/vela/test/test_tflite_supported_operators.py b/ethosu/vela/test/test_tflite_supported_operators.py
index cbad1713..6f3553d8 100644
--- a/ethosu/vela/test/test_tflite_supported_operators.py
+++ b/ethosu/vela/test/test_tflite_supported_operators.py
@@ -675,3 +675,20 @@ def test_rsqrt_support():
# Test not supported op (int16)
op = testutil.create_elemwise_op(Op.Rsqrt, "op", [1, 8, 8, 8], [1, 8, 8, 8], [1, 8, 8, 8], datatype=DataType.int16)
assert not support.is_operator_supported(op)
+
+
+def test_constraint_slice_inputs_const():
+ # Begin and Size tensor cannot be non-const tensors
+ # Test not supported op
+ ifm = Tensor([3, 1, 256], DataType.int8, "in")
+ begin = Tensor([3], DataType.int32, "begin")
+ size = Tensor([3], DataType.int32, "size")
+ ofm = Tensor([1, 1, 256], DataType.int8, "size")
+ op = testutil.create_op(Op.Slice, [ifm, begin, size], ofm)
+ assert not support.is_operator_supported(op)
+ # Test supported op
+ begin = create_const_tensor("begin", [3], DataType.int32, [0, 0, 0])
+ size = create_const_tensor("size", [3], DataType.int32, [2, 1, 256])
+ op.set_input_tensor(begin, 1)
+ op.set_input_tensor(begin, 2)
+ assert support.is_operator_supported(op)
diff --git a/ethosu/vela/tflite_supported_operators.py b/ethosu/vela/tflite_supported_operators.py
index a24eebc5..f965d2ba 100644
--- a/ethosu/vela/tflite_supported_operators.py
+++ b/ethosu/vela/tflite_supported_operators.py
@@ -331,6 +331,9 @@ class TFLiteSupportedOperators:
# 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 @@ class TFLiteSupportedOperators:
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}"