"""This file contains OpenFPGA Architecture parser classIt is desigend to provide a API interface to probe architecrure related data"""fromxml.dom.minidomimportElementimportxml.etree.ElementTreeasETfromspydrnet_physical.util.shellimportlaunch_shell
[docs]classOpenFPGA_Arch:""" This is an architecture parser which parses the VPR and OpenFPGA XML files and provides easy interface APIs .. note:: The idea here is not to parse complete architecture and rebuild the openfpga and VPR mapping """
@propertydefpb_types(self):"""Returns list of pb_types in the architecture"""returnself._pb_types@propertydeftiles(self):"""Returns list of tiles in the architecture"""returnself._tiles@propertydeflayout(self):"""Returns selected layout name"""returnself._layoutdef_get_pb_types(self):return{pb.get("name"):(int(pb.get("width",1)),int(pb.get("height",1)))forpbinself.vpr_arch.findall("./tiles/tile")}def_get_tiles(self):return{tile.get("name"):(int(tile.get("width",1)),int(tile.get("height",1)))fortileinself.vpr_arch.findall("./tiles/tile")}
[docs]defget_width(self):"""Return width of selected layout"""returnself.width-2
[docs]defget_height(self):"""Return height of selected layout"""returnself.height-2
[docs]defget_layouts(self):""" Returns the dictionary of avaialble layouts in the architecture Returns: dict: Available layouts as a key and (width, height) as a value of each key """layout={}foreachinself.vpr_arch.find("layout").findall("fixed_layout"):layout[each.get("name")]=(int(each.get("width")),int(each.get("height")))returnlayout
[docs]defset_layout(self,layout_name):"""Set specific layout as primary layout"""layouts=self.get_layouts().keys()assert(layout_nameinself.get_layouts()),f"{layout_name} layout not found, [{', '.join(layouts)}]"self._layout=self.vpr_arch.find("layout").find(f"fixed_layout[@name='{layout_name}']")self.width=int(self._layout.attrib.get("width",1))self.height=int(self._layout.attrib.get("height",1))
[docs]defis_homogeneous(self):""" Checks if the device is homogeneous device or heterogenous if layout section contains anything other than `corner`, `periphery` and `fill` the device is consider as a homogeneous """raiseNotImplementedError("Not implemented yet")
[docs]defget_hetero_columns(self,pb_type):""" Returns columns numbers of given heterogenesous pb_type """return[]
[docs]defget_hetero_rows(self,pb_type):""" Returns row numbers of given heterogenesous pb_type """return[]