From 49b13a080d204137fb96080f1bee2dc03a986df3 Mon Sep 17 00:00:00 2001 From: Jonghwa Lee Date: Tue, 19 Nov 2024 20:07:20 +0900 Subject: [PATCH] [tools/mec] Add namespace to operator It adds a namespace to the operator node based on the name of its output tensor. It helps to graph folded with grouping of operators that uses same namespace. ONE-DCO-1.0-Signed-off-by: Jonghwa Lee --- .../model_explorer_circle/src/circle_adapter/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/model_explorer_circle/src/circle_adapter/main.py b/tools/model_explorer_circle/src/circle_adapter/main.py index 3a6c871fa0d..387c14a6e84 100644 --- a/tools/model_explorer_circle/src/circle_adapter/main.py +++ b/tools/model_explorer_circle/src/circle_adapter/main.py @@ -104,8 +104,17 @@ def build_graph(self, me_graph: graph_builder.Graph) -> None: for idx, op in enumerate(sub_graph.operators): name = self.opcode_to_name( self.model.operatorCodes[op.opcodeIndex].builtinCode) - me_node = graph_builder.GraphNode(id=f'{idx}', label=name) + # Construct namespace following output tensor's name + output_tensor_id = op.outputs[0] + output_tensor = sub_graph.tensors[output_tensor_id] + ns = output_tensor.name.decode("utf-8") + if '/' in ns: + # Let's take maximum 2 depths of the tensor name + # '/A/B/C/D' becomes 'A/B' + ns = '/'.join(ns.strip('/').split('/')[:2]) + me_node = graph_builder.GraphNode(id=f'{idx}', label=name, namespace=ns) me_graph.nodes.append(me_node) + # Connect edges from inputs to this operator node for i, tensor_id in enumerate(op.inputs): if tensor_id < 0: