Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

234 improve in code documentation of backenddynapcnnmapping #235

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
14 changes: 9 additions & 5 deletions sinabs/backend/dynapcnn/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,16 @@ def __repr__(self):

# graph is list of list of edges. Each edge is
def edmonds(graph, source, sink, verbose: bool = False):
"""Use Edmonds-Karp-Algorithm to match software layers to chip layers"""
graph = deepcopy(graph)
flow = 0
while True:
q = deque()
q.append(source)
pred = [None for _ in range(len(graph))]
while len(q) != 0:
cur = q.popleft()
for edge in graph[cur]:
cur = q.popleft() # current node index
for edge in graph[cur]: # edges to/from current node
if pred[edge.t] is None and edge.t != source and edge.cap > edge.flow:
pred[edge.t] = edge
q.append(edge.t)
Expand All @@ -123,9 +124,12 @@ def edmonds(graph, source, sink, verbose: bool = False):
def make_flow_graph(
layer_mapping: List[List[int]], num_layers: int = 9
) -> List[List[Edge]]:
"""Make a flow graph given all possible chip layers for each DynapcnnCompatibleLayer layer.
Note that the flows are not computed yet. The flow for the graph generated here needs to be
populated by calling the method `edmonds`
"""
Make a bipartite flow graph (flow network) given all possible chip layers
for each DynapcnnLayer layer. The goal is to formulate the mapping from
software layer to chip layer as a bipartite matching problem. Note that the
flows are not computed yet. The flow for the graph generated here needs to
be populated by calling the method `edmonds`

Parameters
----------
Expand Down
Loading