Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/chop/passes/graph/transforms/utils/insert_fork.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import torch


def insert_fork_transform_pass(graph, pass_args={}):
"""Insert hardware-explicit forks into the mase graph

:param graph: a MaseGraph
:type graph: MaseGraph
:param pass_args: this pass requires additional arguments which is explained below, defaults to {}
:type pass_args: _type_, optional
:return: return a tuple of a MaseGraph and an empty dict (no additional info to return)
:rtype: tuple(MaseGraph, Dict)
"""

logger.info("Inserting forks...")

nodes_to_fork = []
for node in graph.fx_graph.nodes:
user_count = 0
for u in node.users.keys():
if u.meta["mase"].parameters["hardware"]["is_implicit"]:
user_count += 1
if user_count > 1:
nodes_to_fork.append(node)

for node in nodes_to_fork:
graph.fx_graph.inserting_after(node)
graph.fx_graph.create_node("call_module", torch.nn.Identity)

return graph, _
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def test_emit_verilog_bert():

# i += 1

mg, _ = passes.insert_fork_transform_pass(mg)

mg, _ = passes.emit_verilog_top_transform_pass(mg)
# mg, _ = passes.emit_bram_transform_pass(mg)
mg, _ = passes.emit_internal_rtl_transform_pass(mg)
Expand Down