Simple framework for physical chip design (place & route) based on KLayout.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

66 lines
1.8 KiB

<?xml version="1.0" encoding="utf-8"?>
<klayout-macro>
<description/>
<version/>
<category>pymacros</category>
<prolog/>
<epilog/>
<doc/>
<autorun>false</autorun>
<autorun-early>false</autorun-early>
<shortcut/>
<show-in-menu>false</show-in-menu>
<group-name/>
<menu-path/>
<interpreter>python</interpreter>
<dsl-interpreter-name/>
<text># === LEGALIZATION ===
"""
Legalization (or detail-placement) converts the rough global placement solution into a
legal placement solution. A legal placement must have no overlaps and cells must be properly
aligned to the rows.
"""
from kpnr.legalizer.tetris import TetrisLegalizer
from kpnr.legalizer.densefirst import DenseFirstLegalizer
from kpnr.legalizer.annealing_legalizer import AnnealingLegalizer
importlib.reload(kpnr.legalizer.densefirst)
logger.info('Start legalization.')
# Get initial positions from the layout.
fixed_circuits = set()
fixed_circuits.update({n for n in fixed_positions})
initial_positions = dict()
for inst in design.top_cell.each_inst():
pos = inst.trans.disp
inst_id = inst.property('circuit_id')
if inst_id:
initial_positions[inst_id] = (pos.x, pos.y)
is_fixed = inst.property('fixed')
if is_fixed:
fixed_circuits.add(inst_id)
legalizer = DenseFirstLegalizer(row_height=row_height, x_grid_pitch=x_grid_pitch)
# Convert global placement result into legal placements.
cell_transf = legalizer.legalize(
design.top_circuit,
core_area=design.core_area.bbox(),
positions=initial_positions,
cell_shapes=cell_shapes
)
# Update positions of the cells.
for inst_id, trans in cell_transf.items():
if inst_id in design.cell_instances_by_subcircuit_id:
design.cell_instances_by_subcircuit_id[inst_id].trans = trans
else:
logger.warning('Cell not found: {}'.format(inst_id))
logger.info('Legalization done.')</text>
</klayout-macro>