Commit 7abd6224 by Dinple

update

parent a79db7e1
"""Open-Sourced PlacementCost client class."""
import os, io
from platform import node
import re
import math
from typing import Text, Tuple
......@@ -65,6 +66,8 @@ class PlacementCost(object):
# default gridding
self.grid_col = 10
self.grid_row = 10
# initial grid mask
self.global_node_mask = [0] * self.grid_col * self.grid_row
# store module/component count
self.port_cnt = len(self.port_indices)
self.hard_macro_cnt = len(self.hard_macro_indices)
......@@ -258,7 +261,10 @@ class PlacementCost(object):
hard_macro_pin.set_weight(float(attr_dict['weight'][1]))
if input_list:
self.net_cnt += 1
if 'weight' in attr_dict.keys():
self.net_cnt += 1 * float(attr_dict['weight'][1])
else:
self.net_cnt += 1
hard_macro_pin.add_sinks(input_list)
self.modules_w_pins.append(hard_macro_pin)
......@@ -353,12 +359,13 @@ class PlacementCost(object):
if inputs:
for k in inputs.keys():
if macro_type == "MACRO":
weight = pin.get_weight()
macro.add_connections(inputs[k], weight)
elif macro_type == "macro":
if macro_type == "MACRO" or macro_type == "macro":
weight = pin.get_weight()
macro.add_connections(inputs[k], weight)
def __update_placement(self):
# assign modules to grid cells
pass
def get_cost(self) -> float:
......@@ -676,11 +683,32 @@ class PlacementCost(object):
"""
return self.hrouting_alloc, self.vrouting_alloc
def is_node_soft_macro(self) -> bool:
return True
def is_node_soft_macro(self, node_idx) -> bool:
return self.get_node_type(node_idx) == "soft_macro"
def is_node_hard_macro(self, node_idx) -> bool:
return self.get_node_type(node_idx) == "hard_macro"
def get_node_name(self, node_idx: int) -> str:
return self.indices_to_mod_name[node_idx]
def get_node_mask(self, node_idx: int, node_name: str) -> list:
return list
"""
Return Grid_col x Grid_row:
1 == placable
0 == unplacable
(100, 100) => 5
(99, 99) => 0
(100, 99) => 1
(99, 100) => 4
Placement Constraint:
- center @ grid cell
- no overlapping other macro
- no OOB
"""
module = self.modules_w_pins[node_idx]
def get_node_type(self, node_idx: int) -> str:
"""
......@@ -730,12 +758,6 @@ class PlacementCost(object):
def is_node_fixed(self):
pass
def unplace_all_nodes(self):
pass
def place_node(self):
pass
def restore_placement(self, init_plc_pth: str):
"""
Read and retrieve .plc file information
......@@ -857,36 +879,69 @@ class PlacementCost(object):
return macro_adj, sorted(cell_location)
def get_node_location(self):
def get_node_location(self, node_idx):
pass
def get_grid_cell_of_node(self):
pass
def get_grid_cell_of_node(self, node_idx):
""" if grid_cell at grid crossing, break-tie to upper right
"""
return self.modules_w_pins(node_idx).get_location()
def update_macro_orientation(self):
def update_macro_orientation(self, node_idx, orientation):
pass
def get_macro_orientation(self):
pass
def unfix_node_coord(self):
"""In case plc is loaded with fixed macros
"""
pass
def unplace_node(self):
def fix_node_coord(self):
"""Find all ports and fix their coordinates.
"""
pass
def is_node_placed(self):
def unplace_all_nodes(self):
pass
def get_source_filename(self):
def place_node(self, node_idx, grid_cell_idx):
pass
def get_blockages(self):
def can_place_node(self, node_idx, grid_cell_idx):
return self.get_node_mask(node_idx=node_idx)[grid_cell_idx]
def unplace_node(self, node_idx):
# update node_mask
pass
def get_ref_node_id(self):
def is_node_placed(self, node_idx):
pass
def disconnect_nets(self):
pass
def get_source_filename(self):
"""return netlist path
"""
return self.netlist_file
def get_blockages(self):
pass
def get_ref_node_id(self, node_idx=-1):
"""ref_node_id is used for macro_pins. Refers to the macro it belongs to.
"""
if node_idx != -1:
if node_idx in self.soft_macro_pin_indices:
pin = self.modules_w_pins[node_idx]
return self.mod_name_to_indices[pin.get_macro_name()]
elif node_idx in self.hard_macro_pin_indices:
pin = self.modules_w_pins[node_idx]
return self.mod_name_to_indices[pin.get_macro_name()]
return -1
def save_placement(self):
pass
......@@ -949,6 +1004,7 @@ class PlacementCost(object):
self.sink = {} # standard cells, macro pins, ports driven by this cell
self.connection = {} # [module_name] => edge degree
self.ifFixed = True
self.placement = 0 # needs to be updated
def get_name(self):
return self.name
......@@ -1025,6 +1081,8 @@ class PlacementCost(object):
self.y = float(y)
self.connection = {} # [module_name] => edge degree
self.ifFixed = False
self.ifPlaced = True
self.location = 0 # needs to be updated
def get_name(self):
return self.name
......@@ -1073,6 +1131,12 @@ class PlacementCost(object):
def get_width(self):
return self.width
def set_location(self, grid_cell_idx):
self.location = grid_cell_idx
def get_location(self):
return self.location
class SoftMacroPin:
def __init__( self, name,
......@@ -1096,6 +1160,9 @@ class PlacementCost(object):
def get_name(self):
return self.name
def get_macro_name(self):
return self.macro_name
def set_pos(self, x, y):
self.x = x
self.y = y
......@@ -1148,6 +1215,8 @@ class PlacementCost(object):
self.orientation = orientation
self.connection = {} # [module_name] => edge degree
self.ifFixed = False
self.ifPlaced = True
self.location = 0 # needs to be updated
def get_name(self):
return self.name
......@@ -1199,6 +1268,12 @@ class PlacementCost(object):
def get_width(self):
return self.width
def set_location(self, grid_cell_idx):
self.location = grid_cell_idx
def get_location(self):
return self.location
class HardMacroPin:
def __init__(self, name,
......@@ -1213,6 +1288,7 @@ class PlacementCost(object):
self.macro_name = macro_name
self.weight = weight
self.sink = {}
self.ifPlaced = True
def set_weight(self, weight):
self.weight = weight
......@@ -1233,6 +1309,9 @@ class PlacementCost(object):
def get_name(self):
return self.name
def get_macro_name(self):
return self.macro_name
def add_sink(self, sink_name):
# NOTE: assume PORT names does not contain slash
ifPORT = False
......
......@@ -18,10 +18,10 @@ class CircuitDataBaseTest():
# 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"
# NETLIST_PATH = "./Plc_client/test/0P2M0m/netlist.pb.txt"
NETLIST_PATH = "./Plc_client/test/0P2M0m/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/0P1M1m/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/0P3M0m/netlist.pb.txt"
NETLIST_PATH = "./Plc_client/test/0P4M0m/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/0P4M0m/netlist.pb.txt"
# Google's Ariane
# CANVAS_WIDTH = 356.592
......@@ -151,12 +151,30 @@ class CircuitDataBaseTest():
def test_miscellaneous(self):
# Google's Binary Executable
self.plc = plc_client_os.PlacementCost(self.NETLIST_PATH)
# Open-sourced Implementation
self.plc = plc_client.PlacementCost(self.NETLIST_PATH)
self.plc_os = plc_client_os.PlacementCost(netlist_file=self.NETLIST_PATH,
macro_macro_x_spacing = 50,
macro_macro_y_spacing = 50)
print("****************** miscellaneous ******************")
self.plc.set_canvas_size(self.CANVAS_WIDTH, self.CANVAS_HEIGHT)
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_placement_grid(self.GRID_COL, self.GRID_ROW)
NODE_IDX = 0
print("get_macro_indices", self.plc.get_macro_indices(), self.plc_os.get_macro_indices())
print("get_node_name", self.plc.get_node_name(NODE_IDX))
print("get_node_location", self.plc.get_node_location(NODE_IDX))
print("get_grid_cell_of_node", self.plc.get_grid_cell_of_node(NODE_IDX))
print("get_node_location", self.plc.get_node_location(NODE_IDX))
print("get_macro_orientation", self.plc.get_macro_orientation(NODE_IDX))
print("is_node_placed", self.plc.is_node_placed(NODE_IDX))
print("get_source_filename", self.plc.get_source_filename())
print("get_blockages", self.plc.get_blockages())
print("get_ref_node_id", self.plc.get_ref_node_id(NODE_IDX), self.plc.get_ref_node_id(NODE_IDX))
print("get_node_mask\n", np.array(self.plc.get_node_mask(NODE_IDX)).reshape((4,4)))
print("can_place_node", self.plc.can_place_node(0, 1))
print("***************************************************")
def main(argv):
temp = CircuitDataBaseTest()
......
......@@ -69,13 +69,13 @@ node {
attr {
key: "x"
value {
f: 75
f: 375
}
}
attr {
key: "y"
value {
f: 25
f: 325
}
}
}
......
......@@ -5,7 +5,7 @@ node {
attr {
key: "height"
value {
f: 50
f: 200
}
}
attr {
......@@ -23,19 +23,19 @@ node {
attr {
key: "x"
value {
f: 350
f: 399
}
}
attr {
key: "y"
value {
f: 350
f: 399
}
}
attr {
key: "width"
value {
f: 50
f: 200
}
}
}
......@@ -108,13 +108,13 @@ node {
attr {
key: "x"
value {
f: 325
f: 374
}
}
attr {
key: "y"
value {
f: 325
f: 374
}
}
attr {
......@@ -153,13 +153,13 @@ node {
attr {
key: "x"
value {
f: 325
f: 374
}
}
attr {
key: "y"
value {
f: 375
f: 424
}
}
attr {
......
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