From 6f4955aa7097b123bbf31aae4654547bb3e3c68c Mon Sep 17 00:00:00 2001 From: Samuel Panijel Date: Thu, 10 Jun 2021 13:40:03 +0300 Subject: MLBEDSW-3890 handling scratch tensor vela: Possible issue with handling scratch tensor on non-ethosu custom op Fixing a case where a tensor input name ends with "scratch". 4 test cases passing this change: 1) non-optimized tflite - input tensor name is _split_1_scratch 2) optimized tflite - input tensor name is _split_1_scratch 3) optimized tflite - input tensor name is _split_1_scratch and custom operation name is non_ethus_u 4) non-optimized tflite - input tensor name is _split_1_scratch_fast Change-Id: Ia515805825b7f9a646607c5075b7ea3a0cf6aad8 Signed-off-by: Samuel Panijel --- ethosu/vela/npu_serialisation.py | 2 +- ethosu/vela/tflite_writer.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'ethosu/vela') diff --git a/ethosu/vela/npu_serialisation.py b/ethosu/vela/npu_serialisation.py index f462168a..06ea61df 100644 --- a/ethosu/vela/npu_serialisation.py +++ b/ethosu/vela/npu_serialisation.py @@ -82,7 +82,7 @@ def serialise_npu_subgraph_into_tensors(sg, arch, scratch_tens, scratch_fast_ten sg.scratch_fast_tensor = make_memory_tensor( sg.name + "_scratch_fast", scratch_fast_area, MemType.Scratch_fast, 0, False, arch ) - sg.scratch_fast_tensor.purpose = TensorPurpose.Scratch + sg.scratch_fast_tensor.purpose = TensorPurpose.ScratchFast else: sg.scratch_tensor = scratch_tens sg.scratch_tensor.shape[0] += scratch_size diff --git a/ethosu/vela/tflite_writer.py b/ethosu/vela/tflite_writer.py index 687b8876..8cabb0ac 100644 --- a/ethosu/vela/tflite_writer.py +++ b/ethosu/vela/tflite_writer.py @@ -25,6 +25,7 @@ from .errors import VelaError from .nn_graph import PassPlacement from .operation import Op from .tensor import MemType +from .tensor import TensorPurpose from .tflite import Buffer from .tflite import Metadata from .tflite import Model @@ -37,6 +38,7 @@ from .tflite_mapping import builtin_operator_inv_map from .tflite_mapping import BuiltinOperator from .tflite_mapping import datatype_inv_map + # ugh, the python flatbuffer interface is missing a method to add in file identifier. patching it in here: tflite_version = 3 @@ -345,7 +347,7 @@ class TFLiteSerialiser: all_tensors = [tens for nm, idx, tens in sorted((tens.name, idx, tens) for idx, tens in enumerate(tensor_set))] - scratch_tensors = [tens for tens in all_tensors if tens.name.endswith("scratch")] + scratch_tensors = [tens for tens in all_tensors if tens.purpose is TensorPurpose.Scratch] if len(scratch_tensors) == 0: scratch_tensor = None -- cgit v1.2.1