Note
Click here to download the full example code
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.
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 4048 3536 8464 7616 rect
grid_clb_1__2_ grid_clb 4048 16048 8464 7616 rect
grid_clb_1__3_ grid_clb 4048 28560 8464 7616 rect
grid_clb_1__4_ grid_clb 4048 41072 8464 7616 rect
grid_clb_2__1_ grid_clb 17848 3536 8464 7616 rect
grid_clb_2__2_ grid_clb 17848 16048 8464 7616 rect
grid_clb_2__3_ grid_clb 17848 28560 8464 7616 rect
grid_clb_2__4_ grid_clb 17848 41072 8464 7616 rect
grid_clb_3__1_ grid_clb 31648 3536 8464 7616 rect
grid_clb_3__2_ grid_clb 31648 16048 8464 7616 rect
grid_clb_3__3_ grid_clb 31648 28560 8464 7616 rect
grid_clb_3__4_ grid_clb 31648 41072 8464 7616 rect
grid_clb_4__1_ grid_clb 45448 3536 8464 7616 rect
grid_clb_4__2_ grid_clb 45448 16048 8464 7616 rect
grid_clb_4__3_ grid_clb 45448 28560 8464 7616 rect
grid_clb_4__4_ grid_clb 45448 41072 8464 7616 rect
sb_0__0_ sb_0__0_ 920 544 3220 2720 cross
sb_0__1_ sb_0__1_ 920 11424 4692 4352 cross
sb_0__2_ sb_0__1_ 920 23936 4692 4352 cross
sb_0__3_ sb_0__1_ 920 36448 4692 4352 cross
sb_0__4_ sb_0__4_ 920 48960 3220 2720 cross
sb_1__0_ sb_1__0_ 12420 544 5520 4080 cross
sb_2__0_ sb_1__0_ 26220 544 5520 4080 cross
sb_3__0_ sb_1__0_ 40020 544 5520 4080 cross
sb_1__1_ sb_1__1_ 10948 10064 8464 7072 cross
sb_1__2_ sb_1__1_ 10948 22576 8464 7072 cross
sb_1__3_ sb_1__1_ 10948 35088 8464 7072 cross
sb_2__1_ sb_1__1_ 24748 10064 8464 7072 cross
sb_2__2_ sb_1__1_ 24748 22576 8464 7072 cross
sb_2__3_ sb_1__1_ 24748 35088 8464 7072 cross
sb_3__1_ sb_1__1_ 38548 10064 8464 7072 cross
sb_3__2_ sb_1__1_ 38548 22576 8464 7072 cross
sb_3__3_ sb_1__1_ 38548 35088 8464 7072 cross
sb_1__4_ sb_1__4_ 12420 47600 5520 4080 cross
sb_2__4_ sb_1__4_ 26220 47600 5520 4080 cross
sb_3__4_ sb_1__4_ 40020 47600 5520 4080 cross
sb_4__0_ sb_4__0_ 53820 544 3220 2720 cross
sb_4__1_ sb_4__1_ 52348 11424 4692 4352 cross
sb_4__2_ sb_4__1_ 52348 23936 4692 4352 cross
sb_4__3_ sb_4__1_ 52348 36448 4692 4352 cross
sb_4__4_ sb_4__4_ 53820 48960 3220 2720 cross
cbx_1__1_ cbx_1__1_ 5980 11424 4600 4352 rect
cbx_1__2_ cbx_1__1_ 5980 23936 4600 4352 rect
cbx_1__3_ cbx_1__1_ 5980 36448 4600 4352 rect
cbx_2__1_ cbx_1__1_ 19780 11424 4600 4352 rect
cbx_2__2_ cbx_1__1_ 19780 23936 4600 4352 rect
cbx_2__3_ cbx_1__1_ 19780 36448 4600 4352 rect
cbx_3__1_ cbx_1__1_ 33580 11424 4600 4352 rect
cbx_3__2_ cbx_1__1_ 33580 23936 4600 4352 rect
cbx_3__3_ cbx_1__1_ 33580 36448 4600 4352 rect
cbx_4__1_ cbx_1__1_ 47380 11424 4600 4352 rect
cbx_4__2_ cbx_1__1_ 47380 23936 4600 4352 rect
cbx_4__3_ cbx_1__1_ 47380 36448 4600 4352 rect
cby_1__1_ cby_1__1_ 12880 4896 4600 4896 rect
cby_1__2_ cby_1__1_ 12880 17408 4600 4896 rect
cby_1__3_ cby_1__1_ 12880 29920 4600 4896 rect
cby_1__4_ cby_1__1_ 12880 42432 4600 4896 rect
cby_2__1_ cby_1__1_ 26680 4896 4600 4896 rect
cby_2__2_ cby_1__1_ 26680 17408 4600 4896 rect
cby_2__3_ cby_1__1_ 26680 29920 4600 4896 rect
cby_2__4_ cby_1__1_ 26680 42432 4600 4896 rect
cby_3__1_ cby_1__1_ 40480 4896 4600 4896 rect
cby_3__2_ cby_1__1_ 40480 17408 4600 4896 rect
cby_3__3_ cby_1__1_ 40480 29920 4600 4896 rect
cby_3__4_ cby_1__1_ 40480 42432 4600 4896 rect
cby_0__1_ cby_0__1_ 920 3536 2760 7616 rect
cby_0__2_ cby_0__1_ 920 16048 2760 7616 rect
cby_0__3_ cby_0__1_ 920 28560 2760 7616 rect
cby_0__4_ cby_0__1_ 920 41072 2760 7616 rect
cbx_1__4_ cbx_1__4_ 4508 48960 7544 2720 rect
cbx_2__4_ cbx_1__4_ 18308 48960 7544 2720 rect
cbx_3__4_ cbx_1__4_ 32108 48960 7544 2720 rect
cbx_4__4_ cbx_1__4_ 45908 48960 7544 2720 rect
cby_4__4_ cby_4__1_ 54280 41072 2760 7616 rect
cby_4__3_ cby_4__1_ 54280 28560 2760 7616 rect
cby_4__2_ cby_4__1_ 54280 16048 2760 7616 rect
cby_4__1_ cby_4__1_ 54280 3536 2760 7616 rect
cbx_4__0_ cbx_1__0_ 45908 544 7544 2720 rect
cbx_3__0_ cbx_1__0_ 32108 544 7544 2720 rect
cbx_2__0_ cbx_1__0_ 18308 544 7544 2720 rect
cbx_1__0_ cbx_1__0_ 4508 544 7544 2720 rect
Total running time of the script: ( 0 minutes 0.000 seconds)