Commit 05aa7fe6 by Dinple

adj matrix bug fixes

parent 9256f51a
......@@ -11,8 +11,6 @@ import numpy as np
Block = namedtuple('Block', 'x_max y_max x_min y_min')
# FLAGS = flags.FLAG
class PlacementCost(object):
def __init__(self,
......@@ -338,9 +336,14 @@ class PlacementCost(object):
for pin_name in pin_names:
pin = self.modules_w_pins[self.mod_name_to_indices[pin_name]]
inputs = pin.get_sink()
if inputs:
for k in inputs.keys():
if macro_type == "MACRO":
macro.add_connections(inputs[k])
elif macro_type == "macro":
weight = pin.get_weight()
macro.add_connections(inputs[k], weight)
def get_cost(self) -> float:
......@@ -462,8 +465,6 @@ class PlacementCost(object):
x_min=mod_x - (mod_w/2),
y_min=mod_y - (mod_h/2)
)
print("Module Four corners")
print("Upper Left",ur, "\nBottom Right", br, "\nUpper Left", ul, "\nBottom Left",bl)
# Four corner grid cells
ur_row, ur_col = self.__get_grid_cell_location(*ur)
......@@ -480,7 +481,6 @@ class PlacementCost(object):
bl_col = 0
else:
# OOB, skip module
print("OOB skipped")
return
if bl_row >= 0 and bl_col >= 0:
......@@ -491,15 +491,10 @@ class PlacementCost(object):
ur_col = self.grid_col - 1
else:
# OOB, skip module
print("OOB skipped")
return
print("Four Corner Grid")
print("UR row",ur_row, "\nUR col", ur_col, "\nBL row", bl_row, "\nBL col",bl_col)
for r_i in range(bl_row, ur_row + 1):
for c_i in range(bl_col, ur_col + 1):
print(r_i, c_i)
# construct block based on current cell row/col
grid_cell_block = Block(
x_max= (c_i + 1) * self.grid_width,
......@@ -514,9 +509,6 @@ class PlacementCost(object):
# 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
print("module_block", module_block)
def get_grid_cells_density(self):
# by default grid row/col is 10/10
self.grid_width = float(self.width/self.grid_col)
......@@ -685,11 +677,10 @@ class PlacementCost(object):
Compute Adjacency Matrix (Unclustered PORTs)
"""
# NOTE: in pb.txt, netlist input count exceed certain threshold will be ommitted
macro_adj = [0] * self.module_cnt * self.module_cnt
assert len(macro_adj) == self.module_cnt * self.module_cnt
#[MACRO][macro][PORT]
module_indices = self.hard_macro_indices + self.soft_macro_indices + self.port_indices
#[MACRO][macro]
module_indices = self.hard_macro_indices + self.soft_macro_indices
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)
for row_idx, module_idx in enumerate(module_indices):
# row index
......@@ -712,7 +703,8 @@ class PlacementCost(object):
if h_module_name in curr_module.get_connection():
entry += curr_module.get_connection()[h_module_name]
macro_adj[row_idx * self.module_cnt + col_idx] = entry
macro_adj[row_idx * (self.hard_macro_cnt + self.soft_macro_cnt) + col_idx] = entry
macro_adj[col_idx * (self.hard_macro_cnt + self.soft_macro_cnt) + row_idx] = entry
return macro_adj
......@@ -927,13 +919,12 @@ class PlacementCost(object):
self.height = float(height)
self.x = float(x)
self.y = float(y)
self.sink = {} # [MACRO_NAME] => [PIN_NAME]
self.connection = {} # [module_name] => edge degree
def get_name(self):
return self.name
def add_connection(self, module_name):
def add_connection(self, module_name, weight):
# NOTE: assume PORT names does not contain slash
ifPORT = False
module_name_splited = module_name.rsplit('/', 1)
......@@ -942,18 +933,19 @@ class PlacementCost(object):
if ifPORT:
# adding PORT
self.connection[module_name] = 1
self.connection[module_name] = 1 * weight
else:
# adding soft/hard macros
if module_name_splited[0] in self.connection.keys():
self.connection[module_name_splited[0]] += 1
self.connection[module_name_splited[0]] += 1 * weight
else:
self.connection[module_name_splited[0]] = 1
self.connection[module_name_splited[0]] = 1 * weight
def add_connections(self, module_names):
def add_connections(self, module_names, weight):
# NOTE: assume PORT names does not contain slash
# consider weight on soft macro pins
for module_name in module_names:
self.add_connection(module_name)
self.add_connection(module_name, weight)
def set_pos(self, x, y):
self.x = x
......@@ -962,9 +954,6 @@ class PlacementCost(object):
def get_pos(self):
return self.x, self.y
def get_sink(self):
return self.sink
def get_type(self):
return "macro"
......@@ -982,7 +971,7 @@ class PlacementCost(object):
class SoftMacroPin:
def __init__(self, name,
x = 0.0, y = 0.0, macro_name = "", weight = 0.0):
x = 0.0, y = 0.0, macro_name = "", weight = 1.0):
self.name = name
self.x = float(x)
self.y = float(y)
......@@ -1036,6 +1025,9 @@ class PlacementCost(object):
def get_sink(self):
return self.sink
def get_weight(self):
return self.weight
def get_type(self):
return "macro_pin"
......@@ -1188,9 +1180,13 @@ def main():
# print(plc.set_placement_grid(5, 5))
print(plc.get_grid_cells_density())
print(plc.get_density_cost())
print(plc.display_canvas())
print(len(plc.get_macro_and_clustered_port_adjacency()))
temppins = plc.soft_macros_to_inpins[plc.modules_w_pins[plc.soft_macro_indices[0]].get_name()]
print(plc.modules_w_pins[plc.mod_name_to_indices[temppins[17]]].get_name())
print(plc.modules_w_pins[plc.mod_name_to_indices[temppins[17]]].get_sink())
print(plc.modules_w_pins[plc.soft_macro_indices[54]].get_name())
temppins2 = plc.soft_macros_to_inpins[plc.modules_w_pins[plc.soft_macro_indices[54]].get_name()]
if __name__ == '__main__':
main()
import unittest
import os
from absl import flags
from absl import app
from Plc_client import plc_client_os as plc_client_os
from Plc_client import plc_client as plc_client
import numpy as np
import sys
np.set_printoptions(threshold=sys.maxsize)
FLAGS = flags.FLAGS
class CircuitDataBaseTest(unittest.TestCase):
class CircuitDataBaseTest():
# NETLIST_PATH = "./Plc_client/test/ariane_hard2soft/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/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/ariane133/netlist.pb.txt"
def test_proxy_cost(self):
# Google's Binary Executable
self.plc = plc_client_os.PlacementCost(self.NETLIST_PATH)
self.plc = plc_client.PlacementCost(self.NETLIST_PATH)
print(self.plc.get_canvas_width_height())
# Open-sourced Implementation
self.plc_os = plc_client_os.PlacementCost(netlist_file=self.NETLIST_PATH,
macro_macro_x_spacing = 50,
macro_macro_y_spacing = 50)
# Google's Ariane
CANVAS_HEIGHT =
CANVAS_WIDTH =
CANVAS_WIDTH = 356.592
CANVAS_HEIGHT = 356.640
GRID_COL = 35
GRID_ROW = 33
# Ariane133
CANVAS_HEIGHT =
CANVAS_WIDTH =
GRID_COL = 35
GRID_ROW = 33
print(self.plc.set_canvas_size(CANVAS_WIDTH, CANVAS_HEIGHT))
print(self.plc.set_placement_grid(GRID_COL, GRID_ROW))
# CANVAS_WIDTH = 1599.99
# CANVAS_HEIGHT = 1598.8
# GRID_COL = 50
# GRID_ROW = 50
# Sample clustered
CANVAS_WIDTH = 80
CANVAS_HEIGHT = 80
GRID_COL = 5
GRID_ROW = 5
self.plc.set_canvas_size(CANVAS_WIDTH, CANVAS_HEIGHT)
self.plc.set_placement_grid(GRID_COL, GRID_ROW)
self.plc_os.set_canvas_size(CANVAS_WIDTH, CANVAS_HEIGHT)
self.plc_os.set_placement_grid(GRID_COL, GRID_ROW)
assert int(self.plc_os.get_wirelength()) == int(self.plc.get_wirelength())
assert int(sum(self.plc_os.get_grid_cells_density())) == int(sum(self.plc.get_grid_cells_density()))
assert int(self.plc_os.get_density_cost()) == int(self.plc.get_density_cost())
def test_metadata(self):
# Google's Binary Executable
self.plc = plc_client_os.PlacementCost(self.NETLIST_PATH)
self.plc = plc_client.PlacementCost(self.NETLIST_PATH)
# Open-sourced Implementation
self.plc_os = plc_client_os.PlacementCost(netlist_file=self.NETLIST_PATH,
macro_macro_x_spacing = 50,
macro_macro_y_spacing = 50)
assert self.plc_os.get_block_name() == self.plc_os.get_block_name()
assert self.plc_os.get_project_name() == self.plc_os.get_project_name()
assert int(self.plc_os.get_area()) == int(self.plc_os.get_area())
assert int(self.plc_os.get_area()) == int(self.plc.get_area())
self.plc.set_routes_per_micron(1.0, 2.0)
self.plc_os.set_routes_per_micron(1.0, 2.0)
......@@ -67,7 +78,7 @@ class CircuitDataBaseTest(unittest.TestCase):
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_adjacency() == self.plc_os.get_macro_adjacency()
assert sum(self.plc.get_macro_adjacency()) == sum(self.plc_os.get_macro_adjacency())
def test_miscellaneous(self):
# Google's Binary Executable
......@@ -77,6 +88,11 @@ class CircuitDataBaseTest(unittest.TestCase):
macro_macro_x_spacing = 50,
macro_macro_y_spacing = 50)
def main(argv):
temp = CircuitDataBaseTest()
temp.test_proxy_cost()
temp.test_metadata()
temp.test_miscellaneous()
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
if __name__ == "__main__":
app.run(main)
\ No newline at end of file
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