aboutsummaryrefslogtreecommitdiff
path: root/ethosu/vela/reader_util.py
diff options
context:
space:
mode:
authorPatrik Gustavsson <patrik.gustavsson@arm.com>2021-06-30 09:07:16 +0200
committerPatrik Gustavsson <patrik.gustavsson@arm.com>2021-07-09 09:51:44 +0200
commit5e26eda0e0f359b6e22b1f1eeb9344cd15e0f093 (patch)
treedce92ab9d8a6ceb261c48353ff7077295efa21da /ethosu/vela/reader_util.py
parent8f1f9aaa58175b17cd2e505bfcdb0e40c955ea72 (diff)
downloadethos-u-vela-5e26eda0e0f359b6e22b1f1eeb9344cd15e0f093.tar.gz
MLBEDSW-4840 Move setting of input indices to tflite reader
Mapping to internal input indexing has been added to tflite_reader.py and tosa_reader.py. And the other way around in tflite_writer.py. Signed-off-by: Patrik Gustavsson <patrik.gustavsson@arm.com> Change-Id: I4d8596e747cfa7c4203884c4e785eb1977e2bcc1
Diffstat (limited to 'ethosu/vela/reader_util.py')
-rw-r--r--ethosu/vela/reader_util.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/ethosu/vela/reader_util.py b/ethosu/vela/reader_util.py
index 5b454b57..233286c8 100644
--- a/ethosu/vela/reader_util.py
+++ b/ethosu/vela/reader_util.py
@@ -58,3 +58,30 @@ def fixup_tensors(input_tensors, tensors):
if not tens.ops:
op = Operation(Op.Const, tens.name)
op.set_output_tensor(tens)
+
+
+def align_inputs_indices(from_indices, to_indices, inputs):
+ to_list = to_indices.ifms + to_indices.weights + to_indices.biases
+ from_list = from_indices.ifms + from_indices.weights + from_indices.biases
+
+ assert len(to_list) == len(from_list)
+ if to_list != from_list:
+ for idx, t_idx in enumerate(to_list):
+ if t_idx >= len(inputs):
+ # Biases are allowed to be left out
+ assert t_idx in from_indices.biases and t_idx in to_indices.biases
+ continue
+ if to_list[idx] != from_list[idx]:
+ # find t_idx in from list and swap.
+ for jdx in from_list[idx:]:
+ if from_list[jdx] == t_idx:
+ inputs[idx], inputs[jdx] = inputs[jdx], inputs[idx]
+ from_list[idx], from_list[jdx] = from_list[jdx], from_list[idx]
+ break
+ assert from_list == to_list
+ return inputs
+
+
+def align_tensor_indices_to_nng(op_type, indices, inputs):
+ nng_op = Op(op_type)
+ return align_inputs_indices(indices, nng_op.info.indices, inputs)