Skip to content

Commit

Permalink
Merge pull request #291 from ALIGN-analoglayout/feature/python_pnr_hier
Browse files Browse the repository at this point in the history
Feature/python pnr hier
  • Loading branch information
stevenmburns authored Jan 6, 2020
2 parents 8bde77b + 841fcad commit 27b1731
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 30 deletions.
16 changes: 16 additions & 0 deletions PlaceRouteHierFlow/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <string>
#include <iostream>
#include <iomanip>
#include "./PnRDB/datatype.h"
#include "./PnRDB/PnRdatabase.h"
#include "./placer/Placer.h"
Expand Down Expand Up @@ -197,6 +198,21 @@ int main(int argc, char** argv ){
PnRdatabase DB(fpath, topcell, vfile, lfile, mfile, dfile); // construction of database
PnRDB::Drc_info drcInfo=DB.getDrc_info();
map<string, PnRDB::lefMacro> lefData = DB.checkoutSingleLEF();


if ( !skip_saving_state) {
queue<int> Q=DB.TraverseHierTree(); // traverse hierarchical tree in topological order
json jsonStrAry = json::array();
std::ofstream jsonStream;
jsonStream.open( opath + "__hierTree.json");
while (!Q.empty()) {
jsonStrAry.push_back( DB.CheckoutHierNode(Q.front()).name);
Q.pop();
}
jsonStream << std::setw(4) << jsonStrAry;
jsonStream.close();
}

queue<int> Q=DB.TraverseHierTree(); // traverse hierarchical tree in topological order

while (!Q.empty())
Expand Down
11 changes: 6 additions & 5 deletions align/cell_fabric/remove_duplicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,15 @@ def build_centerline_tbl( self):
isPorted = 'pin' in d
if isPorted:
assert netName == d['pin'], f"{netName} does not match {d['pin']}"

if layer in self.skip_layers: continue

assert layer in self.layers, (self.layers, layer)
twice_center = sum(rect[index]
for index in self.indicesTbl[self.layers[layer]][0])
if layer in self.layers:
twice_center = sum(rect[index]
for index in self.indicesTbl[self.layers[layer]][0])
tbl[layer][twice_center].append((rect, netName, isPorted))
else:
print( f"Layer {layer} not in {self.layers}")

tbl[layer][twice_center].append((rect, netName, isPorted))
return tbl


Expand Down
52 changes: 31 additions & 21 deletions align/pnr/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,24 @@ def f( gen, value, tag=""):
logger.warning( f"{pth} is not available; not importing subblock rectangles")
else:
found = True


if not found and input_dir is not None:

print( "blk.gdsFile:", blk.gdsFile, found, input_dir)
p = re.compile( r"^\./Results/(\S+)\.gds$")
m = p.match( blk.gdsFile)
if m:
pth = pathlib.Path( input_dir + "/" + m.groups()[0] + ".json")
pth = input_dir / (m.groups()[0] + ".json")
if not pth.is_file():
logger.warning( f"{pth} not found in input_dir")
print("not found", pth.name)
logger.error( f"{pth} not found in input_dir")
else:
print("found")
logger.warning( f"{pth} found in input_dir")
found = True
else:
logger.warning( f"{blk.gdsFile} does not end in .gds")
logger.error( f"{blk.gdsFile} does not end in .gds")

if found:
with pth.open( "rt") as fp:
Expand Down Expand Up @@ -287,24 +293,28 @@ def addt( obj, con):
d['bbox'] = cnv.bbox.toList()
d['terminals'] = cnv.terminals

for (idx,sh) in enumerate(cnv.rd.shorts):
if isinstance( sh, tuple) and len(sh) == 2:
p0, p1 = sh
logger.info( f"SH: {p0} {p1}")
term = { "layer": "M0", "netName": f"SH{idx}_{p0.netName}", "rect": p0.rect}
d['terminals'].append( term)
term = { "layer": "M0", "netName": f"SH{idx}_{p1.netName}", "rect": p1.rect}
d['terminals'].append( term)
else:
logger.error( f"Unknown short type: {sh}")


for (nm,lst) in cnv.rd.opens:
logger.info( f"OP: {nm} {lst}")
for (jdx,l) in enumerate(lst):
for (ly,r) in l:
term = { "layer": ly, "netName": f"OP_{nm}_{jdx}", "rect": r}
d['terminals'].append( term)
#
# Experiment for visualizing shorts and opens
#

# for (idx,sh) in enumerate(cnv.rd.shorts):
# if isinstance( sh, tuple) and len(sh) == 2:
# p0, p1 = sh
# logger.info( f"SH: {p0} {p1}")
# term = { "layer": "M0", "netName": f"SH{idx}_{p0.netName}", "rect": p0.rect}
# d['terminals'].append( term)
# term = { "layer": "M0", "netName": f"SH{idx}_{p1.netName}", "rect": p1.rect}
# d['terminals'].append( term)
# else:
# logger.error( f"Unknown short type: {sh}")


# for (nm,lst) in cnv.rd.opens:
# logger.info( f"OP: {nm} {lst}")
# for (jdx,l) in enumerate(lst):
# for (ly,r) in l:
# term = { "layer": ly, "netName": f"OP_{nm}_{jdx}", "rect": r}
# d['terminals'].append( term)

# multiply by ten make it be in JSON file units (angstroms) This is a mess!
rational_scaling( d, mul=10)
Expand Down
35 changes: 32 additions & 3 deletions align/pnr/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
import logging
import collections
import json
import re

from .db import hierNode
from .checkers import gen_viewer_json

logger = logging.getLogger(__name__)

def _generate_json(dbfile, variant, primitive_dir, pdk_dir, output_dir, check=False, extract=False):
def _generate_json(dbfile, variant, primitive_dir, pdk_dir, output_dir, check=False, extract=False, input_dir=None):

ret = {}
with open(dbfile,"rt") as fp:
hN = hierNode(json.load(fp))
res = gen_viewer_json( hN, pdk=pdk_dir, draw_grid=True, json_dir=str(primitive_dir), checkOnly=(check or extract), extract=extract)
res = gen_viewer_json( hN, pdk=pdk_dir, draw_grid=True, json_dir=str(primitive_dir), checkOnly=(check or extract), extract=extract, input_dir=input_dir)

if check or extract:
cnv, d = res
Expand Down Expand Up @@ -106,6 +107,31 @@ def generate_pnr(topology_dir, primitive_dir, pdk_dir, output_dir, subckt, nvari
print(f"\nCall to '{' '.join(cmd)}' failed with error message:\n\n{e.stderr.decode('utf-8')}")
return {}

def find_variant_names( nm):
p = re.compile( '^(.*)_(\d+)\.db\.json$')
variant_names = []
for file_ in results_dir.iterdir():
m = p.match( file_.name)
if m and m.groups()[0] == nm:
variant_names.append( f"{nm}_{m.groups()[1]}")
return variant_names

if check or extract:
with (results_dir / "__hierTree.json").open("rt") as fp:
order = json.load(fp)
print( "Topological order:", order)

assert order[-1] == subckt, f"Last in topological order should be the subckt {subckt} {order}"

# Process subblocks as well
for nm in order[:-1]:
for variant_name in find_variant_names(nm):
print("variant_name:", variant_name)
file_ = results_dir / ( variant_name + ".db.json")
print( "subblock:", file_.name)
# Hack: put results in input dir
_generate_json( file_, variant_name, primitive_dir, pdk_dir, working_dir, check, extract, input_dir=working_dir)

variants = collections.defaultdict(collections.defaultdict)
for file_ in results_dir.iterdir():
variant = file_.name.split('.')[0]
Expand All @@ -116,6 +142,9 @@ def generate_pnr(topology_dir, primitive_dir, pdk_dir, output_dir, subckt, nvari
elif file_.suffixes == ['.lef']:
variants[variant]['lef'] = file_
elif file_.suffixes == ['.db', '.json'] and (check or extract):
variants[variant].update(_generate_json(file_, variant, primitive_dir, pdk_dir, working_dir, check, extract))
print( ".db.json:", file_.name)
variants[variant].update(_generate_json(file_, variant, primitive_dir, pdk_dir, working_dir, check, extract, input_dir=working_dir))



return variants
4 changes: 3 additions & 1 deletion build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# % ln -sf $ALIGN_HOME/build/Makefile $ALIGN_WORK_DIR
# % make DESIGN=<design in $ALIGN_HOME/examples"

VENV=/opt/venv

EXAMPLES=${ALIGN_HOME}/examples

DESIGN=telescopic_ota
Expand All @@ -35,7 +37,7 @@ ${OUTPUT_DIR}/${DESIGN}_0.png: ${OUTPUT_DIR}/${DESIGN}_0.gds

# Convert schematic to GDS
${OUTPUT_DIR}/${DESIGN}_0.gds: ${EXAMPLES}/${DESIGN}/${DESIGN}.sp ${DESIGN}
$(call execute,align-service, /bin/bash -c "source /opt/venv/bin/activate && cd ${DESIGN} && schematic2layout.py ${EXAMPLES}/${DESIGN} -f ${EXAMPLES}/${DESIGN}/${DESIGN}.sp -s ${DESIGN} -p ${ALIGN_HOME}/${PDK_DIR} -flat ${FLAT}")
$(call execute,align-service, /bin/bash -c "source ${VENV}/bin/activate && cd ${DESIGN} && schematic2layout.py ${EXAMPLES}/${DESIGN} -f ${EXAMPLES}/${DESIGN}/${DESIGN}.sp -s ${DESIGN} -p ${ALIGN_HOME}/${PDK_DIR} -flat ${FLAT}")

${DESIGN}:
mkdir ${DESIGN}
Expand Down

0 comments on commit 27b1731

Please sign in to comment.