Commit 2fa5afdc by sakundu

Updated clustred netlist generation flow

Signed-off-by: sakundu <sakundu@ucsd.edu>
parent 347de1d1
import os
import argparse
import time
import shutil
import sys
from math import sqrt
from gen_setup import gen_setup
run_dir = sys.argv[1]
output_dir = sys.argv[2]
run_dir = os.path.abspath(run_dir)
output_dir = os.path.abspath(output_dir)
## gen_setup create the setup.tcl file which is
## used in the later part of the code
design, halo_width, work_dir, setup_file = gen_setup(run_dir, output_dir)
tmp_dir = os.getcwd()
os.chdir(run_dir)
sys.path.append(f'{work_dir}/CodeElements/Clustering/src')
sys.path.append(f'{work_dir}/CodeElements/Gridding/src')
sys.path.append(f'{work_dir}/CodeElements/Grouping/src')
sys.path.append(f'{work_dir}/CodeElements/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 = f'{work_dir}/CodeElements/Gridding/src'
tolerance = 0.01
min_n_rows = 10
min_n_cols = 10
max_n_rows = 50
max_n_cols = 50
max_rows_times_cols = 3000
# halo_width = 5
gridding = GriddingLefDefInterface(gridding_src_dir, design, setup_file, tolerance, halo_width,
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 = f'{work_dir}/CodeElements/Grouping/src'
grouping_rpt_dir = f'{output_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 = f'{work_dir}/CodeElements/Clustering/src'
chip_width = gridding.GetChipWidth()
chip_height = gridding.GetChipHeight()
num_std_cells = gridding.GetNumStdCells()
grid_width = chip_width / num_cols
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) / 4.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,
grid_width, max_num_vertices, global_net_threshold, Nparts, setup_file,
output_dir, Replace)
cluster_def = f"{output_dir}/OpenROAD/clustered_netlist.def"
cluster_lef = f"{output_dir}/OpenROAD/clusters.lef"
os.chdir(tmp_dir)
import os
import re
import sys
def gen_setup(run_dir, output_dir):
design_setup = f'{run_dir}/design_setup.tcl'
lib_setup = f'{run_dir}/lib_setup.tcl'
fp = open(design_setup, "r")
lines = fp.readlines()
fp.close()
design = ''
site = ''
halo_width = ''
netlist_file = ''
def_file = ''
for line in lines:
words = line.split()
if len(words) == 3 and words[0] == 'set':
if words[1] == 'DESIGN':
design = words[2]
design = design.replace('"','')
elif words[1] == 'SITE':
site = words[2]
site = site.replace('"','')
elif words[1] == 'HALO_WIDTH':
halo_width = int(words[2])
### Other inputs lef and def ###
def_file = f'{run_dir}/def/{design}.def'
if not os.path.isfile(def_file):
print(f'Def: {def_file} do not exists.')
netlist_file = f'{run_dir}/def/{design}.v'
if not os.path.exists(netlist_file):
print(f'Netlist: {netlist_file} does not exists.')
tmp_dir = os.getcwd()
os.chdir(run_dir)
### Extract details of libs and lef ###
fp = open(lib_setup, 'r')
lines = fp.readlines()
fp.close()
lefdir = ''
libdir = ''
lib_files = []
lef_files = []
lefflag = False
libflag = False
for line in lines:
words = line.split()
if len(words) >= 3 and words[0] == 'set':
if words[1] == 'lefdir':
lefdir = words[2]
lefdir = lefdir.replace('"', '')
elif words[1] == 'libdir':
libdir = words[2]
libdir = libdir.replace('"','')
elif words[1] == 'lefs':
if words[2] == '"':
lefflag = True
libflag = False
else:
lef_files = words[2]
elif words[1] == 'libworst':
if words[2] == '"':
lefflag = False
libflag = True
elif 'glob' in words[2]:
for lib_file in os.listdir(libdir):
lib_files.append(libdir+'/'+lib_file)
elif lefflag:
words = line.split()
if words[0] == '"':
lefflag = False
else:
lef_file = re.search(r'([^\/]+\.(lef|tlef))', line)
if lef_file != None:
lef_files.append(lefdir+'/'+lef_file.group())
elif libflag:
words = line.split()
if words[0] == '"':
libflag = False
else:
lib_file = re.search(r'([^\/]+\.lib)', line)
if lib_file != None:
lib_files.append(libdir+'/'+lib_file.group())
os.chdir(tmp_dir)
### Write out Setup ###
if not os.path.exists(output_dir):
os.makedirs(output_dir)
fp = open(output_dir+'/setup.tcl', 'w')
fp.write(f'set design \"{design}\"\n')
fp.write(f'set top_design \"{design}\"\n')
fp.write(f'set netlist \"{netlist_file}\"\n')
fp.write(f'set def_file \"{def_file}\"\n')
fp.write(f'set ALL_LEFS \"\n')
for lef_file in lef_files:
fp.write(f' {lef_file}\n')
fp.write(f'\"\n')
fp.write(f'set LIB_BC \"\n')
for lib_file in lib_files:
fp.write(f' {lib_file}\n')
fp.write(f'\"\n')
fp.write(f'set site \"{site}\"\n')
fp.write('''foreach lef_file ${ALL_LEFS} {
read_lef $lef_file
}
foreach lib_file ${LIB_BC} {
read_liberty $lib_file
}''')
fp.close
work_dir = re.search(r'(/\S+/MacroPlacement)', os.path.abspath(run_dir)).group(1)
return design, halo_width, work_dir, output_dir+'/setup.tcl'
if __name__ == "__main__":
run_dir = sys.argv[1]
output_dir = sys.argv[2]
a, b, c, d = gen_setup(run_dir, output_dir)
print(a, b, c, d)
source /home/tool/anaconda3/etc/profile.d/conda.sh
conda activate py-tf
export PYTHONPATH=$PYTHONPATH:../../../../util/
cd $1
python ../../../../util/flow.py $1 output_CodeElement 2>&1 | tee log/codelement.log
#!/usr/bin/env bash
if [ $PHY_SYNTH -eq 1 ]; then
export PROJ_DIR=`pwd | grep -o '\S*/MacroPlacement'`
export BLOCK_NAME=`echo $PWD | awk -F'/' '{print $(NF-2)}'`
export TECH=`echo $PWD | awk -F'/' '{print $(NF-3)}'`
export OUTPUT_DIR="./output_${BLOCK_NAME}_${TECH}"
export NETLIST_FILE=`readlink -f *.pb.txt`
export HMETIS_DIR="/home/zf4_projects/DREAMPlace/sakundu/GB/CT/hmetis-1.5-linux"
export PLC_WRAPPER_MAIN="/home/zf4_projects/DREAMPlace/sakundu/GB/CT/plc_wrapper_main"
export CT_PATH="/home/zf4_projects/DREAMPlace/sakundu/GB/CT/circuit_training"
export HMETIS_DIR="${PROJ_DIR}/../../../GB/CT/hmetis-1.5-linux"
export PLC_WRAPPER_MAIN="${PROJ_DIR}/../../../GB/CT/plc_wrapper_main"
export CT_PATH="${PROJ_DIR}/../../../GB/CT/circuit_training"
bash -i ../../../../util/run_grp.sh 2>&1 | tee log/grouping.log
fi
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