MLBEDSW-4838 Added basic TOSA support.
Added basic TOSA support, enabling Vela to
read and compile a .tosa file corresponding to
CONV2D + Rescale + Clamp, and writing it to an
optimized .tflite file.
The optimized .tflite file, will in this case, hold
a commandstream where the Rescale and Clamp has been
fused into the CONV2D.
The optimized tflite file is not output from Vela.
-Added support to read .tosa file into Vela
internal structure.
- Added tosa_reader.py, tosa_mapper.py and
helper files stored under tosa/
- Support for this limited to ~10 ops
-Added reader_util.py for functions common
for TOSA and TFLite
-Added tosa_graph_optimiser.py
-Added support to fuse Rescale into convolution
-Modified handling for padding
-Added support to fuse Clamp to previous op
-Added graph_optimiser_util.py
-Moved functions common for TOSA/TFLite graph
optimization to this file.
-Renamed graph_optimiser.py to tflite_graph_optmiser.py
-Added separate tosa_supported_operators.py
-Added supported_operator_util.py
-For functions in common for TOSA/TFLite
Signed-off-by: Patrik Gustavsson <patrik.gustavsson@arm.com>
Change-Id: Ic3c540504ec8c5eb4771397fdc6882050ecf33ab
diff --git a/ethosu/vela/reader_util.py b/ethosu/vela/reader_util.py
new file mode 100644
index 0000000..5b454b5
--- /dev/null
+++ b/ethosu/vela/reader_util.py
@@ -0,0 +1,60 @@
+# Copyright (C) 2021 Arm Limited or its affiliates. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Licensed under the Apache License, Version 2.0 (the License); you may
+# not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an AS IS BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# Description:
+# Utlity function for reading .tosa and .tflite files
+from .operation import Op
+from .operation import Operation
+
+
+def decode_str(s):
+ if s is None:
+ return ""
+ return s.decode("utf-8")
+
+
+def clone_and_reshape_tensor(src_tens, reorder, set_unique):
+ tens = src_tens.clone("_reshape", set_unique)
+ tens.shape = [src_tens.shape[idx] for idx in reorder]
+ tens.bandwidth_shape = tens.shape
+ tens.storage_shape = tens.shape
+
+ if tens.values is not None:
+ tens.values = tens.values.transpose(reorder)
+
+ if tens.quant_values is not None:
+ tens.quant_values = tens.quant_values.transpose(reorder)
+
+ op = Operation(Op.Const, tens.name)
+ op.set_output_tensor(tens)
+ return tens
+
+
+# Fix up tensors without operations. Generate either Placeholder or Constant ops
+def fixup_tensors(input_tensors, tensors):
+ for tens in input_tensors:
+ if len(tens.ops) and tens.ops[0].type == Op.Const:
+ break
+
+ if tens.ops != []:
+ tens.error("This subgraph input tensor has unexpected driving operators.")
+
+ op = Operation(Op.Placeholder, tens.name)
+ op.set_output_tensor(tens)
+
+ for tens in tensors:
+ if not tens.ops:
+ op = Operation(Op.Const, tens.name)
+ op.set_output_tensor(tens)