Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
macroplacement
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
macroplacement
Commits
ae23da02
Commit
ae23da02
authored
Sep 05, 2022
by
Dinple
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates
parent
7beec4a5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
42 deletions
+71
-42
CodeElements/Plc_client/environment_os.py
+9
-0
CodeElements/Plc_client/plc_client_os_test.py
+62
-42
No files found.
CodeElements/Plc_client/environment_os.py
View file @
ae23da02
...
...
@@ -30,6 +30,7 @@ import gin
import
gym
import
numpy
as
np
import
tensorflow
as
tf
from
inspect
import
currentframe
,
getframeinfo
# from tf_agents.environments import suite_gym
# from tf_agents.environments import wrappers
...
...
@@ -123,6 +124,7 @@ class CircuitEnv(object):
def
__init__
(
self
,
_plc_client
=
None
,
netlist_file
:
Text
=
''
,
init_placement
:
Text
=
''
,
_plc
=
None
,
...
...
@@ -195,6 +197,8 @@ class CircuitEnv(object):
self
.
_observation_extractor
=
observation_extractor
.
ObservationExtractor
(
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
:
# It is better to make the shape of soft macros square before using
# analytical std cell placers like FD.
...
...
@@ -208,8 +212,10 @@ class CircuitEnv(object):
m
for
m
in
self
.
_plc
.
get_macro_indices
()
if
not
self
.
_plc
.
is_node_soft_macro
(
m
)
]
self
.
_num_hard_macros
=
len
(
self
.
_hard_macro_indices
)
# sorted by size
self
.
_sorted_node_indices
=
placement_util
.
get_ordered_node_indices
(
mode
=
'descending_size_macro_first'
,
plc
=
self
.
_plc
)
...
...
@@ -235,6 +241,7 @@ class CircuitEnv(object):
self
.
_current_node
=
0
self
.
_done
=
False
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
if
unplace_all_nodes_in_init
:
...
...
@@ -279,10 +286,12 @@ class CircuitEnv(object):
List of 0s and 1s indicating if action is feasible or not.
"""
if
self
.
_done
:
# reset the board
mask
=
np
.
zeros
(
self
.
_observation_config
.
max_grid_size
**
2
,
dtype
=
np
.
int32
)
else
:
node_index
=
self
.
_sorted_node_indices
[
self
.
_current_node
]
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
])
pad
=
((
self
.
_up_pad
,
self
.
_low_pad
),
(
self
.
_right_pad
,
self
.
_left_pad
))
mask
=
np
.
pad
(
mask
,
pad
,
mode
=
'constant'
,
constant_values
=
0
)
...
...
CodeElements/Plc_client/plc_client_os_test.py
View file @
ae23da02
import
numpy
as
np
import
pandas
as
pd
import
sys
,
os
,
traceback
import
argparse
import
math
,
re
from
random
import
randrange
from
absl
import
flags
from
absl.flags
import
argparse_flags
from
absl
import
app
...
...
@@ -293,22 +295,39 @@ class PlacementCostTest():
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_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_placement_grid
(
self
.
GRID_COL
,
self
.
GRID_ROW
)
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
))
self
.
plc_os
.
display_canvas
()
print
(
np
.
flip
(
np
.
array
(
self
.
plc_util
.
get_node_mask
(
0
))
.
reshape
(
35
,
33
),
axis
=
0
))
print
(
np
.
flip
(
np
.
array
(
self
.
plc
.
get_node_mask
(
0
))
.
reshape
(
35
,
33
),
axis
=
0
))
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 = 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("can_place_node", self.plc.can_place_node(0, 1))
print
(
"***************************************************"
)
...
...
@@ -333,7 +352,6 @@ class PlacementCostTest():
self
.
plc_os
.
set_canvas_size
(
self
.
CANVAS_WIDTH
,
self
.
CANVAS_HEIGHT
)
self
.
plc_os
.
set_placement_grid
(
self
.
GRID_COL
,
self
.
GRID_ROW
)
temp_gl_h
=
np
.
array
(
self
.
plc
.
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
))
...
...
@@ -406,19 +424,21 @@ class PlacementCostTest():
plc_client
=
plc_client_os
,
netlist_file
=
self
.
NETLIST_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_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
=
{}
for
i
in
placement_util
.
nodes_of_types
(
self
.
plc_util_os
,
[
'MACRO'
]):
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
)
...
...
@@ -429,18 +449,8 @@ class PlacementCostTest():
placement_util
.
save_placement
(
self
.
plc_util_os
,
"save_test_os.plc"
,
'this is a comment'
)
# ********************** 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)
# 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
)
# fix ports
...
...
@@ -496,15 +506,15 @@ class PlacementCostTest():
max_num_edges
=
28400
,
max_num_nodes
=
5000
,
max_grid_size
=
128
)
self
.
plc_util
=
placement_util
.
create_placement_cost
(
plc_client
=
plc_client
,
netlist_file
=
self
.
NETLIST_PATH
,
init_placement
=
self
.
PLC_PATH
plc_client
=
plc_client
,
netlist_file
=
self
.
NETLIST_PATH
,
init_placement
=
self
.
PLC_PATH
)
self
.
plc_util_os
=
placement_util
.
create_placement_cost
(
plc_client
=
plc_client_os
,
netlist_file
=
self
.
NETLIST_PATH
,
init_placement
=
self
.
PLC_PATH
plc_client
=
plc_client_os
,
netlist_file
=
self
.
NETLIST_PATH
,
init_placement
=
self
.
PLC_PATH
)
self
.
extractor
=
observation_extractor
.
ObservationExtractor
(
...
...
@@ -545,12 +555,22 @@ class PlacementCostTest():
create_placement_cost_fn
=
placement_util
.
create_placement_cost
,
netlist_file
=
self
.
NETLIST_PATH
,
init_placement
=
self
.
PLC_PATH
)
self
.
plc_util
=
placement_util
.
create_placement_cost
(
plc_client
=
plc_client
,
netlist_file
=
self
.
NETLIST_PATH
,
init_placement
=
self
.
PLC_PATH
)
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(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
(
" +++ TEST ENVIRONMENT: PASS +++"
)
...
...
@@ -609,7 +629,7 @@ def main(args):
# PCT.test_metadata()
PCT
.
test_proxy_cost
()
# PCT.test_placement_util()
# PCT.test_placement_util(
keep_save_file=True
)
# PCT.test_miscellaneous()
# PCT.test_observation_extractor()
PCT
.
test_environment
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment