2023-05-05 05:51:30 +02:00
|
|
|
# See LICENSE for licensing information.
|
|
|
|
|
#
|
|
|
|
|
# Copyright (c) 2016-2023 Regents of the University of California, Santa Cruz
|
|
|
|
|
# All rights reserved.
|
|
|
|
|
#
|
|
|
|
|
from openram import debug
|
|
|
|
|
from openram.base.vector import vector
|
2023-05-09 22:23:01 +02:00
|
|
|
from openram.base.vector3d import vector3d
|
2023-05-05 05:51:30 +02:00
|
|
|
from openram.gdsMill import gdsMill
|
|
|
|
|
from openram.tech import GDS
|
|
|
|
|
from openram.tech import layer as tech_layer
|
|
|
|
|
from openram import OPTS
|
|
|
|
|
from .router_tech import router_tech
|
2023-05-29 18:18:55 +02:00
|
|
|
from .hanan_graph import hanan_graph
|
2023-06-04 17:46:59 +02:00
|
|
|
from .hanan_shape import hanan_shape
|
2023-05-05 05:51:30 +02:00
|
|
|
|
|
|
|
|
|
2023-05-29 18:18:55 +02:00
|
|
|
class hanan_router(router_tech):
|
2023-05-05 05:51:30 +02:00
|
|
|
"""
|
2023-05-29 18:18:55 +02:00
|
|
|
This is the router class that implements Hanan graph routing algorithm.
|
2023-05-05 05:51:30 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, layers, design, bbox=None, pin_type=None):
|
|
|
|
|
|
|
|
|
|
router_tech.__init__(self, layers, route_track_width=1)
|
|
|
|
|
|
|
|
|
|
self.layers = layers
|
|
|
|
|
self.design = design
|
|
|
|
|
self.gds_filename = OPTS.openram_temp + "temp.gds"
|
|
|
|
|
self.pins = {}
|
|
|
|
|
self.all_pins = set()
|
|
|
|
|
self.blockages = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def route(self, vdd_name="vdd", gnd_name="gnd"):
|
|
|
|
|
""" Route the given pins in the given order. """
|
2023-05-23 03:16:49 +02:00
|
|
|
#debug.info(1, "Running router for {}...".format(pins))
|
|
|
|
|
self.write_debug_gds(gds_name="before.gds")
|
2023-05-05 05:51:30 +02:00
|
|
|
|
|
|
|
|
# Prepare gdsMill to find pins and blockages
|
|
|
|
|
self.design.gds_write(self.gds_filename)
|
|
|
|
|
self.layout = gdsMill.VlsiLayout(units=GDS["unit"])
|
|
|
|
|
self.reader = gdsMill.Gds2reader(self.layout)
|
|
|
|
|
self.reader.loadFromFile(self.gds_filename)
|
|
|
|
|
|
|
|
|
|
# Find pins to be routed
|
|
|
|
|
self.find_pins(vdd_name)
|
|
|
|
|
self.find_pins(gnd_name)
|
|
|
|
|
|
|
|
|
|
# Find blockages
|
|
|
|
|
self.find_blockages()
|
|
|
|
|
|
2023-05-29 18:18:55 +02:00
|
|
|
# Create the hanan graph
|
2023-05-29 06:25:11 +02:00
|
|
|
# TODO: Remove this part later and route all pins
|
|
|
|
|
vdds = list(self.pins["vdd"])
|
|
|
|
|
vdds.sort()
|
|
|
|
|
pin_iter = iter(vdds)
|
2023-05-05 05:51:30 +02:00
|
|
|
vdd_0 = next(pin_iter)
|
2023-05-29 06:25:11 +02:00
|
|
|
next(pin_iter)
|
|
|
|
|
next(pin_iter)
|
|
|
|
|
next(pin_iter)
|
|
|
|
|
next(pin_iter)
|
|
|
|
|
next(pin_iter)
|
|
|
|
|
next(pin_iter)
|
2023-05-05 05:51:30 +02:00
|
|
|
vdd_1 = next(pin_iter)
|
2023-05-29 18:18:55 +02:00
|
|
|
self.hg = hanan_graph(self)
|
|
|
|
|
self.hg.create_graph(vdd_0, vdd_1)
|
2023-05-05 05:51:30 +02:00
|
|
|
|
2023-05-09 22:23:01 +02:00
|
|
|
# Find the shortest path from source to target
|
2023-06-01 23:24:40 +02:00
|
|
|
path = self.hg.find_shortest_path()
|
2023-05-09 22:23:01 +02:00
|
|
|
|
|
|
|
|
# Create the path shapes on layout
|
2023-05-29 06:25:11 +02:00
|
|
|
if path:
|
|
|
|
|
self.add_path(path)
|
|
|
|
|
debug.info(0, "Successfully routed")
|
|
|
|
|
else:
|
|
|
|
|
debug.info(0, "No path was found!")
|
2023-05-09 22:23:01 +02:00
|
|
|
|
2023-05-23 03:16:49 +02:00
|
|
|
self.write_debug_gds(gds_name="after.gds", source=vdd_0, target=vdd_1)
|
2023-05-05 05:51:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_pins(self, pin_name):
|
|
|
|
|
""" """
|
|
|
|
|
debug.info(1, "Finding all pins for {}".format(pin_name))
|
|
|
|
|
|
|
|
|
|
shape_list = self.layout.getAllPinShapes(str(pin_name))
|
|
|
|
|
pin_set = set()
|
|
|
|
|
for shape in shape_list:
|
|
|
|
|
layer, boundary = shape
|
|
|
|
|
# gdsMill boundaries are in (left, bottom, right, top) order
|
|
|
|
|
# so repack and snap to the grid
|
2023-05-09 22:23:01 +02:00
|
|
|
ll = vector(boundary[0], boundary[1])
|
|
|
|
|
ur = vector(boundary[2], boundary[3])
|
2023-05-05 05:51:30 +02:00
|
|
|
rect = [ll, ur]
|
2023-06-04 17:46:59 +02:00
|
|
|
pin = hanan_shape(pin_name, rect, layer)
|
2023-05-05 05:51:30 +02:00
|
|
|
pin_set.add(pin)
|
|
|
|
|
# Add these pins to the 'pins' dict
|
|
|
|
|
self.pins[pin_name] = pin_set
|
|
|
|
|
self.all_pins.update(pin_set)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_blockages(self):
|
|
|
|
|
""" """
|
2023-05-09 22:23:01 +02:00
|
|
|
debug.info(1, "Finding all blockages...")
|
2023-05-05 05:51:30 +02:00
|
|
|
|
|
|
|
|
for lpp in [self.vert_lpp, self.horiz_lpp]:
|
|
|
|
|
shapes = self.layout.getAllShapes(lpp)
|
|
|
|
|
for boundary in shapes:
|
|
|
|
|
# gdsMill boundaries are in (left, bottom, right, top) order
|
|
|
|
|
# so repack and snap to the grid
|
|
|
|
|
ll = vector(boundary[0], boundary[1])
|
|
|
|
|
ur = vector(boundary[2], boundary[3])
|
|
|
|
|
rect = [ll, ur]
|
2023-06-04 17:46:59 +02:00
|
|
|
new_shape = hanan_shape("blockage{}".format(len(self.blockages)),
|
2023-05-05 05:51:30 +02:00
|
|
|
rect,
|
2023-05-29 06:25:11 +02:00
|
|
|
lpp)
|
2023-05-05 05:51:30 +02:00
|
|
|
# If there is a rectangle that is the same in the pins,
|
|
|
|
|
# it isn't a blockage
|
2023-05-31 05:09:10 +02:00
|
|
|
if new_shape not in self.all_pins and not new_shape.contained_by_any(self.all_pins) and not self.blockage_contains(new_shape):
|
2023-05-29 06:25:11 +02:00
|
|
|
new_shape = new_shape.inflated_pin(multiple=1)
|
2023-05-31 05:09:10 +02:00
|
|
|
# Remove blockages contained by this new blockage
|
|
|
|
|
for i in range(len(self.blockages) - 1, -1, -1):
|
|
|
|
|
blockage = self.blockages[i]
|
2023-06-04 17:46:59 +02:00
|
|
|
# Remove the previous blockage contained by this new
|
|
|
|
|
# blockage
|
2023-05-31 05:09:10 +02:00
|
|
|
if new_shape.contains(blockage):
|
|
|
|
|
self.blockages.remove(blockage)
|
2023-06-04 17:46:59 +02:00
|
|
|
# Merge the previous blockage into this new blockage if
|
|
|
|
|
# they are aligning
|
|
|
|
|
elif new_shape.aligns(blockage):
|
|
|
|
|
new_shape.bbox([blockage])
|
|
|
|
|
self.blockages.remove(blockage)
|
2023-05-05 05:51:30 +02:00
|
|
|
self.blockages.append(new_shape)
|
|
|
|
|
|
|
|
|
|
|
2023-05-31 05:09:10 +02:00
|
|
|
def blockage_contains(self, shape):
|
2023-05-29 21:43:43 +02:00
|
|
|
"""
|
2023-05-31 05:09:10 +02:00
|
|
|
Return if this shape is contained by a blockage.
|
2023-05-29 21:43:43 +02:00
|
|
|
"""
|
|
|
|
|
|
2023-05-31 05:09:10 +02:00
|
|
|
for blockage in self.blockages:
|
|
|
|
|
if blockage.contains(shape):
|
2023-05-05 05:51:30 +02:00
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
2023-05-09 22:23:01 +02:00
|
|
|
def add_path(self, path):
|
2023-05-29 21:43:43 +02:00
|
|
|
""" Add the route path to the layout. """
|
2023-05-09 22:23:01 +02:00
|
|
|
|
2023-05-29 06:25:11 +02:00
|
|
|
coordinates = [x.center for x in path]
|
|
|
|
|
self.design.add_route(layers=self.layers,
|
|
|
|
|
coordinates=coordinates,
|
|
|
|
|
layer_widths=self.layer_widths)
|
2023-05-09 22:23:01 +02:00
|
|
|
|
|
|
|
|
|
2023-05-05 05:51:30 +02:00
|
|
|
def write_debug_gds(self, gds_name="debug_route.gds", source=None, target=None):
|
|
|
|
|
""" """
|
|
|
|
|
|
|
|
|
|
self.add_router_info(source, target)
|
|
|
|
|
self.design.gds_write(gds_name)
|
|
|
|
|
self.del_router_info()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_router_info(self, source=None, target=None):
|
|
|
|
|
""" """
|
|
|
|
|
|
|
|
|
|
# Display the inflated blockage
|
2023-05-31 05:09:10 +02:00
|
|
|
if "hg" in self.__dict__:
|
2023-05-29 18:18:55 +02:00
|
|
|
for blockage in self.hg.graph_blockages:
|
2023-05-31 05:09:10 +02:00
|
|
|
self.add_object_info(blockage, "blockage{}".format(self.get_zindex(blockage.lpp)))
|
2023-05-29 18:18:55 +02:00
|
|
|
for node in self.hg.nodes:
|
2023-05-23 03:16:49 +02:00
|
|
|
offset = (node.center.x, node.center.y)
|
2023-05-31 05:09:10 +02:00
|
|
|
self.design.add_label(text="n{}".format(node.center.z),
|
2023-05-23 03:16:49 +02:00
|
|
|
layer="text",
|
|
|
|
|
offset=offset)
|
2023-05-05 05:51:30 +02:00
|
|
|
if source:
|
2023-05-09 22:23:01 +02:00
|
|
|
self.add_object_info(source, "source")
|
2023-05-05 05:51:30 +02:00
|
|
|
if target:
|
2023-05-09 22:23:01 +02:00
|
|
|
self.add_object_info(target, "target")
|
2023-05-05 05:51:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def del_router_info(self):
|
|
|
|
|
""" """
|
|
|
|
|
|
|
|
|
|
lpp = tech_layer["text"]
|
|
|
|
|
self.design.objs = [x for x in self.design.objs if x.lpp != lpp]
|
2023-05-09 22:23:01 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_object_info(self, obj, label):
|
|
|
|
|
""" """
|
|
|
|
|
|
|
|
|
|
ll, ur = obj.rect
|
|
|
|
|
self.design.add_rect(layer="text",
|
|
|
|
|
offset=ll,
|
|
|
|
|
width=ur.x - ll.x,
|
|
|
|
|
height=ur.y - ll.y)
|
|
|
|
|
self.design.add_label(text=label,
|
|
|
|
|
layer="text",
|
|
|
|
|
offset=ll)
|