Commit 7abd6224 by Dinple

update

parent a79db7e1
"""Open-Sourced PlacementCost client class.""" """Open-Sourced PlacementCost client class."""
import os, io import os, io
from platform import node
import re import re
import math import math
from typing import Text, Tuple from typing import Text, Tuple
...@@ -65,6 +66,8 @@ class PlacementCost(object): ...@@ -65,6 +66,8 @@ class PlacementCost(object):
# default gridding # default gridding
self.grid_col = 10 self.grid_col = 10
self.grid_row = 10 self.grid_row = 10
# initial grid mask
self.global_node_mask = [0] * self.grid_col * self.grid_row
# 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)
...@@ -258,7 +261,10 @@ class PlacementCost(object): ...@@ -258,7 +261,10 @@ class PlacementCost(object):
hard_macro_pin.set_weight(float(attr_dict['weight'][1])) hard_macro_pin.set_weight(float(attr_dict['weight'][1]))
if input_list: 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) hard_macro_pin.add_sinks(input_list)
self.modules_w_pins.append(hard_macro_pin) self.modules_w_pins.append(hard_macro_pin)
...@@ -353,12 +359,13 @@ class PlacementCost(object): ...@@ -353,12 +359,13 @@ class PlacementCost(object):
if inputs: if inputs:
for k in inputs.keys(): for k in inputs.keys():
if macro_type == "MACRO": if macro_type == "MACRO" or macro_type == "macro":
weight = pin.get_weight()
macro.add_connections(inputs[k], weight)
elif macro_type == "macro":
weight = pin.get_weight() weight = pin.get_weight()
macro.add_connections(inputs[k], weight) macro.add_connections(inputs[k], weight)
def __update_placement(self):
# assign modules to grid cells
pass
def get_cost(self) -> float: def get_cost(self) -> float:
...@@ -676,11 +683,32 @@ class PlacementCost(object): ...@@ -676,11 +683,32 @@ class PlacementCost(object):
""" """
return self.hrouting_alloc, self.vrouting_alloc return self.hrouting_alloc, self.vrouting_alloc
def is_node_soft_macro(self) -> bool: def is_node_soft_macro(self, node_idx) -> bool:
return True 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: 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: def get_node_type(self, node_idx: int) -> str:
""" """
...@@ -730,12 +758,6 @@ class PlacementCost(object): ...@@ -730,12 +758,6 @@ class PlacementCost(object):
def is_node_fixed(self): def is_node_fixed(self):
pass pass
def unplace_all_nodes(self):
pass
def place_node(self):
pass
def restore_placement(self, init_plc_pth: str): def restore_placement(self, init_plc_pth: str):
""" """
Read and retrieve .plc file information Read and retrieve .plc file information
...@@ -857,36 +879,69 @@ class PlacementCost(object): ...@@ -857,36 +879,69 @@ class PlacementCost(object):
return macro_adj, sorted(cell_location) return macro_adj, sorted(cell_location)
def get_node_location(self): def get_node_location(self, node_idx):
pass pass
def get_grid_cell_of_node(self): def get_grid_cell_of_node(self, node_idx):
pass """ 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 pass
def get_macro_orientation(self): def get_macro_orientation(self):
pass pass
def unfix_node_coord(self): def unfix_node_coord(self):
"""In case plc is loaded with fixed macros
"""
pass pass
def unplace_node(self): def fix_node_coord(self):
"""Find all ports and fix their coordinates.
"""
pass pass
def is_node_placed(self): def unplace_all_nodes(self):
pass pass
def get_source_filename(self): def place_node(self, node_idx, grid_cell_idx):
pass 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 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 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): def save_placement(self):
pass pass
...@@ -949,6 +1004,7 @@ class PlacementCost(object): ...@@ -949,6 +1004,7 @@ class PlacementCost(object):
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 self.ifFixed = True
self.placement = 0 # needs to be updated
def get_name(self): def get_name(self):
return self.name return self.name
...@@ -1025,6 +1081,8 @@ class PlacementCost(object): ...@@ -1025,6 +1081,8 @@ class PlacementCost(object):
self.y = float(y) self.y = float(y)
self.connection = {} # [module_name] => edge degree self.connection = {} # [module_name] => edge degree
self.ifFixed = False self.ifFixed = False
self.ifPlaced = True
self.location = 0 # needs to be updated
def get_name(self): def get_name(self):
return self.name return self.name
...@@ -1073,6 +1131,12 @@ class PlacementCost(object): ...@@ -1073,6 +1131,12 @@ class PlacementCost(object):
def get_width(self): def get_width(self):
return self.width return self.width
def set_location(self, grid_cell_idx):
self.location = grid_cell_idx
def get_location(self):
return self.location
class SoftMacroPin: class SoftMacroPin:
def __init__( self, name, def __init__( self, name,
...@@ -1096,6 +1160,9 @@ class PlacementCost(object): ...@@ -1096,6 +1160,9 @@ class PlacementCost(object):
def get_name(self): def get_name(self):
return self.name return self.name
def get_macro_name(self):
return self.macro_name
def set_pos(self, x, y): def set_pos(self, x, y):
self.x = x self.x = x
self.y = y self.y = y
...@@ -1148,6 +1215,8 @@ class PlacementCost(object): ...@@ -1148,6 +1215,8 @@ class PlacementCost(object):
self.orientation = orientation self.orientation = orientation
self.connection = {} # [module_name] => edge degree self.connection = {} # [module_name] => edge degree
self.ifFixed = False self.ifFixed = False
self.ifPlaced = True
self.location = 0 # needs to be updated
def get_name(self): def get_name(self):
return self.name return self.name
...@@ -1199,6 +1268,12 @@ class PlacementCost(object): ...@@ -1199,6 +1268,12 @@ class PlacementCost(object):
def get_width(self): def get_width(self):
return self.width return self.width
def set_location(self, grid_cell_idx):
self.location = grid_cell_idx
def get_location(self):
return self.location
class HardMacroPin: class HardMacroPin:
def __init__(self, name, def __init__(self, name,
...@@ -1213,6 +1288,7 @@ class PlacementCost(object): ...@@ -1213,6 +1288,7 @@ class PlacementCost(object):
self.macro_name = macro_name self.macro_name = macro_name
self.weight = weight self.weight = weight
self.sink = {} self.sink = {}
self.ifPlaced = True
def set_weight(self, weight): def set_weight(self, weight):
self.weight = weight self.weight = weight
...@@ -1233,6 +1309,9 @@ class PlacementCost(object): ...@@ -1233,6 +1309,9 @@ class PlacementCost(object):
def get_name(self): def get_name(self):
return self.name return self.name
def get_macro_name(self):
return self.macro_name
def add_sink(self, sink_name): def add_sink(self, sink_name):
# NOTE: assume PORT names does not contain slash # NOTE: assume PORT names does not contain slash
ifPORT = False ifPORT = False
......
...@@ -18,10 +18,10 @@ class CircuitDataBaseTest(): ...@@ -18,10 +18,10 @@ class CircuitDataBaseTest():
# 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"
# 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/0P1M1m/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/0P3M0m/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 # Google's Ariane
# CANVAS_WIDTH = 356.592 # CANVAS_WIDTH = 356.592
...@@ -151,12 +151,30 @@ class CircuitDataBaseTest(): ...@@ -151,12 +151,30 @@ class CircuitDataBaseTest():
def test_miscellaneous(self): def test_miscellaneous(self):
# Google's Binary Executable # 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, self.plc_os = plc_client_os.PlacementCost(netlist_file=self.NETLIST_PATH,
macro_macro_x_spacing = 50, macro_macro_x_spacing = 50,
macro_macro_y_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): def main(argv):
temp = CircuitDataBaseTest() temp = CircuitDataBaseTest()
......
...@@ -69,13 +69,13 @@ node { ...@@ -69,13 +69,13 @@ node {
attr { attr {
key: "x" key: "x"
value { value {
f: 75 f: 375
} }
} }
attr { attr {
key: "y" key: "y"
value { value {
f: 25 f: 325
} }
} }
} }
......
...@@ -5,7 +5,7 @@ node { ...@@ -5,7 +5,7 @@ node {
attr { attr {
key: "height" key: "height"
value { value {
f: 50 f: 200
} }
} }
attr { attr {
...@@ -23,19 +23,19 @@ node { ...@@ -23,19 +23,19 @@ node {
attr { attr {
key: "x" key: "x"
value { value {
f: 350 f: 399
} }
} }
attr { attr {
key: "y" key: "y"
value { value {
f: 350 f: 399
} }
} }
attr { attr {
key: "width" key: "width"
value { value {
f: 50 f: 200
} }
} }
} }
...@@ -108,13 +108,13 @@ node { ...@@ -108,13 +108,13 @@ node {
attr { attr {
key: "x" key: "x"
value { value {
f: 325 f: 374
} }
} }
attr { attr {
key: "y" key: "y"
value { value {
f: 325 f: 374
} }
} }
attr { attr {
...@@ -153,13 +153,13 @@ node { ...@@ -153,13 +153,13 @@ node {
attr { attr {
key: "x" key: "x"
value { value {
f: 325 f: 374
} }
} }
attr { attr {
key: "y" key: "y"
value { value {
f: 375 f: 424
} }
} }
attr { 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