Skip to content

Commit

Permalink
feat(noc_pass): use one obj and account for width rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
jake-ke committed Jun 21, 2024
1 parent 7c13184 commit 25d9b34
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions noc_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
from pydantic import BaseModel, ConfigDict

from device import Device
from ir_helper import extract_slot_coord, extract_slot_range, get_slot_to_noc_nodes
from ir_helper import (
extract_slot_coord,
extract_slot_range,
get_slot_to_noc_nodes,
round_up_to_noc_bw,
)
from tcl_helper import print_noc_loc_tcl


Expand Down Expand Up @@ -69,7 +74,8 @@ def print_ordered_edges(edges: list[tuple[str, str]]) -> None:
print(" -> ".join(ordered_nodes))
return
except nx.NetworkXUnfeasible:
# Graph contains a cycle or is invalid
print("Graph contains a cycle or is invalid!")
print(edges)
return


Expand Down Expand Up @@ -290,6 +296,20 @@ def ilp_noc_selector_add_constr(
== 0
)

# each node is visited at most once
m += lpSum(
ilp_var[stream_name]["x"][(u, node)]
for u in noc_nx_graph.predecessors(node)
) + lpSum(
ilp_var[stream_name]["x"][(node, v)]
for v in noc_nx_graph.successors(node)
) <= (
1 + 1
)

# forbid disconnected edge cycles
# may not be necessary

# src has only one outgoing flow
for n in end_nodes["src"]:
m += (
Expand Down Expand Up @@ -352,7 +372,7 @@ def ilp_noc_selector_add_constr(
e_tuple = (e.src.name, e.dest.name)
m += (
lpSum(
bw * ilp_var[stream_name]["x"][e_tuple]
round_up_to_noc_bw(bw) * ilp_var[stream_name]["x"][e_tuple]
for stream_name, bw in streams_bw.items()
)
<= e.bandwidth
Expand Down Expand Up @@ -416,21 +436,20 @@ def ilp_noc_selector_add_constr_special(
def ilp_noc_selector_add_obj(
m: LpProblem,
ilp_var: dict[str, dict[str, LpVariable]],
streams_nodes: dict[str, dict[str, list[str]]],
streams_bw: dict[str, float],
device: Device,
) -> None:
"""Adds objectives for the NoC selector ILP."""
total_path_length = lpSum(
ilp_var[stream_name]["x"][e]
for stream_name, _ in streams_nodes.items()
for e in device.noc_graph.get_all_edges()
)
# not used
# total_path_length = lpSum(
# ilp_var[stream_name]["x"][e]
# for stream_name, _ in streams_nodes.items()
# for e in device.noc_graph.get_all_edges()
# )
total_not_mapped_bandwidth = lpSum(
bw * ilp_var[stream_name]["not_mapped_stream"]
for stream_name, bw in streams_bw.items()
)
m += total_path_length + total_not_mapped_bandwidth
m += total_not_mapped_bandwidth


def post_process_noc_ilp(
Expand Down Expand Up @@ -516,7 +535,7 @@ def ilp_noc_selector(
streams_manhattan_bw = get_stream_manhattan_bw(streams_slots, streams_bw)
# mypy bug: sees LpVariable as Any
# declaring a new function and trick mypy to see ilp_var's values as LpVariable
ilp_noc_selector_add_obj(m, ilp_var, streams_nodes, streams_manhattan_bw, device)
ilp_noc_selector_add_obj(m, ilp_var, streams_manhattan_bw)

m.solve(GUROBI_CMD(options=[("TimeLimit", 300)]))

Expand Down

0 comments on commit 25d9b34

Please sign in to comment.