Commit 0173d080 by Dinple

Bug fixing

parent 8988a64b
...@@ -31,10 +31,6 @@ class PlacementCost(object): ...@@ -31,10 +31,6 @@ class PlacementCost(object):
self.init_plc = None self.init_plc = None
self.project_name = "circuit_training" self.project_name = "circuit_training"
self.block_name = netlist_file.rsplit('/', -1)[-2] self.block_name = netlist_file.rsplit('/', -1)[-2]
self.width = 0.0
self.height = 0.0
self.grid_col = 10
self.grid_row = 10
self.hroutes_per_micron = 0.0 self.hroutes_per_micron = 0.0
self.vroutes_per_micron = 0.0 self.vroutes_per_micron = 0.0
self.smooth_range = 0.0 self.smooth_range = 0.0
...@@ -62,6 +58,13 @@ class PlacementCost(object): ...@@ -62,6 +58,13 @@ class PlacementCost(object):
self.soft_macros_to_inpins = {} self.soft_macros_to_inpins = {}
# read netlist # read netlist
self.__read_protobuf() self.__read_protobuf()
# default canvas width/height based on cell area
self.width = math.sqrt(self.get_area()/0.6)
self.height = math.sqrt(self.get_area()/0.6)
# default gridding
self.grid_col = 10
self.grid_row = 10
# store module/component count # store module/component count
self.port_cnt = len(self.port_indices) self.port_cnt = len(self.port_indices)
self.hard_macro_cnt = len(self.hard_macro_indices) self.hard_macro_cnt = len(self.hard_macro_indices)
...@@ -361,16 +364,6 @@ class PlacementCost(object): ...@@ -361,16 +364,6 @@ class PlacementCost(object):
""" """
Compute wirelength cost from wirelength Compute wirelength cost from wirelength
""" """
# temp_net_cnt = math.floor(self.net_cnt * 0.15)
# if temp_net_cnt == 0:
# temp_net_cnt = 1
# unknown_threshold = 100
# if self.net_cnt <= unknown_threshold:
# return self.get_wirelength() / ((self.get_canvas_width_height()[0] + self.get_canvas_width_height()[1]) * temp_net_cnt)
# else:
return self.get_wirelength() / ((self.get_canvas_width_height()[0] + self.get_canvas_width_height()[1]) * self.net_cnt) return self.get_wirelength() / ((self.get_canvas_width_height()[0] + self.get_canvas_width_height()[1]) * self.net_cnt)
def get_area(self) -> float: def get_area(self) -> float:
...@@ -707,14 +700,14 @@ class PlacementCost(object): ...@@ -707,14 +700,14 @@ class PlacementCost(object):
macro_adj = [0] * (self.hard_macro_cnt + self.soft_macro_cnt) * (self.hard_macro_cnt + self.soft_macro_cnt) macro_adj = [0] * (self.hard_macro_cnt + self.soft_macro_cnt) * (self.hard_macro_cnt + self.soft_macro_cnt)
assert len(macro_adj) == (self.hard_macro_cnt + self.soft_macro_cnt) * (self.hard_macro_cnt + self.soft_macro_cnt) assert len(macro_adj) == (self.hard_macro_cnt + self.soft_macro_cnt) * (self.hard_macro_cnt + self.soft_macro_cnt)
for row_idx, module_idx in enumerate(module_indices): for row_idx, module_idx in enumerate(sorted(module_indices)):
# row index # row index
# store temp module # store temp module
curr_module = self.modules_w_pins[module_idx] curr_module = self.modules_w_pins[module_idx]
# get module name # get module name
curr_module_name = curr_module.get_name() curr_module_name = curr_module.get_name()
for col_idx, h_module_idx in enumerate(module_indices): for col_idx, h_module_idx in enumerate(sorted(module_indices)):
# col index # col index
entry = 0 entry = 0
# store connected module # store connected module
...@@ -767,6 +760,7 @@ class PlacementCost(object): ...@@ -767,6 +760,7 @@ class PlacementCost(object):
def get_macro_and_clustered_port_adjacency(self): def get_macro_and_clustered_port_adjacency(self):
""" """
Compute Adjacency Matrix (Unclustered PORTs) Compute Adjacency Matrix (Unclustered PORTs)
if module is a PORT, assign nearest cell location even if OOB
""" """
#[MACRO][macro] #[MACRO][macro]
module_indices = self.hard_macro_indices + self.soft_macro_indices module_indices = self.hard_macro_indices + self.soft_macro_indices
...@@ -779,6 +773,19 @@ class PlacementCost(object): ...@@ -779,6 +773,19 @@ class PlacementCost(object):
row, col = self.__get_grid_cell_location(x_pos=x_pos, y_pos=y_pos) row, col = self.__get_grid_cell_location(x_pos=x_pos, y_pos=y_pos)
# prevent OOB
if row >= self.grid_row:
row = self.grid_row - 1
if row < 0:
row = 0
if col >= self.grid_col:
col = self.grid_col - 1
if col < 0:
col = 0
if (row, col) in clustered_ports: if (row, col) in clustered_ports:
clustered_ports[(row, col)].append(port) clustered_ports[(row, col)].append(port)
else: else:
...@@ -789,13 +796,13 @@ class PlacementCost(object): ...@@ -789,13 +796,13 @@ class PlacementCost(object):
cell_location = [0] * len(clustered_ports) cell_location = [0] * len(clustered_ports)
# instantiate macros # instantiate macros
for row_idx, module_idx in enumerate(module_indices): for row_idx, module_idx in enumerate(sorted(module_indices)):
# store temp module # store temp module
curr_module = self.modules_w_pins[module_idx] curr_module = self.modules_w_pins[module_idx]
# get module name # get module name
curr_module_name = curr_module.get_name() curr_module_name = curr_module.get_name()
for col_idx, h_module_idx in enumerate(module_indices): for col_idx, h_module_idx in enumerate(sorted(module_indices)):
# col index # col index
entry = 0 entry = 0
# store connected module # store connected module
...@@ -813,9 +820,11 @@ class PlacementCost(object): ...@@ -813,9 +820,11 @@ class PlacementCost(object):
macro_adj[col_idx * (len(module_indices) + len(clustered_ports)) + row_idx] = entry macro_adj[col_idx * (len(module_indices) + len(clustered_ports)) + row_idx] = entry
# instantiate clustered ports # instantiate clustered ports
for row_idx, cluster_cell in enumerate(clustered_ports): for row_idx, cluster_cell in enumerate(sorted(clustered_ports, key=lambda tup: tup[1])):
# print("cluster_cell", cluster_cell)
# print("port cnt", len(clustered_ports[cluster_cell]))
# add cell location # add cell location
cell_location[row_idx] = cluster_cell[0] * self.grid_row + cluster_cell[1] cell_location[row_idx] = cluster_cell[0] * self.grid_col + cluster_cell[1]
# relocate to after macros # relocate to after macros
row_idx += len(module_indices) row_idx += len(module_indices)
...@@ -824,8 +833,7 @@ class PlacementCost(object): ...@@ -824,8 +833,7 @@ class PlacementCost(object):
for curr_port in clustered_ports[cluster_cell]: for curr_port in clustered_ports[cluster_cell]:
# get module name # get module name
curr_port_name = curr_port.get_name() curr_port_name = curr_port.get_name()
# print("curr_port_name", curr_port_name) # print("curr_port_name", curr_port_name, curr_port.get_pos())
# print("connections", curr_port.get_connection())
# assuming ports only connects to macros # assuming ports only connects to macros
for col_idx, h_module_idx in enumerate(module_indices): for col_idx, h_module_idx in enumerate(module_indices):
# col index # col index
...@@ -890,8 +898,8 @@ class PlacementCost(object): ...@@ -890,8 +898,8 @@ class PlacementCost(object):
ax.set_aspect('equal', adjustable='box') ax.set_aspect('equal', adjustable='box')
# Construct grid # Construct grid
x, y = np.meshgrid(np.linspace(0, self.height, self.grid_row + 1),\ x, y = np.meshgrid(np.linspace(0, self.width, self.grid_col + 1),\
np.linspace(0, self.width, self.grid_col + 1)) np.linspace(0, self.height, self.grid_row + 1))
ax.plot(x, y, c='b', alpha=0.1) # use plot, not scatter ax.plot(x, y, c='b', alpha=0.1) # use plot, not scatter
ax.plot(np.transpose(x), np.transpose(y), c='b', alpha=0.2) # add this here ax.plot(np.transpose(x), np.transpose(y), c='b', alpha=0.2) # add this here
...@@ -899,7 +907,7 @@ class PlacementCost(object): ...@@ -899,7 +907,7 @@ class PlacementCost(object):
# Construct module blocks # Construct module blocks
for mod in self.modules_w_pins: for mod in self.modules_w_pins:
if mod.get_type() == 'PORT': if mod.get_type() == 'PORT':
plt.plot(*mod.get_pos(),'ro', markersize=2) plt.plot(*mod.get_pos(),'ro', markersize=4)
elif mod.get_type() == 'MACRO': elif mod.get_type() == 'MACRO':
ax.add_patch(Rectangle((mod.get_pos()[0] - mod.get_width()/2, mod.get_pos()[1] - mod.get_height()/2),\ ax.add_patch(Rectangle((mod.get_pos()[0] - mod.get_width()/2, mod.get_pos()[1] - mod.get_height()/2),\
mod.get_width(), mod.get_height(),\ mod.get_width(), mod.get_height(),\
...@@ -928,6 +936,7 @@ class PlacementCost(object): ...@@ -928,6 +936,7 @@ class PlacementCost(object):
self.side = side # "BOTTOM", "TOP", "LEFT", "RIGHT" self.side = side # "BOTTOM", "TOP", "LEFT", "RIGHT"
self.sink = {} # standard cells, macro pins, ports driven by this cell self.sink = {} # standard cells, macro pins, ports driven by this cell
self.connection = {} # [module_name] => edge degree self.connection = {} # [module_name] => edge degree
self.ifFixed = True
def get_name(self): def get_name(self):
return self.name return self.name
...@@ -1003,6 +1012,7 @@ class PlacementCost(object): ...@@ -1003,6 +1012,7 @@ class PlacementCost(object):
self.x = float(x) self.x = float(x)
self.y = float(y) self.y = float(y)
self.connection = {} # [module_name] => edge degree self.connection = {} # [module_name] => edge degree
self.ifFixed = False
def get_name(self): def get_name(self):
return self.name return self.name
...@@ -1124,6 +1134,7 @@ class PlacementCost(object): ...@@ -1124,6 +1134,7 @@ class PlacementCost(object):
self.y = float(y) self.y = float(y)
self.orientation = orientation self.orientation = orientation
self.connection = {} # [module_name] => edge degree self.connection = {} # [module_name] => edge degree
self.ifFixed = False
def get_name(self): def get_name(self):
return self.name return self.name
...@@ -1238,7 +1249,7 @@ class PlacementCost(object): ...@@ -1238,7 +1249,7 @@ class PlacementCost(object):
def main(): def main():
test_netlist_dir = './Plc_client/test/'+\ test_netlist_dir = './Plc_client/test/'+\
'ariane' 'ariane133'
netlist_file = os.path.join(test_netlist_dir, netlist_file = os.path.join(test_netlist_dir,
'netlist.pb.txt') 'netlist.pb.txt')
plc = PlacementCost(netlist_file) plc = PlacementCost(netlist_file)
...@@ -1255,14 +1266,5 @@ def main(): ...@@ -1255,14 +1266,5 @@ def main():
print("# SOFT_MACRO_PINs : %d"%(plc.get_soft_macro_pin_count())) print("# SOFT_MACRO_PINs : %d"%(plc.get_soft_macro_pin_count()))
print("# STDCELLs : 0") print("# STDCELLs : 0")
# print(adj[137])
# print(np.unique(adj))
print(plc.set_canvas_size(356.592, 356.640))
print(plc.set_placement_grid(35, 33))
# print(plc.set_canvas_size(80, 80))
# print(plc.set_placement_grid(5, 5))
print(plc.get_grid_cells_density())
print(plc.get_density_cost())
if __name__ == '__main__': if __name__ == '__main__':
main() main()
...@@ -4,6 +4,8 @@ from Plc_client import plc_client_os as plc_client_os ...@@ -4,6 +4,8 @@ from Plc_client import plc_client_os as plc_client_os
from Plc_client import plc_client as plc_client from Plc_client import plc_client as plc_client
import numpy as np import numpy as np
import sys import sys
import time
import math
np.set_printoptions(threshold=sys.maxsize) np.set_printoptions(threshold=sys.maxsize)
FLAGS = flags.FLAGS FLAGS = flags.FLAGS
...@@ -13,9 +15,9 @@ class CircuitDataBaseTest(): ...@@ -13,9 +15,9 @@ class CircuitDataBaseTest():
# NETLIST_PATH = "./Plc_client/test/ariane_soft2hard/netlist.pb.txt" # NETLIST_PATH = "./Plc_client/test/ariane_soft2hard/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/ariane_port2soft/netlist.pb.txt" # NETLIST_PATH = "./Plc_client/test/ariane_port2soft/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/sample_clustered_nomacro/netlist.pb.txt" # NETLIST_PATH = "./Plc_client/test/sample_clustered_nomacro/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/sample_clustered_macroxy/netlist.pb.txt" NETLIST_PATH = "./Plc_client/test/sample_clustered_macroxy/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/ariane/netlist.pb.txt" # NETLIST_PATH = "./Plc_client/test/ariane/netlist.pb.txt"
NETLIST_PATH = "./Plc_client/test/ariane133/netlist.pb.txt" # NETLIST_PATH = "./Plc_client/test/ariane133/netlist.pb.txt"
# Google's Ariane # Google's Ariane
# CANVAS_WIDTH = 356.592 # CANVAS_WIDTH = 356.592
...@@ -24,21 +26,27 @@ class CircuitDataBaseTest(): ...@@ -24,21 +26,27 @@ class CircuitDataBaseTest():
# GRID_ROW = 33 # GRID_ROW = 33
# Ariane133 # Ariane133
CANVAS_WIDTH = 1599.99 # CANVAS_WIDTH = 1430.723
CANVAS_HEIGHT = 1598.8 # CANVAS_HEIGHT = 1430.723
GRID_COL = 50 # GRID_COL = 24
GRID_ROW = 50 # GRID_ROW = 21
# Sample clustered # Sample clustered
# CANVAS_WIDTH = 500 CANVAS_WIDTH = 500
# CANVAS_HEIGHT = 500 CANVAS_HEIGHT = 500
# GRID_COL = 4 GRID_COL = 4
# GRID_ROW = 4 GRID_ROW = 4
def test_proxy_cost(self): def test_proxy_cost(self):
# Google's Binary Executable # Google's Binary Executable
self.plc = plc_client.PlacementCost(self.NETLIST_PATH) self.plc = plc_client.PlacementCost(self.NETLIST_PATH)
print(self.plc.get_canvas_width_height())
print("start timing")
start = time.time()
print(self.plc.get_congestion_cost())
end = time.time()
print("time elapsed:", end - start)
print("end timing")
# Open-sourced Implementation # Open-sourced Implementation
self.plc_os = plc_client_os.PlacementCost(netlist_file=self.NETLIST_PATH, self.plc_os = plc_client_os.PlacementCost(netlist_file=self.NETLIST_PATH,
macro_macro_x_spacing = 50, macro_macro_x_spacing = 50,
...@@ -48,6 +56,7 @@ class CircuitDataBaseTest(): ...@@ -48,6 +56,7 @@ class CircuitDataBaseTest():
self.plc.set_placement_grid(self.GRID_COL, self.GRID_ROW) self.plc.set_placement_grid(self.GRID_COL, self.GRID_ROW)
self.plc_os.set_canvas_size(self.CANVAS_WIDTH, self.CANVAS_HEIGHT) self.plc_os.set_canvas_size(self.CANVAS_WIDTH, self.CANVAS_HEIGHT)
self.plc_os.set_placement_grid(self.GRID_COL, self.GRID_ROW) self.plc_os.set_placement_grid(self.GRID_COL, self.GRID_ROW)
# print(self.plc_os.display_canvas()) # print(self.plc_os.display_canvas())
print(self.plc_os.get_wirelength(), self.plc.get_wirelength()) print(self.plc_os.get_wirelength(), self.plc.get_wirelength())
...@@ -93,23 +102,30 @@ class CircuitDataBaseTest(): ...@@ -93,23 +102,30 @@ class CircuitDataBaseTest():
self.plc_os.set_macro_routing_allocation(3.0, 4.0) self.plc_os.set_macro_routing_allocation(3.0, 4.0)
assert self.plc.get_macro_routing_allocation() == self.plc_os.get_macro_routing_allocation() assert self.plc.get_macro_routing_allocation() == self.plc_os.get_macro_routing_allocation()
# test get_macro_adjacency
plc_macroadj = self.plc.get_macro_adjacency() plc_macroadj = self.plc.get_macro_adjacency()
plc_macroadj = np.array(plc_macroadj).reshape(int(math.sqrt(len(plc_macroadj))),\
int(math.sqrt(len(plc_macroadj))))
plcos_macroadj = self.plc_os.get_macro_adjacency() plcos_macroadj = self.plc_os.get_macro_adjacency()
# print("diff macro", np.nonzero(np.array(plc_macroadj) - np.array(plcos_macroadj))) plcos_macroadj = np.array(plcos_macroadj).reshape(int(math.sqrt(len(plcos_macroadj))),\
int(math.sqrt(len(plcos_macroadj))))
# print(self.plc_os.get_macro_and_clustered_port_adjacency()) assert(np.sum(np.nonzero(plc_macroadj - plcos_macroadj)) == 0)
# print(self.plc.get_macro_and_clustered_port_adjacency()[0])
# print("gl number of clustered ports found:", self.plc.get_macro_and_clustered_port_adjacency()[0]) # test get_macro_and_clustered_port_adjacency
# print("our number of clustered ports found:", self.plc_os.get_macro_and_clustered_port_adjacency()[0]) plc_clusteradj, plc_cell = self.plc.get_macro_and_clustered_port_adjacency()
# print(self.plc_os.display_canvas()) plc_clusteradj = np.array(plc_clusteradj).reshape(int(math.sqrt(len(plc_clusteradj))),\
int(math.sqrt(len(plc_clusteradj))))
# print("count", self.plc_os.soft_macro_cnt, self.plc_os.hard_macro_cnt, self.plc_os.port_cnt) plcos_clusteradj, plcos_cell = self.plc_os.get_macro_and_clustered_port_adjacency()
plcos_clusteradj = np.array(plcos_clusteradj).reshape(int(math.sqrt(len(plcos_clusteradj))),\
int(math.sqrt(len(plcos_clusteradj))))
assert(plc_cell == plcos_cell)
# compare both macro and clustered ports array for plc_adj, plcos_adj in zip(plc_clusteradj, plcos_clusteradj):
for plc_adj, plcos_adj in zip(self.plc.get_macro_and_clustered_port_adjacency(), self.plc_os.get_macro_and_clustered_port_adjacency()): assert(np.sum(np.nonzero(plc_adj - plcos_adj)) == 0)
# print("diff macro cluster", np.nonzero(np.array(plc_adj) - np.array(plcos_adj)))
assert sum(plc_adj) == sum(plcos_adj)
def test_miscellaneous(self): def test_miscellaneous(self):
# Google's Binary Executable # Google's Binary Executable
......
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