aboutsummaryrefslogtreecommitdiff
path: root/ethosu/vela/tflite_model_semantic.py
diff options
context:
space:
mode:
authorAyaan Masood <Ayaan.Masood@arm.com>2022-06-29 11:30:57 +0100
committerAyaan Masood <Ayaan.Masood@arm.com>2022-06-29 11:30:57 +0100
commit4965faee41300393cd8d74da4b399fa4c4ee9030 (patch)
tree1054d6f89be70ec471007132dec97d325ecc0067 /ethosu/vela/tflite_model_semantic.py
parent68b8f2f9457d56df3211be5318e3682332bcefbf (diff)
downloadethos-u-vela-4965faee41300393cd8d74da4b399fa4c4ee9030.tar.gz
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 <Ayaan.Masood@arm.com>
Diffstat (limited to 'ethosu/vela/tflite_model_semantic.py')
-rw-r--r--ethosu/vela/tflite_model_semantic.py23
1 files changed, 22 insertions, 1 deletions
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(
@@ -200,6 +208,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"
valid = True