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 <johan.alfven@arm.com>
Change-Id: I317188af11a5470614770e18dc8973462fd5f21c
diff --git a/ethosu/vela/extract_npu_subgraphs.py b/ethosu/vela/extract_npu_subgraphs.py
index f46f031..ac24e43 100644
--- a/ethosu/vela/extract_npu_subgraphs.py
+++ b/ethosu/vela/extract_npu_subgraphs.py
@@ -87,6 +87,14 @@
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.