From 8d57aaa722a4f0430d7e7520d194d1df5394eb6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Alfv=C3=A9n?= Date: Fri, 4 Feb 2022 11:19:17 +0100 Subject: MLBEDSW-6148: Allow overwrite of subgraph input This change will allow the subgraph's input tensor to be reused/overwritten by the output from an elementwise op if there is only one consumer attached to the input tensor. Signed-off-by: Johan Alfven Change-Id: I317188af11a5470614770e18dc8973462fd5f21c --- ethosu/vela/extract_npu_subgraphs.py | 8 ++++++++ ethosu/vela/live_range.py | 2 +- ethosu/vela/tensor.py | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ethosu/vela/extract_npu_subgraphs.py b/ethosu/vela/extract_npu_subgraphs.py index f46f031a..ac24e430 100644 --- a/ethosu/vela/extract_npu_subgraphs.py +++ b/ethosu/vela/extract_npu_subgraphs.py @@ -87,6 +87,14 @@ def rewrite_tensor_cpu_producer_npu_consumers( call_ps.inputs.append(orig_tens) call_ps.primary_op.inputs.append(orig_tens) + # Elementwise op can not overwrite ifm if input is used by many consumers + if orig_tens in cpu_subgraph.input_tensors and len(orig_tens.consumers()) > 1: + new_tens.ifm_write_protected = True + + # Elementwise op can not overwrite ifm if tensor is used as output from sub graph + if orig_tens in cpu_subgraph.output_tensors: + new_tens.ifm_write_protected = True + for op in list(orig_tens.consumers()): if op is None: continue # Subgraph consumers handled separately. diff --git a/ethosu/vela/live_range.py b/ethosu/vela/live_range.py index 5aec0dfb..1aaaadd5 100644 --- a/ethosu/vela/live_range.py +++ b/ethosu/vela/live_range.py @@ -158,7 +158,7 @@ def tensor_should_be_ignored(tens, target_mem_area, target_mem_type_set): def merge_elementwise_op_ranges(sg, sched_op, lr_graph, target_mem_area, target_mem_type_set): def _tensor_should_be_ignored(tens): - if tens in sg.input_tensors + sg.output_tensors: + if tens.ifm_write_protected: return True return tensor_should_be_ignored(tens, target_mem_area, target_mem_type_set) diff --git a/ethosu/vela/tensor.py b/ethosu/vela/tensor.py index ab63afd8..82de8973 100644 --- a/ethosu/vela/tensor.py +++ b/ethosu/vela/tensor.py @@ -370,6 +370,7 @@ class Tensor: "resampling_mode", "src_tensor", "needs_linear_format", + "ifm_write_protected", ) AllocationQuantum = 16 @@ -416,6 +417,7 @@ class Tensor: self.resampling_mode: resampling_mode = resampling_mode.NONE self.needs_linear_format = True + self.ifm_write_protected = False # Reference to parent-tensor if this tensor is a clone self.src_tensor = None -- cgit v1.2.1