Commit 933fafee by Dinple

update on congestion

parent 5c5e93f5
...@@ -464,6 +464,13 @@ class PlacementCost(object): ...@@ -464,6 +464,13 @@ class PlacementCost(object):
+ abs(max(y_coord) - min(y_coord))) + abs(max(y_coord) - min(y_coord)))
return total_hpwl return total_hpwl
def abu(self, xx, n = 0.1):
xxs = sorted(xx, reverse = True)
cnt = math.floor(len(xxs)*n)
if cnt == 0:
return max(xxs)
return sum(xxs[0:cnt])/cnt
def get_V_congestion_cost(self) -> float: def get_V_congestion_cost(self) -> float:
""" """
compute average of top 10% of grid cell cong and take half of it compute average of top 10% of grid cell cong and take half of it
...@@ -513,29 +520,29 @@ class PlacementCost(object): ...@@ -513,29 +520,29 @@ class PlacementCost(object):
return float(sum_cong / cong_cnt) return float(sum_cong / cong_cnt)
def get_congestion_cost(self): def get_congestion_cost(self):
# return max(self.get_H_congestion_cost(), self.get_V_congestion_cost()) #return max(self.get_H_congestion_cost(), self.get_V_congestion_cost())
temp_cong = self.V_routing_cong + self.H_routing_cong return self.abu(self.V_routing_cong + self.H_routing_cong, 0.05)
# temp_cong = [sum(x) for x in zip(self.V_routing_cong, self.H_routing_cong)]
occupied_cells = sorted([gc for gc in temp_cong if gc != 0.0], reverse=True) # occupied_cells = sorted([gc for gc in temp_cong if gc != 0.0], reverse=True)
cong_cost = 0.0 # cong_cost = 0.0
# take top 5% # # take top 10%
cong_cnt = math.floor(len(temp_cong) * 0.05) # cong_cnt = math.floor(len(temp_cong) * 0.1)
if cong_cnt == 0: cong_cnt = 1
# if grid cell smaller than 5, take the average over occupied cells # # if grid cell smaller than 10, take the average over occupied cells
if len(temp_cong) < 5: # if len(temp_cong) < 10:
cong_cost = float(sum(occupied_cells) / len(occupied_cells)) # cong_cost = float(sum(occupied_cells) / len(occupied_cells))
return cong_cost # return cong_cost
idx = 0 # idx = 0
sum_cong = 0 # sum_cong = 0
# take top 10% # # take top 10%
while idx < cong_cnt and idx < len(occupied_cells): # while idx < cong_cnt and idx < len(occupied_cells):
sum_cong += occupied_cells[idx] # sum_cong += occupied_cells[idx]
idx += 1 # idx += 1
return float(sum_cong / cong_cnt) # return float(sum_cong / cong_cnt)
def __get_grid_cell_location(self, x_pos, y_pos): def __get_grid_cell_location(self, x_pos, y_pos):
""" """
...@@ -803,140 +810,111 @@ class PlacementCost(object): ...@@ -803,140 +810,111 @@ class PlacementCost(object):
for col_idx in range(col_min, col_max, 1): for col_idx in range(col_min, col_max, 1):
col = col_idx col = col_idx
row = source_gcell[0] row = source_gcell[0]
# ignore OOB
if row * self.grid_col + col > len(self.H_routing_cong):
continue
self.H_routing_cong[row * self.grid_col + col] += weight self.H_routing_cong[row * self.grid_col + col] += weight
# V routing # V routing
for row_idx in range(row_min, row_max, 1): for row_idx in range(row_min, row_max, 1):
row = row_idx row = row_idx
col = sink_gcell[1] col = sink_gcell[1]
# ignore OOB
if row * self.grid_col + col > len(self.V_routing_cong):
continue
self.V_routing_cong[row * self.grid_col + col] += weight self.V_routing_cong[row * self.grid_col + col] += weight
def __three_pin_net_routing(self, node_gcells, weight): def l_routing(self, node_gcells, weight):
temp_gcell = sorted(node_gcells) node_gcells.sort(key = lambda x: (x[1], x[0]))
y1, x1 = node_gcells[0]
# y, x y2, x2 = node_gcells[1]
temp_gcell_first_row, temp_gcell_first_col = temp_gcell[0] y3, x3 = node_gcells[2]
temp_gcell_second_row, temp_gcell_second_col = temp_gcell[1] # H routing (x1, y1) to (x2, y1)
temp_gcell_third_row, temp_gcell_third_col = temp_gcell[2] for col in range(x1, x2):
row = y1
if ((temp_gcell_first_row >= temp_gcell_second_row) and (temp_gcell_second_row >= temp_gcell_third_row)) \ self.H_routing_cong[row * self.grid_col + col] += weight
or ((temp_gcell_first_row <= temp_gcell_second_row) and (temp_gcell_second_row <= temp_gcell_third_row)):
# H routing (x1,y1) to (x2-1, y1) # H routing (x2, y2) to (x2, y3)
for col_idx in range(temp_gcell_first_col, temp_gcell_second_col, 1): for col in range(x2,x3):
col = col_idx row = y2
row = temp_gcell_first_row self.H_routing_cong[row * self.grid_col + col] += weight
# ignore OOB
if row * self.grid_col + col > len(self.H_routing_cong): # V routing (x2, min(y1, y2)) to (x2, max(y1, y2))
continue for row in range(min(y1, y2), max(y1, y2)):
self.H_routing_cong[row * self.grid_col + col] += weight col = x2
self.V_routing_cong[row * self.grid_col + col] += weight
# H routing (x2, y2) to (x3-1, y2)
for col_idx in range(temp_gcell_second_col, temp_gcell_third_col, 1): # V routing (x3, min(y2, y3)) to (x3, max(y2, y3))
col = col_idx for row in range(min(y2, y3), max(y2, y3)):
row = temp_gcell_second_row col = x3
# ignore OOB self.V_routing_cong[row * self.grid_col + col] += weight
if row * self.grid_col + col > len(self.H_routing_cong): return
continue
self.H_routing_cong[row * self.grid_col + col] += weight def t_routing(self, node_gcells, weight):
node_gcells.sort()
# V routing (x2,min(y1,y2)) to (x2, max(y1,y2)-1) #print(node_gcells)
for row_idx in range(min(temp_gcell_first_row, temp_gcell_second_row), max(temp_gcell_first_row, temp_gcell_second_row), 1): y1, x1 = node_gcells[0]
row = row_idx y2, x2 = node_gcells[1]
col = temp_gcell_second_col y3, x3 = node_gcells[2]
# ignore OOB xmin = min(x1, x2, x3)
if row * self.grid_col + col > len(self.V_routing_cong): xmax = max(x1, x2, x3)
continue
self.V_routing_cong[row * self.grid_col + col] += weight # H routing (xmin, y2) to (xmax, y2)
for col in range(xmin, xmax):
# V routing (x3,min(y2,y3)) to (x3, max(y2,y3)-1) row = y2
for row_idx in range(min(temp_gcell_second_row, temp_gcell_third_row), max(temp_gcell_second_row, temp_gcell_third_row), 1): self.H_routing_cong[row * self.grid_col + col] += weight
row = row_idx
col = temp_gcell_third_col # V routing (x1, y1) to (x1, y2)
# ignore OOB for row in range(min(y1, y2), max(y1, y2)):
if row * self.grid_col + col > len(self.V_routing_cong): col = x1
continue self.V_routing_cong[row * self.grid_col + col] += weight
self.V_routing_cong[row * self.grid_col + col] += weight
# V routing (x3, y3) to (x3, y2)
for row in range(min(y2, y3), max(y2, y3)):
col = x3
self.V_routing_cong[row * self.grid_col + col] += weight
pass
elif temp_gcell_first_row == temp_gcell_third_row: def __three_pin_net_routing(self, node_gcells, weight):
# H routing from (x1, y1) to (x3-1, y1) temp_gcell = list(node_gcells)
for col_idx in range(temp_gcell_first_col, temp_gcell_third_col, 1): ## Sorted based on X
temp_gcell.sort(key = lambda x: (x[1], x[0]))
y1, x1 = temp_gcell[0]
y2, x2 = temp_gcell[1]
y3, x3 = temp_gcell[2]
if x1 < x2 and x2 < x3 and min(y1, y3) < y2 and max(y1, y3) > y2:
# print('sk1')
self.l_routing(temp_gcell, weight)
return
if x2 == x3 and x1 < x2 and y1 < min(y2, y3):
# print('sk2')
for col_idx in range(x1,x2,1):
row = y1
col = col_idx col = col_idx
row = temp_gcell_first_row
# ignore OOB
if row * self.grid_col + col > len(self.H_routing_cong):
continue
self.H_routing_cong[row * self.grid_col + col] += weight self.H_routing_cong[row * self.grid_col + col] += weight
# V routing from (x2, min(y1,y2)) to (x2, max(y1,y2)-1) for row_idx in range(y1, max(y2,y3)):
for row_idx in range(min(temp_gcell_first_row, temp_gcell_second_row), max(temp_gcell_first_row, temp_gcell_second_row), 1): col = x2
row = row_idx row = row_idx
col = temp_gcell_second_col
# ignore OOB
if row * self.grid_col + col > len(self.V_routing_cong):
continue
self.V_routing_cong[row * self.grid_col + col] += weight self.V_routing_cong[row * self.grid_col + col] += weight
return
elif temp_gcell_first_row > temp_gcell_third_row and temp_gcell_third_row > temp_gcell_second_row: if y2 == y3:
# H routing from (x1, y3) to (x3-1, y3) # print('sk3')
for col_idx in range(temp_gcell_first_col, temp_gcell_third_col, 1): for col in range(x1, x2):
col = col_idx row = y1
row = temp_gcell_third_row
# ignore OOB
if row * self.grid_col + col > len(self.H_routing_cong):
continue
self.H_routing_cong[row * self.grid_col + col] += weight self.H_routing_cong[row * self.grid_col + col] += weight
# V routing from (x1,y3) to (x1,y1-1) for col in range(x2, x3):
for row_idx in range(temp_gcell_third_row, temp_gcell_first_row, 1): row = y2
row = row_idx
col = temp_gcell_first_col
# ignore OOB
if row * self.grid_col + col > len(self.V_routing_cong):
continue
self.V_routing_cong[row * self.grid_col + col] += weight
# V routing from (x2, min(y2,y3)) to (x2, max(y2,y3)-1)
for row_idx in range(min(temp_gcell_second_row, temp_gcell_third_row), max(temp_gcell_second_row, temp_gcell_third_row), 1):
row = row_idx
col = temp_gcell_second_col
# ignore OOB
if row * self.grid_col + col > len(self.V_routing_cong):
continue
self.V_routing_cong[row * self.grid_col + col] += weight
elif temp_gcell_third_row > temp_gcell_first_row and temp_gcell_first_row > temp_gcell_second_row:
# H routing from (x1, y3) to (x3-1, y3)
for col_idx in range(temp_gcell_first_row, temp_gcell_third_col, 1):
col = col_idx
row = temp_gcell_third_row
# ignore OOB
if row * self.grid_col + col > len(self.H_routing_cong):
continue
self.H_routing_cong[row * self.grid_col + col] += weight self.H_routing_cong[row * self.grid_col + col] += weight
# V routing from (x1,y3) to (x1,y1-1) for row in range(min(y2, y1), max(y2, y1)):
for row_idx in range(temp_gcell_third_col, temp_gcell_first_col, 1): col = x2
row = row_idx
col = temp_gcell_first_col
# ignore OOB
if row * self.grid_col + col > len(self.V_routing_cong):
continue
self.V_routing_cong[row * self.grid_col + col] += weight self.V_routing_cong[row * self.grid_col + col] += weight
return
# print('sk4')
self.t_routing(temp_gcell, weight)
return
# V routing from (x2, min(y2,y3)) to (x2, max(y2,y3)-1)
for row_idx in range(min(temp_gcell_second_row, temp_gcell_third_row), max(temp_gcell_second_row, temp_gcell_third_row), 1):
row = row_idx
col = temp_gcell_second_col
# ignore OOB
if row * self.grid_col + col > len(self.V_routing_cong):
continue
self.V_routing_cong[row * self.grid_col + col] += weight
def __macro_route_over_grid_cell(self, mod_x, mod_y, mod_w, mod_h): def __macro_route_over_grid_cell(self, mod_x, mod_y, mod_w, mod_h):
""" """
...@@ -1020,6 +998,7 @@ class PlacementCost(object): ...@@ -1020,6 +998,7 @@ class PlacementCost(object):
self.H_routing_cong = [0] * self.grid_row * self.grid_col self.H_routing_cong = [0] * self.grid_row * self.grid_col
self.V_routing_cong = [0] * self.grid_row * self.grid_col self.V_routing_cong = [0] * self.grid_row * self.grid_col
net_count = 0
for mod in self.modules_w_pins: for mod in self.modules_w_pins:
norm_fact = 1.0 norm_fact = 1.0
curr_type = mod.get_type() curr_type = mod.get_type()
...@@ -1048,7 +1027,7 @@ class PlacementCost(object): ...@@ -1048,7 +1027,7 @@ class PlacementCost(object):
node_gcells.add(self.__get_grid_cell_location(*(mod.get_pos()))) node_gcells.add(self.__get_grid_cell_location(*(mod.get_pos())))
source_gcell = self.__get_grid_cell_location(*(mod.get_pos())) source_gcell = self.__get_grid_cell_location(*(mod.get_pos()))
if mod.get_weight() != 1: if mod.get_weight() > 1:
weight = mod.get_weight() weight = mod.get_weight()
for input_list in mod.get_sink().values(): for input_list in mod.get_sink().values():
...@@ -1831,4 +1810,4 @@ def main(): ...@@ -1831,4 +1810,4 @@ def main():
print("# STDCELLs : 0") print("# STDCELLs : 0")
if __name__ == '__main__': if __name__ == '__main__':
main() main()
\ No newline at end of file
...@@ -45,10 +45,10 @@ class CircuitDataBaseTest(): ...@@ -45,10 +45,10 @@ class CircuitDataBaseTest():
# GRID_ROW = 4 # GRID_ROW = 4
# PMm # PMm
CANVAS_WIDTH = 100 # CANVAS_WIDTH = 100
CANVAS_HEIGHT = 100 # CANVAS_HEIGHT = 100
GRID_COL = 3 # GRID_COL = 20
GRID_ROW = 3 # GRID_ROW = 20
def __init__(self, NETLIST_PATH) -> None: def __init__(self, NETLIST_PATH) -> None:
self.NETLIST_PATH = NETLIST_PATH self.NETLIST_PATH = NETLIST_PATH
...@@ -65,8 +65,8 @@ class CircuitDataBaseTest(): ...@@ -65,8 +65,8 @@ class CircuitDataBaseTest():
self.plc.set_macro_routing_allocation(10, 10) self.plc.set_macro_routing_allocation(10, 10)
self.plc_os.set_macro_routing_allocation(10, 10) self.plc_os.set_macro_routing_allocation(10, 10)
self.plc.set_congestion_smooth_range(2.0) self.plc.set_congestion_smooth_range(0.0)
self.plc_os.set_congestion_smooth_range(2.0) self.plc_os.set_congestion_smooth_range(0.0)
self.plc.set_canvas_size(self.CANVAS_WIDTH, self.CANVAS_HEIGHT) self.plc.set_canvas_size(self.CANVAS_WIDTH, self.CANVAS_HEIGHT)
self.plc.set_placement_grid(self.GRID_COL, self.GRID_ROW) self.plc.set_placement_grid(self.GRID_COL, self.GRID_ROW)
...@@ -75,7 +75,7 @@ class CircuitDataBaseTest(): ...@@ -75,7 +75,7 @@ class CircuitDataBaseTest():
print("Name: ", self.plc.get_source_filename().rsplit("/", 1)[1]) print("Name: ", self.plc.get_source_filename().rsplit("/", 1)[1])
self.plc_os.display_canvas() # self.plc_os.display_canvas()
# start = time.time() # start = time.time()
temp_gl_h = self.plc.get_horizontal_routing_congestion() temp_gl_h = self.plc.get_horizontal_routing_congestion()
......
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