Commit ae23da02 by Dinple

updates

parent 7beec4a5
...@@ -30,6 +30,7 @@ import gin ...@@ -30,6 +30,7 @@ import gin
import gym import gym
import numpy as np import numpy as np
import tensorflow as tf import tensorflow as tf
from inspect import currentframe, getframeinfo
# from tf_agents.environments import suite_gym # from tf_agents.environments import suite_gym
# from tf_agents.environments import wrappers # from tf_agents.environments import wrappers
...@@ -123,6 +124,7 @@ class CircuitEnv(object): ...@@ -123,6 +124,7 @@ class CircuitEnv(object):
def __init__( def __init__(
self, self,
_plc_client = None,
netlist_file: Text = '', netlist_file: Text = '',
init_placement: Text = '', init_placement: Text = '',
_plc = None, _plc = None,
...@@ -195,6 +197,8 @@ class CircuitEnv(object): ...@@ -195,6 +197,8 @@ class CircuitEnv(object):
self._observation_extractor = observation_extractor.ObservationExtractor( self._observation_extractor = observation_extractor.ObservationExtractor(
plc=self._plc) plc=self._plc)
# print("FLAG1")
print(getframeinfo(currentframe()).lineno, '\n', np.array(self._plc.get_node_mask(0)).reshape(35,33))
if self._make_soft_macros_square: if self._make_soft_macros_square:
# It is better to make the shape of soft macros square before using # It is better to make the shape of soft macros square before using
# analytical std cell placers like FD. # analytical std cell placers like FD.
...@@ -208,8 +212,10 @@ class CircuitEnv(object): ...@@ -208,8 +212,10 @@ class CircuitEnv(object):
m for m in self._plc.get_macro_indices() m for m in self._plc.get_macro_indices()
if not self._plc.is_node_soft_macro(m) if not self._plc.is_node_soft_macro(m)
] ]
self._num_hard_macros = len(self._hard_macro_indices) self._num_hard_macros = len(self._hard_macro_indices)
# sorted by size
self._sorted_node_indices = placement_util.get_ordered_node_indices( self._sorted_node_indices = placement_util.get_ordered_node_indices(
mode='descending_size_macro_first', plc=self._plc) mode='descending_size_macro_first', plc=self._plc)
...@@ -235,6 +241,7 @@ class CircuitEnv(object): ...@@ -235,6 +241,7 @@ class CircuitEnv(object):
self._current_node = 0 self._current_node = 0
self._done = False self._done = False
self._current_mask = self._get_mask() self._current_mask = self._get_mask()
print(getframeinfo(currentframe()).lineno, '\n', np.array(self._plc.get_node_mask(0)).reshape(35,33))
self._infeasible_state = False self._infeasible_state = False
if unplace_all_nodes_in_init: if unplace_all_nodes_in_init:
...@@ -279,10 +286,12 @@ class CircuitEnv(object): ...@@ -279,10 +286,12 @@ class CircuitEnv(object):
List of 0s and 1s indicating if action is feasible or not. List of 0s and 1s indicating if action is feasible or not.
""" """
if self._done: if self._done:
# reset the board
mask = np.zeros(self._observation_config.max_grid_size**2, dtype=np.int32) mask = np.zeros(self._observation_config.max_grid_size**2, dtype=np.int32)
else: else:
node_index = self._sorted_node_indices[self._current_node] node_index = self._sorted_node_indices[self._current_node]
mask = np.asarray(self._plc.get_node_mask(node_index), dtype=np.int32) mask = np.asarray(self._plc.get_node_mask(node_index), dtype=np.int32)
print("current node mask: \n", mask.reshape(35, 33))
mask = np.reshape(mask, [self._grid_rows, self._grid_cols]) mask = np.reshape(mask, [self._grid_rows, self._grid_cols])
pad = ((self._up_pad, self._low_pad), (self._right_pad, self._left_pad)) pad = ((self._up_pad, self._low_pad), (self._right_pad, self._left_pad))
mask = np.pad(mask, pad, mode='constant', constant_values=0) mask = np.pad(mask, pad, mode='constant', constant_values=0)
......
import numpy as np import numpy as np
import pandas as pd
import sys,os,traceback import sys,os,traceback
import argparse import argparse
import math,re import math,re
from random import randrange
from absl import flags from absl import flags
from absl.flags import argparse_flags from absl.flags import argparse_flags
from absl import app from absl import app
...@@ -293,22 +295,39 @@ class PlacementCostTest(): ...@@ -293,22 +295,39 @@ class PlacementCostTest():
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_canvas_size(self.CANVAS_WIDTH, self.CANVAS_HEIGHT)
self.plc.set_placement_grid(self.GRID_COL, self.GRID_ROW) self.plc.set_placement_grid(self.GRID_COL, self.GRID_ROW)
self.plc_util = placement_util.create_placement_cost(
plc_client=plc_client,
netlist_file=self.NETLIST_PATH,
init_placement=self.PLC_PATH
)
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)
NODE_IDX = 22853
print("get_macro_indices", self.plc.get_macro_indices()) self.plc_os.display_canvas()
print("get_node_name", self.plc.get_node_name(NODE_IDX)) print(np.flip(np.array(self.plc_util.get_node_mask(0)).reshape(35,33), axis=0))
print("get_node_type", self.plc.get_node_type(NODE_IDX))
print("get_node_location", self.plc.get_node_location(NODE_IDX)) print(np.flip(np.array(self.plc.get_node_mask(0)).reshape(35,33), axis=0))
print("get_grid_cell_of_node", self.plc.get_grid_cell_of_node(NODE_IDX)) print("****************** miscellaneous ******************")
print("get_macro_orientation", self.plc.get_macro_orientation(NODE_IDX)) # self.plc.set_canvas_size(self.CANVAS_WIDTH, self.CANVAS_HEIGHT)
print("is_node_placed", self.plc.is_node_placed(NODE_IDX)) # self.plc.set_placement_grid(self.GRID_COL, self.GRID_ROW)
print("get_source_filename", self.plc.get_source_filename()) # self.plc_os.set_canvas_size(self.CANVAS_WIDTH, self.CANVAS_HEIGHT)
print("get_blockages", self.plc.get_blockages()) # self.plc_os.set_placement_grid(self.GRID_COL, self.GRID_ROW)
print("get_ref_node_id", self.plc.get_ref_node_id(NODE_IDX), self.plc.get_ref_node_id(NODE_IDX)) # NODE_IDX = 22853
# print("get_macro_indices", self.plc.get_macro_indices())
# print("get_node_name", self.plc.get_node_name(NODE_IDX))
# print("get_node_type", self.plc.get_node_type(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_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("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("can_place_node", self.plc.can_place_node(0, 1))
print("***************************************************") print("***************************************************")
...@@ -333,7 +352,6 @@ class PlacementCostTest(): ...@@ -333,7 +352,6 @@ class PlacementCostTest():
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)
temp_gl_h = np.array(self.plc.get_horizontal_routing_congestion()) temp_gl_h = np.array(self.plc.get_horizontal_routing_congestion())
temp_os_h = np.array(self.plc_os.get_horizontal_routing_congestion()) temp_os_h = np.array(self.plc_os.get_horizontal_routing_congestion())
print(temp_gl_h.reshape(self.GRID_COL, self.GRID_ROW)) print(temp_gl_h.reshape(self.GRID_COL, self.GRID_ROW))
...@@ -407,19 +425,21 @@ class PlacementCostTest(): ...@@ -407,19 +425,21 @@ class PlacementCostTest():
netlist_file=self.NETLIST_PATH, netlist_file=self.NETLIST_PATH,
init_placement=self.PLC_PATH init_placement=self.PLC_PATH
) )
# ********************** plc_client_os **********************
# node_xy_coordinates
# NODE_XY_DICT = {}
# for i in placement_util.nodes_of_types(self.plc_util_os, ['MACRO', 'STDCELL', 'PORT']):
# NODE_XY_DICT[i] = (100, 100)
# placement_util.restore_node_xy_coordinates(self.plc_util_os, NODE_XY_DICT) # node_xy_coordinates
NODE_XY_DICT = {}
for i in placement_util.nodes_of_types(self.plc_util_os, ['MACRO', 'STDCELL', 'PORT']):
NODE_XY_DICT[i] = (randrange(int(self.plc_util.get_canvas_width_height()[0])),
randrange(int(self.plc_util.get_canvas_width_height()[1])))
# macro_orientation # macro_orientation
MACRO_ORIENTATION = {} MACRO_ORIENTATION = {}
for i in placement_util.nodes_of_types(self.plc_util_os, ['MACRO']): for i in placement_util.nodes_of_types(self.plc_util_os, ['MACRO']):
MACRO_ORIENTATION[i] = "S" MACRO_ORIENTATION[i] = "S"
# ********************** plc_client_os **********************
# placement_util.restore_node_xy_coordinates(self.plc_util_os, NODE_XY_DICT)
placement_util.restore_macro_orientations(self.plc_util_os, MACRO_ORIENTATION) placement_util.restore_macro_orientations(self.plc_util_os, MACRO_ORIENTATION)
# fix ports # fix ports
...@@ -429,18 +449,8 @@ class PlacementCostTest(): ...@@ -429,18 +449,8 @@ class PlacementCostTest():
placement_util.save_placement(self.plc_util_os, "save_test_os.plc", 'this is a comment') placement_util.save_placement(self.plc_util_os, "save_test_os.plc", 'this is a comment')
# ********************** plc_client ********************** # ********************** plc_client **********************
# # node_xy_coordinates
# NODE_XY_DICT = {}
# for i in placement_util.nodes_of_types(self.plc_util, ['MACRO', 'STDCELL', 'PORT']):
# NODE_XY_DICT[i] = (100, 100)
# placement_util.restore_node_xy_coordinates(self.plc_util, NODE_XY_DICT) # placement_util.restore_node_xy_coordinates(self.plc_util, NODE_XY_DICT)
# macro_orientation
MACRO_ORIENTATION = {}
for i in placement_util.nodes_of_types(self.plc_util, ['MACRO']):
MACRO_ORIENTATION[i] = "S"
placement_util.restore_macro_orientations(self.plc_util, MACRO_ORIENTATION) placement_util.restore_macro_orientations(self.plc_util, MACRO_ORIENTATION)
# fix ports # fix ports
...@@ -546,11 +556,21 @@ class PlacementCostTest(): ...@@ -546,11 +556,21 @@ class PlacementCostTest():
netlist_file=self.NETLIST_PATH, netlist_file=self.NETLIST_PATH,
init_placement=self.PLC_PATH) init_placement=self.PLC_PATH)
env_os = environment.CircuitEnv( self.plc_util = placement_util.create_placement_cost(
_plc=plc_client_os, plc_client=plc_client,
create_placement_cost_fn=placement_util.create_placement_cost,
netlist_file=self.NETLIST_PATH, netlist_file=self.NETLIST_PATH,
init_placement=self.PLC_PATH) init_placement=self.PLC_PATH
)
# print(np.array2string(env._current_mask.reshape(128, 128)), sep=']')
# env_os = environment.CircuitEnv(
# _plc=plc_client_os,
# create_placement_cost_fn=placement_util.create_placement_cost,
# netlist_file=self.NETLIST_PATH,
# init_placement=self.PLC_PATH)
print(" ++++++++++++++++++++++++++++++") print(" ++++++++++++++++++++++++++++++")
print(" +++ TEST ENVIRONMENT: PASS +++") print(" +++ TEST ENVIRONMENT: PASS +++")
...@@ -609,7 +629,7 @@ def main(args): ...@@ -609,7 +629,7 @@ def main(args):
# PCT.test_metadata() # PCT.test_metadata()
PCT.test_proxy_cost() PCT.test_proxy_cost()
# PCT.test_placement_util() # PCT.test_placement_util(keep_save_file=True)
# PCT.test_miscellaneous() # PCT.test_miscellaneous()
# PCT.test_observation_extractor() # PCT.test_observation_extractor()
PCT.test_environment() PCT.test_environment()
......
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