Skip to content

Commit

Permalink
Assign the correct orientation to the netlist when writing it out.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 465597131
Change-Id: I62fccf540245f3319d35103cfab55839bcb4118e
  • Loading branch information
Circuit Training Team authored and copybara-github committed Aug 5, 2022
1 parent 867f60d commit 25720c8
Show file tree
Hide file tree
Showing 3 changed files with 348 additions and 1 deletion.
2 changes: 1 addition & 1 deletion circuit_training/grouping/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ def write_grouped_netlist(self, file_path: str) -> None:
if node.orientation is None:
self.add_attr(new_node, "orientation", mnds.Orientation.N.name)
else:
self.add_attr(new_node, "orientation", mnds.Orientation.name)
self.add_attr(new_node, "orientation", node.orientation.name)

for group_no in groups_to_print:
self.write_as_macro(group_no, graph_def)
Expand Down
30 changes: 30 additions & 0 deletions circuit_training/grouping/grouping_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

_NETLIST_FILE_PATH = "third_party/py/circuit_training/grouping/testdata/simple.pb.txt"
_EXPECTED_GROUPED_NETLIST_FILE_PATH = "third_party/py/circuit_training/grouping/testdata/simple_grouped_soft_macro_not_bloated.pb.txt"
_EXPECTED_GROUPED_NETLIST_S_FILE_PATH = "third_party/py/circuit_training/grouping/testdata/simple_grouped_soft_macro_not_bloated_s.pb.txt"


class GroupingTest(absltest.TestCase):
Expand Down Expand Up @@ -203,6 +204,35 @@ def test_write_grouped_netlist(self):

compare.assertProto2Equal(self, tmp_graph_def, expected_graph_def)

def test_write_grouped_netlist_with_orientation_change(self):
meta_netlist = copy.deepcopy(self._meta_netlist)
group = grouping.Grouping(meta_netlist)
group.set_cell_area_utilization(1.0)
name_to_id_map = {node.name: node.id for node in meta_netlist.node}
s0_id = name_to_id_map["S0"]
s1_id = name_to_id_map["S1"]
group.set_node_group(s0_id, 2)
group.set_node_group(s1_id, 2)
# place them to check coord calculation for the group.
meta_netlist.node[s0_id].coord = mnds.Coord(x=10, y=60)
meta_netlist.node[s1_id].coord = mnds.Coord(x=30, y=30)

meta_netlist.node[name_to_id_map["M0"]].orientation = mnds.Orientation.S

tmpfile = os.path.join(FLAGS.test_tmpdir, "netlist.pb.txt")
group.write_grouped_netlist(tmpfile)
# Compare two protobufs with proto util.
expected_graph_def = tf.compat.v1.GraphDef()

with open(tmpfile, "r") as f:
tmp_graph_def = text_format.Parse(f.read(), tf.compat.v1.GraphDef())

expected_grouped_netlist_file_path = _EXPECTED_GROUPED_NETLIST_S_FILE_PATH
with open(expected_grouped_netlist_file_path, "r") as f:
expected_graph_def = text_format.Parse(f.read(), tf.compat.v1.GraphDef())

compare.assertProto2Equal(self, tmp_graph_def, expected_graph_def)

def test_merge_groups(self):
meta_netlist = copy.deepcopy(self._meta_netlist)
group = grouping.Grouping(meta_netlist)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
node {
name: "__metadata__"
attr {
key: "soft_macro_area_bloating_ratio"
value {
f: 1.0
}
}
}
node {
name: "P0"
input: "Grp_2/Pinput"
input: "P0_M0"
attr {
key: "side"
value {
placeholder: "LEFT"
}
}
attr {
key: "type"
value {
placeholder: "PORT"
}
}
}
node {
name: "P1"
attr {
key: "side"
value {
placeholder: "TOP"
}
}
attr {
key: "type"
value {
placeholder: "PORT"
}
}
}
node {
name: "M0"
attr {
key: "height"
value {
f: 120
}
}
attr {
key: "orientation"
value {
placeholder: "S"
}
}
attr {
key: "type"
value {
placeholder: "MACRO"
}
}
attr {
key: "width"
value {
f: 120
}
}
}
node {
name: "M1"
attr {
key: "height"
value {
f: 40
}
}
attr {
key: "orientation"
value {
placeholder: "N"
}
}
attr {
key: "type"
value {
placeholder: "MACRO"
}
}
attr {
key: "width"
value {
f: 80
}
}
}
node {
name: "P0_M0"
attr {
key: "macro_name"
value {
placeholder: "M0"
}
}
attr {
key: "type"
value {
placeholder: "MACRO_PIN"
}
}
attr {
key: "x_offset"
value {
f: -60
}
}
attr {
key: "y_offset"
value {
f: 60
}
}
}
node {
name: "P1_M0"
input: "Grp_2/Pinput"
attr {
key: "macro_name"
value {
placeholder: "M0"
}
}
attr {
key: "type"
value {
placeholder: "MACRO_PIN"
}
}
attr {
key: "x_offset"
value {
f: 60
}
}
attr {
key: "y_offset"
value {
f: 60
}
}
}
node {
name: "P0_M1"
attr {
key: "macro_name"
value {
placeholder: "M1"
}
}
attr {
key: "type"
value {
placeholder: "MACRO_PIN"
}
}
attr {
key: "x_offset"
value {
f: -40
}
}
attr {
key: "y_offset"
value {
f: 20
}
}
}
node {
name: "P1_M1"
input: "P1"
attr {
key: "macro_name"
value {
placeholder: "M1"
}
}
attr {
key: "type"
value {
placeholder: "MACRO_PIN"
}
}
attr {
key: "x_offset"
value {
f: 40
}
}
attr {
key: "y_offset"
value {
f: 20
}
}
}
node {
name: "Grp_2"
attr {
key: "height"
value {
f: 0.12375519
}
}
attr {
key: "type"
value {
placeholder: "macro"
}
}
attr {
key: "width"
value {
f: 17.128008
}
}
attr {
key: "x"
value {
f: 20
}
}
attr {
key: "y"
value {
f: 45
}
}
}
node {
name: "Grp_2/Poutput_single_0"
input: "P0_M1"
attr {
key: "macro_name"
value {
placeholder: "Grp_2"
}
}
attr {
key: "type"
value {
placeholder: "macro_pin"
}
}
attr {
key: "x"
value {
f: 20
}
}
attr {
key: "x_offset"
value {
f: 0
}
}
attr {
key: "y"
value {
f: 45
}
}
attr {
key: "y_offset"
value {
f: 0
}
}
}
node {
name: "Grp_2/Pinput"
attr {
key: "macro_name"
value {
placeholder: "Grp_2"
}
}
attr {
key: "type"
value {
placeholder: "macro_pin"
}
}
attr {
key: "x"
value {
f: 20
}
}
attr {
key: "x_offset"
value {
f: 0
}
}
attr {
key: "y"
value {
f: 45
}
}
attr {
key: "y_offset"
value {
f: 0
}
}
}

0 comments on commit 25720c8

Please sign in to comment.