From 25720c85c3d273e7883436a7742f454c80f8a6fb Mon Sep 17 00:00:00 2001 From: Circuit Training Team Date: Fri, 5 Aug 2022 10:42:46 -0700 Subject: [PATCH] Assign the correct orientation to the netlist when writing it out. PiperOrigin-RevId: 465597131 Change-Id: I62fccf540245f3319d35103cfab55839bcb4118e --- circuit_training/grouping/grouping.py | 2 +- circuit_training/grouping/grouping_test.py | 30 ++ ...le_grouped_soft_macro_not_bloated_s.pb.txt | 317 ++++++++++++++++++ 3 files changed, 348 insertions(+), 1 deletion(-) create mode 100644 circuit_training/grouping/testdata/simple_grouped_soft_macro_not_bloated_s.pb.txt diff --git a/circuit_training/grouping/grouping.py b/circuit_training/grouping/grouping.py index bec3f2a..416d152 100644 --- a/circuit_training/grouping/grouping.py +++ b/circuit_training/grouping/grouping.py @@ -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) diff --git a/circuit_training/grouping/grouping_test.py b/circuit_training/grouping/grouping_test.py index ff4d255..5262c2b 100644 --- a/circuit_training/grouping/grouping_test.py +++ b/circuit_training/grouping/grouping_test.py @@ -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): @@ -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) diff --git a/circuit_training/grouping/testdata/simple_grouped_soft_macro_not_bloated_s.pb.txt b/circuit_training/grouping/testdata/simple_grouped_soft_macro_not_bloated_s.pb.txt new file mode 100644 index 0000000..2021ab4 --- /dev/null +++ b/circuit_training/grouping/testdata/simple_grouped_soft_macro_not_bloated_s.pb.txt @@ -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 + } + } +}