4.1. Auto floorplan homogeneous designΒΆ

This example demonstate how to render FPGA Tile using FloorPlanViz class User can provide external script to render tiles, by default the rendering is based on initial_placement class.

This script can be used for shaping and placement of the modules before place and route.

../_images/_fpga_auto_initial_placement.svg
import glob
import math
import logging

import spydrnet as sdn
from spydrnet_physical.util import OpenFPGA, initial_hetero_placement
from spydrnet_physical.util import FPGAGridGen, FloorPlanViz

logger = logging.getLogger("spydrnet_logs")
sdn.enable_file_logging(LOG_LEVEL="INFO")

STYLE_SHEET = """
    .over_util {fill:#b22222 !important}
    line {stroke-width: 30}
    text{font-family: Lato; font-style: italic; font-size: 250px;}
"""

SCALE = 100
CPP = math.floor(0.46 * SCALE)
SC_HEIGHT = math.floor(2.72 * SCALE)

PROP = "VERILOG.InlineConstraints"


def main():
    """
    Main method
    """
    proj = "../homogeneous_fabric"
    source_files = glob.glob(f"{proj}/*_Verilog/lb/*.v")
    source_files += glob.glob(f"{proj}/*_Verilog/routing/*.v")
    source_files += glob.glob(f"{proj}/*_Verilog/sub_module/*.v")
    source_files += glob.glob(f"{proj}/*_Verilog/fpga_top.v")

    # Create OpenFPGA object
    fpga = OpenFPGA(grid=(4, 4), verilog_files=source_files)

    # Convert wires to bus structure
    fpga.merge_all_grid_ios()

    # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    #           Floorplan visualization
    # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    fpga_grid = FPGAGridGen(
        design_name="FPGA4x4",
        layout="4x4",
        arch_file=f"{proj}/FPGA44_Task/arch/k6_N10_tileable.xml",
        release_root=None,
    )

    fpga.SC_HEIGHT = SC_HEIGHT
    fpga.CPP = CPP
    fpga.SC_GRID = CPP * SC_HEIGHT

    fpga_grid.enumerate_grid()
    fpga.load_grid(fpga_grid)
    fpga.annotate_area_information(f"{proj}/area_info.txt", skipline=1)

    fpga.register_placement_creator(initial_hetero_placement)
    fpga.show_utilization_data()

    # Uncomment this to set module dimensions
    # ====================================================================
    # m = {}
    # m["clb_w"], m["clb_h"] = 360, 8
    # m["cbx11_w"], m["cbx11_h"] = 280, 4
    # m["bottom_cbx_w"], m["bottom_cbx_h"] = 280, 4
    # m["top_cbx_w"], m["top_cbx_h"] = 280, 4

    # m["cby11_w"], m["cby11_h"] = 50, 6
    # m["left_cby_w"], m["left_cby_h"] = 50, 6
    # m["right_cby_w"], m["right_cby_h"] = 50, 6
    # fpga.placement_creator.update_shaping_param(m)
    # ====================================================================

    fpga.placement_creator.derive_sb_paramters()
    fpga.placement_creator.create_shapes()

    # # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    # #           Adding Margin
    # # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    shapes = fpga.placement_creator.module_shapes

    for module in ["cbx_1__0_", "cbx_1__1_", "cbx_1__4_", "grid_clb"]:
        shapes[module]["POINTS"][0] -= 16
        shapes[module]["PLACEMENT"][0] += 8

    for module in ["cby_0__1_", "cby_1__1_", "cby_4__1_", "grid_clb"]:
        shapes[module]["POINTS"][1] -= 2
        shapes[module]["PLACEMENT"][1] += 1

    fpga.create_placement()
    fpga.show_placement_data(filename="_homogeneous_placement.txt")
    fpga.show_utilization_data()
    fpga.design_top_stat()
    fpga.save_shaping_data("*", scale=1/SCALE)

    fpga.update_module_label()
    fpga.show_utilization_data()

    fpga.update_module_label(
        get_label=lambda x: f"{int(x.data[PROP]['WIDTH'])/CPP:.1f}" +
                            f"x{int(x.data[PROP]['HEIGHT'])/SC_HEIGHT:.1f}" +
                            f"\n[{x.utilization:.0%}]")
    fpga.show_utilization_data()

    # # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    # #           Adjust Floorplan
    # # = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

    fp = FloorPlanViz(fpga.top_module)
    fp.compose(skip_connections=True, skip_pins=True)
    fp.custom_style_sheet = STYLE_SHEET
    dwg = fp.get_svg()
    # This adds placment grid markers
    dwg.add(fpga.placement_creator.design_grid.render_grid(return_group=True))

    # This standard cell grid
    pattern = dwg.pattern(size=(2 * CPP, 2 * SC_HEIGHT),
                          patternUnits="userSpaceOnUse")
    pattern.add(dwg.circle(center=(4, 4), r=4, fill="black"))
    pattern.add(dwg.circle(center=(4, SC_HEIGHT + 4), r=4, fill="red"))
    dwg.defs.add(pattern)
    dwg.defs.elements[0].elements[0].attribs["fill"] = pattern.get_funciri()

    dwg.saveas("_fpga_auto_initial_placement.svg", pretty=True, indent=4)


if __name__ == "__main__":
    main()

Placement information

 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
            INSTANCE               MODULE LOC_X    LOC_Y    WIDTH   HEIGHT    SHAPE               POINTS
 = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
grid_clb_1__1_       grid_clb              3128  3536  3864  4896 rect     
grid_clb_1__2_       grid_clb              3128  10608  3864  4896 rect     
grid_clb_1__3_       grid_clb              3128  17680  3864  4896 rect     
grid_clb_1__4_       grid_clb              3128  24752  3864  4896 rect     
grid_clb_2__1_       grid_clb              9108  3536  3864  4896 rect     
grid_clb_2__2_       grid_clb              9108  10608  3864  4896 rect     
grid_clb_2__3_       grid_clb              9108  17680  3864  4896 rect     
grid_clb_2__4_       grid_clb              9108  24752  3864  4896 rect     
grid_clb_3__1_       grid_clb              15088  3536  3864  4896 rect     
grid_clb_3__2_       grid_clb              15088  10608  3864  4896 rect     
grid_clb_3__3_       grid_clb              15088  17680  3864  4896 rect     
grid_clb_3__4_       grid_clb              15088  24752  3864  4896 rect     
grid_clb_4__1_       grid_clb              21068  3536  3864  4896 rect     
grid_clb_4__2_       grid_clb              21068  10608  3864  4896 rect     
grid_clb_4__3_       grid_clb              21068  17680  3864  4896 rect     
grid_clb_4__4_       grid_clb              21068  24752  3864  4896 rect     
sb_0__0_             sb_0__0_               920   544  2530  3264 cross    
sb_0__1_             sb_0__1_               920  8160  2760  2720 cross    
sb_0__2_             sb_0__1_               920  15232  2760  2720 cross    
sb_0__3_             sb_0__1_               920  22304  2760  2720 cross    
sb_0__4_             sb_0__4_               920  29376  2530  3264 cross    
sb_1__0_             sb_1__0_              6670   544  2760  3808 cross    
sb_2__0_             sb_1__0_              12650   544  2760  3808 cross    
sb_3__0_             sb_1__0_              18630   544  2760  3808 cross    
sb_1__1_             sb_1__1_              6440  7616  3220  3808 cross    
sb_1__2_             sb_1__1_              6440  14688  3220  3808 cross    
sb_1__3_             sb_1__1_              6440  21760  3220  3808 cross    
sb_2__1_             sb_1__1_              12420  7616  3220  3808 cross    
sb_2__2_             sb_1__1_              12420  14688  3220  3808 cross    
sb_2__3_             sb_1__1_              12420  21760  3220  3808 cross    
sb_3__1_             sb_1__1_              18400  7616  3220  3808 cross    
sb_3__2_             sb_1__1_              18400  14688  3220  3808 cross    
sb_3__3_             sb_1__1_              18400  21760  3220  3808 cross    
sb_1__4_             sb_1__4_              6670  28832  2760  3808 cross    
sb_2__4_             sb_1__4_              12650  28832  2760  3808 cross    
sb_3__4_             sb_1__4_              18630  28832  2760  3808 cross    
sb_4__0_             sb_4__0_              24610   544  2530  3264 cross    
sb_4__1_             sb_4__1_              24380  8160  2760  2720 cross    
sb_4__2_             sb_4__1_              24380  15232  2760  2720 cross    
sb_4__3_             sb_4__1_              24380  22304  2760  2720 cross    
sb_4__4_             sb_4__4_              24610  29376  2530  3264 cross    
cbx_1__1_            cbx_1__1_             4048  8704  2024  1632 rect     
cbx_1__2_            cbx_1__1_             4048  15776  2024  1632 rect     
cbx_1__3_            cbx_1__1_             4048  22848  2024  1632 rect     
cbx_2__1_            cbx_1__1_             10028  8704  2024  1632 rect     
cbx_2__2_            cbx_1__1_             10028  15776  2024  1632 rect     
cbx_2__3_            cbx_1__1_             10028  22848  2024  1632 rect     
cbx_3__1_            cbx_1__1_             16008  8704  2024  1632 rect     
cbx_3__2_            cbx_1__1_             16008  15776  2024  1632 rect     
cbx_3__3_            cbx_1__1_             16008  22848  2024  1632 rect     
cbx_4__1_            cbx_1__1_             21988  8704  2024  1632 rect     
cbx_4__2_            cbx_1__1_             21988  15776  2024  1632 rect     
cbx_4__3_            cbx_1__1_             21988  22848  2024  1632 rect     
cby_1__1_            cby_1__1_             7360  4624  1380  2720 rect     
cby_1__2_            cby_1__1_             7360  11696  1380  2720 rect     
cby_1__3_            cby_1__1_             7360  18768  1380  2720 rect     
cby_1__4_            cby_1__1_             7360  25840  1380  2720 rect     
cby_2__1_            cby_1__1_             13340  4624  1380  2720 rect     
cby_2__2_            cby_1__1_             13340  11696  1380  2720 rect     
cby_2__3_            cby_1__1_             13340  18768  1380  2720 rect     
cby_2__4_            cby_1__1_             13340  25840  1380  2720 rect     
cby_3__1_            cby_1__1_             19320  4624  1380  2720 rect     
cby_3__2_            cby_1__1_             19320  11696  1380  2720 rect     
cby_3__3_            cby_1__1_             19320  18768  1380  2720 rect     
cby_3__4_            cby_1__1_             19320  25840  1380  2720 rect     
cby_0__1_            cby_0__1_              920  4080  1840  3808 rect     
cby_0__2_            cby_0__1_              920  11152  1840  3808 rect     
cby_0__3_            cby_0__1_              920  18224  1840  3808 rect     
cby_0__4_            cby_0__1_              920  25296  1840  3808 rect     
cbx_1__4_            cbx_1__4_             3818  29920  2484  2720 rect     
cbx_2__4_            cbx_1__4_             9798  29920  2484  2720 rect     
cbx_3__4_            cbx_1__4_             15778  29920  2484  2720 rect     
cbx_4__4_            cbx_1__4_             21758  29920  2484  2720 rect     
cby_4__4_            cby_4__1_             25300  25296  1840  3808 rect     
cby_4__3_            cby_4__1_             25300  18224  1840  3808 rect     
cby_4__2_            cby_4__1_             25300  11152  1840  3808 rect     
cby_4__1_            cby_4__1_             25300  4080  1840  3808 rect     
cbx_4__0_            cbx_1__0_             21758   544  2484  2720 rect     
cbx_3__0_            cbx_1__0_             15778   544  2484  2720 rect     
cbx_2__0_            cbx_1__0_             9798   544  2484  2720 rect     
cbx_1__0_            cbx_1__0_             3818   544  2484  2720 rect     

Total running time of the script: ( 0 minutes 0.000 seconds)

Gallery generated by Sphinx-Gallery