Skip to content

Commit

Permalink
Added option to add segments
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshgore committed Jan 5, 2025
1 parent 03f66b4 commit 68488bb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
19 changes: 19 additions & 0 deletions spydrnet_physical/util/rrgraph_uncompress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<segments></segments>")
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
21 changes: 20 additions & 1 deletion spydrnet_physical/util/rrgraph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -172,14 +190,15 @@ 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"))
# rrgraph_rr_nodes_bin2xml(self.rrgraph_bin.channels, etree.Element("channels"))
# 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(
Expand Down
2 changes: 1 addition & 1 deletion spydrnet_physical/util/tests/test_rrgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 68488bb

Please sign in to comment.