Commit f6cff733 by ZhiangWang033

code flow integration

parent fe1d1a7e
...@@ -259,10 +259,13 @@ class Clustering: ...@@ -259,10 +259,13 @@ class Clustering:
# origin and threshold as step size to grid the bounding box # origin and threshold as step size to grid the bounding box
# All the instances in each grid cell (in terms of the center of the instance) forms a new cluster # All the instances in each grid cell (in terms of the center of the instance) forms a new cluster
cluster_lx, cluster_ly, cluster_ux, cluster_uy = self.GetBoundingBox(self.vertices_in_cluster[cluster_id]) cluster_lx, cluster_ly, cluster_ux, cluster_uy = self.GetBoundingBox(self.vertices_in_cluster[cluster_id])
if (((cluster_ux - cluster_lx) <= self.step_threshold) if (((cluster_ux - cluster_lx) <= self.step_threshold)
and ((cluster_uy - cluster_ly) <= self.step_threshold)): and ((cluster_uy - cluster_ly) <= self.step_threshold)):
return None return None
Print("Break This Cluster")
cluster_x = (cluster_lx + cluster_ux) / 2.0 cluster_x = (cluster_lx + cluster_ux) / 2.0
cluster_y = (cluster_ly + cluster_uy) / 2.0 cluster_y = (cluster_ly + cluster_uy) / 2.0
num_x_grid = int((cluster_ux - cluster_x) / self.step_threshold) num_x_grid = int((cluster_ux - cluster_x) / self.step_threshold)
...@@ -507,5 +510,6 @@ class Clustering: ...@@ -507,5 +510,6 @@ class Clustering:
cmd = "rm " + file_name cmd = "rm " + file_name
os.system(cmd) os.system(cmd)
def GetNumClusters(self):
return len(self.vertices_in_cluster)
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
import os
import argparse
import time
import shutil
import sys
from math import sqrt
sys.path.append('../Clustering/src')
sys.path.append('../Gridding/src')
sys.path.append('../Grouping/src')
sys.path.append('../FormatTranslators/src')
from clustering import Clustering
from gridding import GriddingLefDefInterface
from grouping import Grouping
from FormatTranslators import LefDef2ProBufFormat
setup_file = "setup.tcl"
design = "ariane"
macro_lefs = ["./lefs/fakeram45_256x16.lef"]
##############################################
### Call Gridding Function
##############################################
gridding_src_dir = '../Gridding/src'
tolerance = 0.01
min_n_rows = 30
min_n_cols = 30
max_n_rows = 50
max_n_cols = 50
max_rows_times_cols = 3000
gridding = GriddingLefDefInterface(gridding_src_dir, design, setup_file, tolerance,
min_n_rows, min_n_cols, max_n_rows, max_n_cols,
max_rows_times_cols)
num_rows = gridding.GetNumRows()
num_cols = gridding.GetNumCols()
##############################################
### Call Grouping Function
##############################################
grouping_src_dir = '../Grouping/src'
grouping_rpt_dir = 'grouping_rpt'
K_in = 1
K_out = 1
global_net_threshold = 300
grouping = Grouping(design, num_rows, num_cols, K_in, K_out, setup_file, global_net_threshold, grouping_src_dir)
# clean the rpt_dir
if not os.path.exists(grouping_rpt_dir):
os.mkdir(grouping_rpt_dir)
cmd = "mv " + design + ".fix " + grouping_rpt_dir
os.system(cmd)
cmd = "mv " + design + ".fix.old " + grouping_rpt_dir
os.system(cmd)
fixed_file = grouping_rpt_dir + "/" + design + ".fix.old"
##############################################
### Call Clustering Function
##############################################
clustering_src_dir = '../Clustering/src'
chip_width = gridding.GetChipWidth()
chip_height = gridding.GetChipHeight()
num_std_cells = gridding.GetNumStdCells()
Nparts = 500
# Based on the description of circuit training, [see line 180 at grouper.py]
# we set the following thresholds
step_threshold = sqrt(chip_width * chip_height) / 100.0
distance = step_threshold / 2.0
max_num_vertices = num_std_cells / Nparts / 4
Replace = False
print("[INFO] step_threshold : ", step_threshold)
print("[INFO] distance : ", distance)
print("[INFO] max_num_vertices : ", max_num_vertices)
clustering = Clustering(design, clustering_src_dir, fixed_file, step_threshold, distance,
max_num_vertices, global_net_threshold, Nparts, setup_file, Replace)
cluster_def = "./results/OpenROAD/clustered_netlist.def"
cluster_lef = "./results/OpenROAD/clusters.lef"
######################################################################
### Convert the clustered netlist to the Protocol Buffer Format
######################################################################
translator_src_dir = '../FormatTranslators/src'
openroad_exe = translator_src_dir + "/utils/openroad"
lef_list = []
lef_list.append(cluster_lef)
for macro_lef in macro_lefs:
lef_list.append(macro_lef)
LefDef2ProBufFormat(lef_list, cluster_def, design, openroad_exe, global_net_threshold)
### Print Summary Information
print("*"*80)
print("[INFO] number of clusters : ", clustering.GetNumClusters())
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
set design "ariane"
set top_design "ariane"
set netlist "./design/ariane.v"
# def file generated by iSpatial flow
# where all the instances have been placed
set def_file "./design/ariane.def"
set ALL_LEFS "
./lefs/NangateOpenCellLibrary.tech.lef
./lefs/NangateOpenCellLibrary.macro.mod.lef
./lefs/fakeram45_256x16.lef
"
set LIB_BC "
./libs/NangateOpenCellLibrary_typical.lib
./libs/fakeram45_256x16.lib
"
set site "FreePDK45_38x28_10R_NP_162NW_34O"
foreach lef_file ${ALL_LEFS} {
read_lef $lef_file
}
foreach lib_file ${LIB_BC} {
read_liberty $lib_file
}
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
import os import os
from math import floor from math import floor
from math import ceil from math import ceil
import shutil
import sys
sys.path.append('./utils')
# Note that we use the center point of an object (macro, grid) # Note that we use the center point of an object (macro, grid)
# to represent the position of that object # to represent the position of that object
...@@ -81,9 +84,9 @@ def PlaceMacros(macro_map, grid_list, chip_width, chip_height, n): ...@@ -81,9 +84,9 @@ def PlaceMacros(macro_map, grid_list, chip_width, chip_height, n):
grid_height = grid.height_ grid_height = grid.height_
# update covered grids # update covered grids
min_col_id = floor(lx / grid_width) min_col_id = floor(lx / grid_width)
max_col_id = ceil(ux / grid_width) max_col_id = floor(ux / grid_width)
min_row_id = floor(ly / grid_height) min_row_id = floor(ly / grid_height)
max_row_id = ceil(uy / grid_height) max_row_id = floor(uy / grid_height)
for i in range(min_row_id, max_row_id + 1): for i in range(min_row_id, max_row_id + 1):
for j in range(min_col_id, max_col_id + 1): for j in range(min_col_id, max_col_id + 1):
grid_id = i * n + j # n is the num_cols grid_id = i * n + j # n is the num_cols
...@@ -115,6 +118,14 @@ def Gridding(macro_width_list, macro_height_list, ...@@ -115,6 +118,14 @@ def Gridding(macro_width_list, macro_height_list,
macro_map = dict(sorted(macro_map.items(), key=lambda item: item[1][0] * item[1][1], reverse = True)) macro_map = dict(sorted(macro_map.items(), key=lambda item: item[1][0] * item[1][1], reverse = True))
macro_bbox = [] # (lx, ly, ux, uy) for each bounding box macro_bbox = [] # (lx, ly, ux, uy) for each bounding box
print("*"*80)
print("[INFO] Outline Information : outline_width =", chip_width, " outline_height =", chip_height)
print("\n")
print("[INFO] Sorted Macro Information")
for key, value in macro_map.items():
print("macro_" + str(key), " macro_width =", round(value[0], 2), " macro_height =", round(value[1], 2), " macro_area =", round(value[0] * value[1], 2))
print("\n")
# we use m for max_n_rows and n for max_n_cols # we use m for max_n_rows and n for max_n_cols
m_best = -1 m_best = -1
n_best = -1 n_best = -1
...@@ -174,6 +185,97 @@ def Gridding(macro_width_list, macro_height_list, ...@@ -174,6 +185,97 @@ def Gridding(macro_width_list, macro_height_list,
return m_opt, n_opt return m_opt, n_opt
class GriddingLefDefInterface:
def __init__(self, src_dir, design, setup_file = "setup.tcl", tolerance = 0.01,
min_n_rows = 10, min_n_cols = 10, max_n_rows = 100, max_n_cols = 100,
max_rows_times_cols = 3000):
self.src_dir = src_dir
self.design = design
self.setup_file = setup_file
self.tolerance = tolerance
self.min_n_rows = min_n_rows
self.min_n_cols = min_n_cols
self.max_n_rows = max_n_rows
self.max_n_cols = max_n_cols
self.max_rows_times_cols = max_rows_times_cols
self.macro_width_list = []
self.macro_height_list = []
self.chip_width = 0.0
self.chip_height = 0.0
self.num_std_cells = 0
self.extract_hypergraph_file = self.src_dir + '/utils/extract_hypergraph.tcl'
self.openroad_exe = self.src_dir + "/utils/openroad"
self.GenerateHypergraph()
self.ExtractInputs()
self.m_opt, self.n_opt = Gridding(self.macro_width_list, self.macro_height_list, self.chip_width, self.chip_height, self.tolerance,
self.min_n_rows, self.min_n_cols, self.max_n_rows, self.max_n_cols, self.max_rows_times_cols)
def GetNumRows(self):
return self.m_opt
def GetNumCols(self):
return self.n_opt
def GetChipWidth(self):
return self.chip_width
def GetChipHeight(self):
return self.chip_height
def GetNumStdCells(self):
return self.num_std_cells
def GenerateHypergraph(self):
# Extract hypergraph from netlist
temp_file = os.getcwd() + "/extract_hypergraph.tcl"
cmd = "cp " + self.setup_file + " " + temp_file
os.system(cmd)
with open(self.extract_hypergraph_file) as f:
content = f.read().splitlines()
f.close()
f = open(temp_file, "a")
f.write("\n")
for line in content:
f.write(line + "\n")
f.close()
cmd = self.openroad_exe + " " + temp_file
os.system(cmd)
cmd = "rm " + temp_file
os.system(cmd)
def ExtractInputs(self):
file_name = os.getcwd() + "/rtl_mp/" + self.design + ".hgr.outline"
with open(file_name) as f:
content = f.read().splitlines()
f.close()
items = content[0].split()
self.chip_width = float(items[2]) - float(items[0])
self.chip_height = float(items[3]) - float(items[1])
file_name = os.getcwd() + "/rtl_mp/" + self.design + ".hgr.instance"
with open(file_name) as f:
content = f.read().splitlines()
f.close()
for line in content:
items = line.split()
if (items[1] == "1"):
self.macro_width_list.append(float(items[4]) - float(items[2]))
self.macro_height_list.append(float(items[5]) - float(items[3]))
else:
self.num_std_cells += 1
rpt_dir = os.getcwd() + "/rtl_mp"
shutil.rmtree(rpt_dir)
if __name__ == "__main__": if __name__ == "__main__":
# Just test # Just test
macro_width_list = [1, 2, 3.5, 3.5, 2.5] macro_width_list = [1, 2, 3.5, 3.5, 2.5]
......
#######################################################################
### Author: Zhiang, May, 2022
### Uses OpenROAD API to convert the netlist to a hypergraph (in hemtis format)
### This file cannot be used directly. It will be called by
### generate_cluster.py
### All the parameters set here are meaningless.
### !!! Please don't touch this file !!!
########################################################################
read_def $def_file
#Generate the hypergraph
partition_design -max_num_inst 2000000 -min_num_inst 40000 \
-max_num_macro 12 -min_num_macro 4 \
-net_threshold 20 -virtual_weight 50 \
-num_hop 0 -timing_weight 1000 \
-report_file ${top_design}.hgr
exit
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
set design "ariane"
set top_design "ariane"
set netlist "./design/ariane.v"
# def file generated by iSpatial flow
# where all the instances have been placed
set def_file "./design/ariane.def"
set ALL_LEFS "
./lefs/NangateOpenCellLibrary.tech.lef
./lefs/NangateOpenCellLibrary.macro.mod.lef
./lefs/fakeram45_256x16.lef
"
set LIB_BC "
./libs/NangateOpenCellLibrary_typical.lib
./libs/fakeram45_256x16.lib
"
set site "FreePDK45_38x28_10R_NP_162NW_34O"
foreach lef_file ${ALL_LEFS} {
read_lef $lef_file
}
foreach lib_file ${LIB_BC} {
read_liberty $lib_file
}
import os
import argparse
import time
import shutil
import sys
sys.path.append('../src')
from gridding import GriddingLefDefInterface
if __name__ == '__main__':
design = "ariane"
src_dir = "../src"
setup_file = "setup.tcl"
tolerance = 0.1
GriddingLefDefInterface(src_dir, design, setup_file, tolerance)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment