Skip to content

Commit

Permalink
[tools/mec] Add edges between graph nodes (#14353)
Browse files Browse the repository at this point in the history
The model explorer draws edges based on the information provided by
the 'IncomingEdge' API. By utilizing this API and a mapping from input
tensors to source nodes, it adds edges accordingly.

ONE-DCO-1.0-Signed-off-by: Jonghwa Lee <[email protected]>
  • Loading branch information
batcheu authored Nov 22, 2024
1 parent 827ae31 commit f092fe3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tools/model_explorer_circle/src/circle_adapter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ def get_source_of(self, tensor_id: int) -> Optional[str]:
"""Get the source of the tensor."""
return self.map_tensor_to_source.get(tensor_id)

def add_incoming_edge(self, me_node: graph_builder.GraphNode, tensor_id: int,
input_id: int) -> None:
"""Add incoming edge to the given node."""
source = self.get_source_of(tensor_id)
if source is not None:
sid, soid = source.split('/')
me_node.incomingEdges.append(
graph_builder.IncomingEdge(sourceNodeId=sid,
sourceNodeOutputId=soid,
targetNodeInputId=f'{input_id}'))

def build_graph(self, me_graph: graph_builder.Graph) -> None:
"""Build the graph using the model."""

Expand Down Expand Up @@ -95,12 +106,20 @@ def build_graph(self, me_graph: graph_builder.Graph) -> None:
self.model.operatorCodes[op.opcodeIndex].builtinCode)
me_node = graph_builder.GraphNode(id=f'{idx}', label=name)
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:
continue
self.add_incoming_edge(me_node=me_node, tensor_id=tensor_id, input_id=i)

# Create Output nodes
me_node = graph_builder.GraphNode(id=f'{len(me_graph.nodes)}',
label="GraphOutputs",
namespace="GraphOutputs")
me_graph.nodes.append(me_node)
# Connect edges from inputs to output node
for i in sub_graph.outputs:
self.add_incoming_edge(me_node=me_node, tensor_id=i, input_id=i)

def convert(self, model_path: str, settings: Dict) -> ModelExplorerGraphs:
"""Convert the model to a set of graphs."""
Expand Down

0 comments on commit f092fe3

Please sign in to comment.