Commit 8d03aea7 by Dinple

code clean up and added readme

parent 05aa7fe6
...@@ -27,8 +27,21 @@ $$ ...@@ -27,8 +27,21 @@ $$
HPWL(netlist) = \sum_{i}^{N_{netlist}} W_{i\_{source}} \cdot [max_{b\in i}(x_b) - min_{b\in i}(x_b) + max_{b\in i}(y_b) - min_{b\in i}(y_b)] HPWL(netlist) = \sum_{i}^{N_{netlist}} W_{i\_{source}} \cdot [max_{b\in i}(x_b) - min_{b\in i}(x_b) + max_{b\in i}(y_b) - min_{b\in i}(y_b)]
$$ $$
## Density Computation
Density cost is computed from grid cells density.
By default, any given input will have grid col/row set to 10/10 until user later defines in the .plc file.
Grid cell density is represented as an 1D array where the length is set to be $grid_col * grid_row$. Each entry of this array represents the current occupied precentage within this cell.
Overlaps gets double counted, so it is possible for a cell density to exceed 1.0.
When a Placement Cost object is initialized, coordinate information and dimension information will be read from the netlist input and used to compute an initial grid cell density.
Once grid cell density is obtained, we take the top 10% of the largest grid cells and compute its average. The density cost will be half of the average value.
## Adjacency Matrix Computation ## Adjacency Matrix Computation
The adjacency matrix is represented as an array of $[N_{hardmacros} + N_{softmacros} + N_{ports}] \times [N_{hardmacros} + N_{softmacros} + N_{ports}]$ elements. The adjacency matrix is represented as an array of $[N_{hardmacros} + N_{softmacros} + N_{ports}] \times [N_{hardmacros} + N_{softmacros} + N_{ports}]$ elements.
For each entry of the adjacency matrix, it represents the total number of connections between module $i$ and module $j$ subject to all corresponding pins. For each entry of the adjacency matrix, it represents the total number of connections between module $i$ and module $j$ subject to all corresponding pins. For soft macro pins, weight should be consider a factor to the number of connections.
...@@ -434,13 +434,17 @@ class PlacementCost(object): ...@@ -434,13 +434,17 @@ class PlacementCost(object):
return 0.0 return 0.0
def __get_grid_cell_location(self, x_pos, y_pos): def __get_grid_cell_location(self, x_pos, y_pos):
# private function for getting grid cell row/col ranging from 0...N """
private function for getting grid cell row/col ranging from 0...N
"""
row = math.floor(y_pos / self.grid_height) row = math.floor(y_pos / self.grid_height)
col = math.floor(x_pos / self.grid_width) col = math.floor(x_pos / self.grid_width)
return row, col return row, col
def __overlap_area(self, block_i, block_j): def __overlap_area(self, block_i, block_j):
# private function for computing block overlapping """
private function for computing block overlapping
"""
x_diff = min(block_i.x_max, block_j.x_max) - max(block_i.x_min, block_j.x_min) x_diff = min(block_i.x_max, block_j.x_max) - max(block_i.x_min, block_j.x_min)
y_diff = min(block_i.y_max, block_j.y_max) - max(block_i.y_min, block_j.y_min) y_diff = min(block_i.y_max, block_j.y_max) - max(block_i.y_min, block_j.y_min)
if x_diff >= 0 and y_diff >= 0: if x_diff >= 0 and y_diff >= 0:
...@@ -448,14 +452,11 @@ class PlacementCost(object): ...@@ -448,14 +452,11 @@ class PlacementCost(object):
return 0 return 0
def __add_module_to_grid_cells(self, mod_x, mod_y, mod_w, mod_h): def __add_module_to_grid_cells(self, mod_x, mod_y, mod_w, mod_h):
# private function for add module to grid cells """
# row/col ranging from 0...N private function for add module to grid cells
row, col = self.__get_grid_cell_location(mod_x, mod_y) """
# Two corners
# Four corners
ur = (mod_x + (mod_w/2), mod_y + (mod_h/2)) ur = (mod_x + (mod_w/2), mod_y + (mod_h/2))
br = (mod_x + (mod_w/2), mod_y - (mod_h/2))
ul = (mod_x - (mod_w/2), mod_y + (mod_h/2))
bl = (mod_x - (mod_w/2), mod_y - (mod_h/2)) bl = (mod_x - (mod_w/2), mod_y - (mod_h/2))
# construct block based on current module # construct block based on current module
...@@ -466,10 +467,8 @@ class PlacementCost(object): ...@@ -466,10 +467,8 @@ class PlacementCost(object):
y_min=mod_y - (mod_h/2) y_min=mod_y - (mod_h/2)
) )
# Four corner grid cells # Only need two corners of a grid cell
ur_row, ur_col = self.__get_grid_cell_location(*ur) ur_row, ur_col = self.__get_grid_cell_location(*ur)
br_row, br_col = self.__get_grid_cell_location(*br)
ul_row, ul_col = self.__get_grid_cell_location(*ul)
bl_row, bl_col = self.__get_grid_cell_location(*bl) bl_row, bl_col = self.__get_grid_cell_location(*bl)
# check if out of bound # check if out of bound
...@@ -506,10 +505,10 @@ class PlacementCost(object): ...@@ -506,10 +505,10 @@ class PlacementCost(object):
self.grid_occupied[self.grid_col * r_i + c_i] += \ self.grid_occupied[self.grid_col * r_i + c_i] += \
self.__overlap_area(grid_cell_block, module_block) self.__overlap_area(grid_cell_block, module_block)
# if abs(self.grid_occupied[self.grid_row * r_i + c_i] - 1) < 1e-6:
# self.grid_occupied[self.grid_row * r_i + c_i] = 1
def get_grid_cells_density(self): def get_grid_cells_density(self):
"""
compute density for all grid cells
"""
# by default grid row/col is 10/10 # by default grid row/col is 10/10
self.grid_width = float(self.width/self.grid_col) self.grid_width = float(self.width/self.grid_col)
self.grid_height = float(self.height/self.grid_row) self.grid_height = float(self.height/self.grid_row)
...@@ -538,6 +537,9 @@ class PlacementCost(object): ...@@ -538,6 +537,9 @@ class PlacementCost(object):
return self.grid_cells return self.grid_cells
def get_density_cost(self) -> float: def get_density_cost(self) -> float:
"""
compute average of top 10% of grid cell density and take half of it
"""
occupied_cells = sorted([gc for gc in self.grid_cells if gc != 0.0], reverse=True) occupied_cells = sorted([gc for gc in self.grid_cells if gc != 0.0], reverse=True)
density_cost = 0.0 density_cost = 0.0
......
...@@ -12,8 +12,8 @@ class CircuitDataBaseTest(): ...@@ -12,8 +12,8 @@ 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"
def test_proxy_cost(self): def test_proxy_cost(self):
...@@ -37,10 +37,10 @@ class CircuitDataBaseTest(): ...@@ -37,10 +37,10 @@ class CircuitDataBaseTest():
# GRID_ROW = 50 # GRID_ROW = 50
# Sample clustered # Sample clustered
CANVAS_WIDTH = 80 # CANVAS_WIDTH = 80
CANVAS_HEIGHT = 80 # CANVAS_HEIGHT = 80
GRID_COL = 5 # GRID_COL = 5
GRID_ROW = 5 # GRID_ROW = 5
self.plc.set_canvas_size(CANVAS_WIDTH, CANVAS_HEIGHT) self.plc.set_canvas_size(CANVAS_WIDTH, CANVAS_HEIGHT)
self.plc.set_placement_grid(GRID_COL, GRID_ROW) self.plc.set_placement_grid(GRID_COL, GRID_ROW)
......
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