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
0173d080
Commit
0173d080
authored
Aug 19, 2022
by
Dinple
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug fixing
parent
8988a64b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
59 deletions
+77
-59
CodeElements/Plc_client/plc_client_os.py
+38
-36
CodeElements/Plc_client/plc_client_os_test.py
+39
-23
No files found.
CodeElements/Plc_client/plc_client_os.py
View file @
0173d080
...
...
@@ -31,10 +31,6 @@ class PlacementCost(object):
self
.
init_plc
=
None
self
.
project_name
=
"circuit_training"
self
.
block_name
=
netlist_file
.
rsplit
(
'/'
,
-
1
)[
-
2
]
self
.
width
=
0.0
self
.
height
=
0.0
self
.
grid_col
=
10
self
.
grid_row
=
10
self
.
hroutes_per_micron
=
0.0
self
.
vroutes_per_micron
=
0.0
self
.
smooth_range
=
0.0
...
...
@@ -62,6 +58,13 @@ class PlacementCost(object):
self
.
soft_macros_to_inpins
=
{}
# read netlist
self
.
__read_protobuf
()
# default canvas width/height based on cell area
self
.
width
=
math
.
sqrt
(
self
.
get_area
()
/
0.6
)
self
.
height
=
math
.
sqrt
(
self
.
get_area
()
/
0.6
)
# default gridding
self
.
grid_col
=
10
self
.
grid_row
=
10
# store module/component count
self
.
port_cnt
=
len
(
self
.
port_indices
)
self
.
hard_macro_cnt
=
len
(
self
.
hard_macro_indices
)
...
...
@@ -361,16 +364,6 @@ class PlacementCost(object):
"""
Compute wirelength cost from wirelength
"""
# temp_net_cnt = math.floor(self.net_cnt * 0.15)
# if temp_net_cnt == 0:
# temp_net_cnt = 1
# unknown_threshold = 100
# if self.net_cnt <= unknown_threshold:
# return self.get_wirelength() / ((self.get_canvas_width_height()[0] + self.get_canvas_width_height()[1]) * temp_net_cnt)
# else:
return
self
.
get_wirelength
()
/
((
self
.
get_canvas_width_height
()[
0
]
+
self
.
get_canvas_width_height
()[
1
])
*
self
.
net_cnt
)
def
get_area
(
self
)
->
float
:
...
...
@@ -707,14 +700,14 @@ class PlacementCost(object):
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
):
for
row_idx
,
module_idx
in
enumerate
(
sorted
(
module_indices
)
):
# row index
# store temp module
curr_module
=
self
.
modules_w_pins
[
module_idx
]
# get module name
curr_module_name
=
curr_module
.
get_name
()
for
col_idx
,
h_module_idx
in
enumerate
(
module_indices
):
for
col_idx
,
h_module_idx
in
enumerate
(
sorted
(
module_indices
)
):
# col index
entry
=
0
# store connected module
...
...
@@ -767,6 +760,7 @@ class PlacementCost(object):
def
get_macro_and_clustered_port_adjacency
(
self
):
"""
Compute Adjacency Matrix (Unclustered PORTs)
if module is a PORT, assign nearest cell location even if OOB
"""
#[MACRO][macro]
module_indices
=
self
.
hard_macro_indices
+
self
.
soft_macro_indices
...
...
@@ -779,6 +773,19 @@ class PlacementCost(object):
row
,
col
=
self
.
__get_grid_cell_location
(
x_pos
=
x_pos
,
y_pos
=
y_pos
)
# prevent OOB
if
row
>=
self
.
grid_row
:
row
=
self
.
grid_row
-
1
if
row
<
0
:
row
=
0
if
col
>=
self
.
grid_col
:
col
=
self
.
grid_col
-
1
if
col
<
0
:
col
=
0
if
(
row
,
col
)
in
clustered_ports
:
clustered_ports
[(
row
,
col
)]
.
append
(
port
)
else
:
...
...
@@ -789,13 +796,13 @@ class PlacementCost(object):
cell_location
=
[
0
]
*
len
(
clustered_ports
)
# instantiate macros
for
row_idx
,
module_idx
in
enumerate
(
module_indices
):
for
row_idx
,
module_idx
in
enumerate
(
sorted
(
module_indices
)
):
# store temp module
curr_module
=
self
.
modules_w_pins
[
module_idx
]
# get module name
curr_module_name
=
curr_module
.
get_name
()
for
col_idx
,
h_module_idx
in
enumerate
(
module_indices
):
for
col_idx
,
h_module_idx
in
enumerate
(
sorted
(
module_indices
)
):
# col index
entry
=
0
# store connected module
...
...
@@ -813,9 +820,11 @@ class PlacementCost(object):
macro_adj
[
col_idx
*
(
len
(
module_indices
)
+
len
(
clustered_ports
))
+
row_idx
]
=
entry
# instantiate clustered ports
for
row_idx
,
cluster_cell
in
enumerate
(
clustered_ports
):
for
row_idx
,
cluster_cell
in
enumerate
(
sorted
(
clustered_ports
,
key
=
lambda
tup
:
tup
[
1
])):
# print("cluster_cell", cluster_cell)
# print("port cnt", len(clustered_ports[cluster_cell]))
# add cell location
cell_location
[
row_idx
]
=
cluster_cell
[
0
]
*
self
.
grid_
row
+
cluster_cell
[
1
]
cell_location
[
row_idx
]
=
cluster_cell
[
0
]
*
self
.
grid_
col
+
cluster_cell
[
1
]
# relocate to after macros
row_idx
+=
len
(
module_indices
)
...
...
@@ -824,8 +833,7 @@ class PlacementCost(object):
for
curr_port
in
clustered_ports
[
cluster_cell
]:
# get module name
curr_port_name
=
curr_port
.
get_name
()
# print("curr_port_name", curr_port_name)
# print("connections", curr_port.get_connection())
# print("curr_port_name", curr_port_name, curr_port.get_pos())
# assuming ports only connects to macros
for
col_idx
,
h_module_idx
in
enumerate
(
module_indices
):
# col index
...
...
@@ -842,7 +850,7 @@ class PlacementCost(object):
if
h_module_name
in
curr_port
.
get_connection
():
entry
+=
curr_port
.
get_connection
()[
h_module_name
]
macro_adj
[
row_idx
*
(
len
(
module_indices
)
+
len
(
clustered_ports
))
+
col_idx
]
+=
entry
macro_adj
[
col_idx
*
(
len
(
module_indices
)
+
len
(
clustered_ports
))
+
row_idx
]
+=
entry
...
...
@@ -890,8 +898,8 @@ class PlacementCost(object):
ax
.
set_aspect
(
'equal'
,
adjustable
=
'box'
)
# Construct grid
x
,
y
=
np
.
meshgrid
(
np
.
linspace
(
0
,
self
.
height
,
self
.
grid_row
+
1
),
\
np
.
linspace
(
0
,
self
.
width
,
self
.
grid_col
+
1
))
x
,
y
=
np
.
meshgrid
(
np
.
linspace
(
0
,
self
.
width
,
self
.
grid_col
+
1
),
\
np
.
linspace
(
0
,
self
.
height
,
self
.
grid_row
+
1
))
ax
.
plot
(
x
,
y
,
c
=
'b'
,
alpha
=
0.1
)
# use plot, not scatter
ax
.
plot
(
np
.
transpose
(
x
),
np
.
transpose
(
y
),
c
=
'b'
,
alpha
=
0.2
)
# add this here
...
...
@@ -899,7 +907,7 @@ class PlacementCost(object):
# Construct module blocks
for
mod
in
self
.
modules_w_pins
:
if
mod
.
get_type
()
==
'PORT'
:
plt
.
plot
(
*
mod
.
get_pos
(),
'ro'
,
markersize
=
2
)
plt
.
plot
(
*
mod
.
get_pos
(),
'ro'
,
markersize
=
4
)
elif
mod
.
get_type
()
==
'MACRO'
:
ax
.
add_patch
(
Rectangle
((
mod
.
get_pos
()[
0
]
-
mod
.
get_width
()
/
2
,
mod
.
get_pos
()[
1
]
-
mod
.
get_height
()
/
2
),
\
mod
.
get_width
(),
mod
.
get_height
(),
\
...
...
@@ -928,6 +936,7 @@ class PlacementCost(object):
self
.
side
=
side
# "BOTTOM", "TOP", "LEFT", "RIGHT"
self
.
sink
=
{}
# standard cells, macro pins, ports driven by this cell
self
.
connection
=
{}
# [module_name] => edge degree
self
.
ifFixed
=
True
def
get_name
(
self
):
return
self
.
name
...
...
@@ -1003,6 +1012,7 @@ class PlacementCost(object):
self
.
x
=
float
(
x
)
self
.
y
=
float
(
y
)
self
.
connection
=
{}
# [module_name] => edge degree
self
.
ifFixed
=
False
def
get_name
(
self
):
return
self
.
name
...
...
@@ -1124,6 +1134,7 @@ class PlacementCost(object):
self
.
y
=
float
(
y
)
self
.
orientation
=
orientation
self
.
connection
=
{}
# [module_name] => edge degree
self
.
ifFixed
=
False
def
get_name
(
self
):
return
self
.
name
...
...
@@ -1238,7 +1249,7 @@ class PlacementCost(object):
def
main
():
test_netlist_dir
=
'./Plc_client/test/'
+
\
'ariane'
'ariane
133
'
netlist_file
=
os
.
path
.
join
(
test_netlist_dir
,
'netlist.pb.txt'
)
plc
=
PlacementCost
(
netlist_file
)
...
...
@@ -1254,15 +1265,6 @@ def main():
print
(
"# SOFT_MACROs :
%
d"
%
(
plc
.
get_soft_macro_count
()))
print
(
"# SOFT_MACRO_PINs :
%
d"
%
(
plc
.
get_soft_macro_pin_count
()))
print
(
"# STDCELLs : 0"
)
# print(adj[137])
# print(np.unique(adj))
print
(
plc
.
set_canvas_size
(
356.592
,
356.640
))
print
(
plc
.
set_placement_grid
(
35
,
33
))
# print(plc.set_canvas_size(80, 80))
# print(plc.set_placement_grid(5, 5))
print
(
plc
.
get_grid_cells_density
())
print
(
plc
.
get_density_cost
())
if
__name__
==
'__main__'
:
main
()
CodeElements/Plc_client/plc_client_os_test.py
View file @
0173d080
...
...
@@ -4,6 +4,8 @@ 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
import
time
import
math
np
.
set_printoptions
(
threshold
=
sys
.
maxsize
)
FLAGS
=
flags
.
FLAGS
...
...
@@ -13,9 +15,9 @@ class CircuitDataBaseTest():
# 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"
#
NETLIST_PATH = "./Plc_client/test/ariane133/netlist.pb.txt"
# Google's Ariane
# CANVAS_WIDTH = 356.592
...
...
@@ -24,21 +26,27 @@ class CircuitDataBaseTest():
# GRID_ROW = 33
# Ariane133
CANVAS_WIDTH
=
1599.99
CANVAS_HEIGHT
=
1598.8
GRID_COL
=
50
GRID_ROW
=
50
# CANVAS_WIDTH = 1430.723
# CANVAS_HEIGHT = 1430.723
# GRID_COL = 24
# GRID_ROW = 21
# Sample clustered
#
CANVAS_WIDTH = 500
#
CANVAS_HEIGHT = 500
#
GRID_COL = 4
#
GRID_ROW = 4
CANVAS_WIDTH
=
500
CANVAS_HEIGHT
=
500
GRID_COL
=
4
GRID_ROW
=
4
def
test_proxy_cost
(
self
):
# Google's Binary Executable
self
.
plc
=
plc_client
.
PlacementCost
(
self
.
NETLIST_PATH
)
print
(
self
.
plc
.
get_canvas_width_height
())
print
(
"start timing"
)
start
=
time
.
time
()
print
(
self
.
plc
.
get_congestion_cost
())
end
=
time
.
time
()
print
(
"time elapsed:"
,
end
-
start
)
print
(
"end timing"
)
# Open-sourced Implementation
self
.
plc_os
=
plc_client_os
.
PlacementCost
(
netlist_file
=
self
.
NETLIST_PATH
,
macro_macro_x_spacing
=
50
,
...
...
@@ -48,6 +56,7 @@ class CircuitDataBaseTest():
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
)
# print(self.plc_os.display_canvas())
print
(
self
.
plc_os
.
get_wirelength
(),
self
.
plc
.
get_wirelength
())
...
...
@@ -93,24 +102,31 @@ class CircuitDataBaseTest():
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
()
# test get_macro_adjacency
plc_macroadj
=
self
.
plc
.
get_macro_adjacency
()
plc_macroadj
=
np
.
array
(
plc_macroadj
)
.
reshape
(
int
(
math
.
sqrt
(
len
(
plc_macroadj
))),
\
int
(
math
.
sqrt
(
len
(
plc_macroadj
))))
plcos_macroadj
=
self
.
plc_os
.
get_macro_adjacency
()
# print("diff macro", np.nonzero(np.array(plc_macroadj) - np.array(plcos_macroadj)))
plcos_macroadj
=
np
.
array
(
plcos_macroadj
)
.
reshape
(
int
(
math
.
sqrt
(
len
(
plcos_macroadj
))),
\
int
(
math
.
sqrt
(
len
(
plcos_macroadj
))))
# print(self.plc_os.get_macro_and_clustered_port_adjacency())
# print(self.plc.get_macro_and_clustered_port_adjacency()[0])
# print("gl number of clustered ports found:", self.plc.get_macro_and_clustered_port_adjacency()[0])
# print("our number of clustered ports found:", self.plc_os.get_macro_and_clustered_port_adjacency()[0])
# print(self.plc_os.display_canvas())
assert
(
np
.
sum
(
np
.
nonzero
(
plc_macroadj
-
plcos_macroadj
))
==
0
)
# test get_macro_and_clustered_port_adjacency
plc_clusteradj
,
plc_cell
=
self
.
plc
.
get_macro_and_clustered_port_adjacency
()
plc_clusteradj
=
np
.
array
(
plc_clusteradj
)
.
reshape
(
int
(
math
.
sqrt
(
len
(
plc_clusteradj
))),
\
int
(
math
.
sqrt
(
len
(
plc_clusteradj
))))
# print("count", self.plc_os.soft_macro_cnt, self.plc_os.hard_macro_cnt, self.plc_os.port_cnt)
plcos_clusteradj
,
plcos_cell
=
self
.
plc_os
.
get_macro_and_clustered_port_adjacency
()
plcos_clusteradj
=
np
.
array
(
plcos_clusteradj
)
.
reshape
(
int
(
math
.
sqrt
(
len
(
plcos_clusteradj
))),
\
int
(
math
.
sqrt
(
len
(
plcos_clusteradj
))))
assert
(
plc_cell
==
plcos_cell
)
for
plc_adj
,
plcos_adj
in
zip
(
plc_clusteradj
,
plcos_clusteradj
):
assert
(
np
.
sum
(
np
.
nonzero
(
plc_adj
-
plcos_adj
))
==
0
)
# compare both macro and clustered ports array
for
plc_adj
,
plcos_adj
in
zip
(
self
.
plc
.
get_macro_and_clustered_port_adjacency
(),
self
.
plc_os
.
get_macro_and_clustered_port_adjacency
()):
# print("diff macro cluster", np.nonzero(np.array(plc_adj) - np.array(plcos_adj)))
assert
sum
(
plc_adj
)
==
sum
(
plcos_adj
)
def
test_miscellaneous
(
self
):
# Google's Binary Executable
self
.
plc
=
plc_client_os
.
PlacementCost
(
self
.
NETLIST_PATH
)
...
...
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