From 4965faee41300393cd8d74da4b399fa4c4ee9030 Mon Sep 17 00:00:00 2001 From: Ayaan Masood Date: Wed, 29 Jun 2022 11:30:57 +0100 Subject: MLBEDSW-6313 Static optimisation for Shape OP *Shape OP value is available at compile time hence it can be optimised *Disconnected shape OP at compile time from parent tensor *Transformed shape OP tensor into constant Change-Id: I0a024269e2b592c6146dd72e62d7a41951fb727a Signed-off-by: Ayaan Masood --- ethosu/vela/tflite_model_semantic.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'ethosu/vela/tflite_model_semantic.py') diff --git a/ethosu/vela/tflite_model_semantic.py b/ethosu/vela/tflite_model_semantic.py index e0541df5..ee66d4cc 100644 --- a/ethosu/vela/tflite_model_semantic.py +++ b/ethosu/vela/tflite_model_semantic.py @@ -186,7 +186,15 @@ class TFLiteSemantic: if op.type in (Op.Placeholder, Op.SubgraphInput, Op.Const): return True - for constraint in self.generic_constraints + self.specific_constraints[op.type]: + # Generic constraints list filtered out to exclude certain constraints depending on op.type + filtered_generic_constraints = [] + + for constraint in self.generic_constraints: + # Check constraint not in dictionary otherwise return empty array + if constraint not in self.get_generic_constraint_exclude_list().get(op.type, []): + filtered_generic_constraints.append(constraint) + + for constraint in filtered_generic_constraints + self.specific_constraints[op.type]: valid, extra = constraint(op) if not valid: print( @@ -199,6 +207,19 @@ class TFLiteSemantic: return True + @staticmethod + def get_generic_constraint_exclude_list(): + + # Not all generic constraints can be applied to each operator + generic_constraints_exclude_list = { + Op.Shape: [ + TFLiteSemantic.constraint_tens_quant_none_check, + TFLiteSemantic.constraint_tens_quant_scale, + TFLiteSemantic.constraint_quant_scale_inf, + ] + } + return generic_constraints_exclude_list + @staticmethod def constraint_none_const_tensors(op): "Constant tensors should not have NoneType-values" -- cgit v1.2.1