From 68488bb196e3f7d59899c7bfa1b29b06d3333be5 Mon Sep 17 00:00:00 2001 From: Ganesh Gore Date: Sun, 5 Jan 2025 15:41:23 -0700 Subject: [PATCH] Added option to add segments --- spydrnet_physical/util/rrgraph_uncompress.py | 19 ++++++++++++++++++ spydrnet_physical/util/rrgraph_utils.py | 21 +++++++++++++++++++- spydrnet_physical/util/tests/test_rrgraph.py | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/spydrnet_physical/util/rrgraph_uncompress.py b/spydrnet_physical/util/rrgraph_uncompress.py index a61c6905..6de959f1 100755 --- a/spydrnet_physical/util/rrgraph_uncompress.py +++ b/spydrnet_physical/util/rrgraph_uncompress.py @@ -92,3 +92,22 @@ def _switches_bin2xml(switches, xml_root=None): switch_root.append(sizing) xml_root.append(switch_root) return xml_root + + @staticmethod + def _segments_bin2xml(segments, xml_root=None): + if xml_root is None: + xml_root = XML("") + for segment_bin in segments: + segment_root = Element( + "segment", + id=str(segment_bin.id), + name=str(segment_bin.name), + length=str(segment_bin.length) + ) + if not segment_bin.resType == "uxsdInvalid": + segment_root.res_type= segment_bin.resType + + timing = update_attr(Element("timing"), segment_bin.timing.to_dict()) + segment_root.append(timing) + xml_root.append(segment_root) + return xml_root diff --git a/spydrnet_physical/util/rrgraph_utils.py b/spydrnet_physical/util/rrgraph_utils.py index b4c7d3c0..69a0a192 100644 --- a/spydrnet_physical/util/rrgraph_utils.py +++ b/spydrnet_physical/util/rrgraph_utils.py @@ -21,6 +21,7 @@ def __init__(self, width, height, vpr_arch, routing_chan): self.channels = {} self.channels["X"] = list(routing_chan for _ in range(width)) self.channels["Y"] = list(routing_chan for _ in range(width)) + self.segments = [] self.rrgraph_bin = rr_capnp.RrGraph.new_message() self.create_channels() @@ -88,6 +89,23 @@ def create_node(self, x, y, node_id, ptc_start, seg_type, side, tap=1): self.node_lookup[x - 1][y - 1].append(node) return node + def create_segment(self, name, length, res_type="uxsdInvalid", c_per_meter=0, r_per_meter=0): + rr = self.rrgraph_bin + rr.segments = rr_capnp.Segments.new_message() + + segment_ux = rr_capnp.Segment.new_message( + id=len(self.segments), + name=name, + length=int(length), + resType=res_type, + timing=rr_capnp.SegmentTiming.new_message( + cPerMeter=c_per_meter, + rPerMeter=r_per_meter + ) + ) + self.segments.append(segment_ux) + return segment_ux + def create_channels(self): # Channels rr = self.rrgraph_bin @@ -172,7 +190,7 @@ def _gen_rrgraph_xml( # channels = etree.Element("channels") channels = self._channels_bin2xml(self.rrgraph_bin.channels) switches = self._switches_bin2xml(self.switches) - # switches = self._switches_bin2xml(self.rrgraph_bin.switches) + segments = self._segments_bin2xml(self.segments) # rrgraph_segments_bin2xml(self.rrgraph_bin.channels, etree.Element("channels")) # rrgraph_block_types_bin2xml(self.rrgraph_bin.channels, etree.Element("channels")) # rrgraph_grid_bin2xml(self.rrgraph_bin.channels, etree.Element("channels")) @@ -180,6 +198,7 @@ def _gen_rrgraph_xml( # rrgraph_rr_edges_bin2xml(self.rrgraph_bin.channels, etree.Element("channels")) root.append(channels) root.append(switches) + root.append(segments) return root def write_rrgraph_xml( diff --git a/spydrnet_physical/util/tests/test_rrgraph.py b/spydrnet_physical/util/tests/test_rrgraph.py index ffb977ee..8a421685 100644 --- a/spydrnet_physical/util/tests/test_rrgraph.py +++ b/spydrnet_physical/util/tests/test_rrgraph.py @@ -154,7 +154,7 @@ def test_write_rrgraph_xml(self) -> None: - The root element's "tool_version" attribute matches the generated tool_version. """ - rrgraph_bin = rrgraph(6, 6, "vpr_arch", "routing_chan") + rrgraph_bin = rrgraph(6, 6, "vpr_arch", 160) tool_comment = self._gen_random_string(50) tool_name = self._gen_random_string(10)