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
05aa7fe6
Commit
05aa7fe6
authored
Aug 15, 2022
by
Dinple
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adj matrix bug fixes
parent
9256f51a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
56 deletions
+68
-56
CodeElements/Plc_client/plc_client_os.py
+30
-34
CodeElements/Plc_client/plc_client_os_test.py
+38
-22
No files found.
CodeElements/Plc_client/plc_client_os.py
View file @
05aa7fe6
...
@@ -11,8 +11,6 @@ import numpy as np
...
@@ -11,8 +11,6 @@ import numpy as np
Block
=
namedtuple
(
'Block'
,
'x_max y_max x_min y_min'
)
Block
=
namedtuple
(
'Block'
,
'x_max y_max x_min y_min'
)
# FLAGS = flags.FLAG
class
PlacementCost
(
object
):
class
PlacementCost
(
object
):
def
__init__
(
self
,
def
__init__
(
self
,
...
@@ -338,9 +336,14 @@ class PlacementCost(object):
...
@@ -338,9 +336,14 @@ class PlacementCost(object):
for
pin_name
in
pin_names
:
for
pin_name
in
pin_names
:
pin
=
self
.
modules_w_pins
[
self
.
mod_name_to_indices
[
pin_name
]]
pin
=
self
.
modules_w_pins
[
self
.
mod_name_to_indices
[
pin_name
]]
inputs
=
pin
.
get_sink
()
inputs
=
pin
.
get_sink
()
if
inputs
:
if
inputs
:
for
k
in
inputs
.
keys
():
for
k
in
inputs
.
keys
():
macro
.
add_connections
(
inputs
[
k
])
if
macro_type
==
"MACRO"
:
macro
.
add_connections
(
inputs
[
k
])
elif
macro_type
==
"macro"
:
weight
=
pin
.
get_weight
()
macro
.
add_connections
(
inputs
[
k
],
weight
)
def
get_cost
(
self
)
->
float
:
def
get_cost
(
self
)
->
float
:
...
@@ -462,8 +465,6 @@ class PlacementCost(object):
...
@@ -462,8 +465,6 @@ class PlacementCost(object):
x_min
=
mod_x
-
(
mod_w
/
2
),
x_min
=
mod_x
-
(
mod_w
/
2
),
y_min
=
mod_y
-
(
mod_h
/
2
)
y_min
=
mod_y
-
(
mod_h
/
2
)
)
)
print
(
"Module Four corners"
)
print
(
"Upper Left"
,
ur
,
"
\n
Bottom Right"
,
br
,
"
\n
Upper Left"
,
ul
,
"
\n
Bottom Left"
,
bl
)
# Four corner grid cells
# Four corner grid cells
ur_row
,
ur_col
=
self
.
__get_grid_cell_location
(
*
ur
)
ur_row
,
ur_col
=
self
.
__get_grid_cell_location
(
*
ur
)
...
@@ -480,7 +481,6 @@ class PlacementCost(object):
...
@@ -480,7 +481,6 @@ class PlacementCost(object):
bl_col
=
0
bl_col
=
0
else
:
else
:
# OOB, skip module
# OOB, skip module
print
(
"OOB skipped"
)
return
return
if
bl_row
>=
0
and
bl_col
>=
0
:
if
bl_row
>=
0
and
bl_col
>=
0
:
...
@@ -491,15 +491,10 @@ class PlacementCost(object):
...
@@ -491,15 +491,10 @@ class PlacementCost(object):
ur_col
=
self
.
grid_col
-
1
ur_col
=
self
.
grid_col
-
1
else
:
else
:
# OOB, skip module
# OOB, skip module
print
(
"OOB skipped"
)
return
return
print
(
"Four Corner Grid"
)
print
(
"UR row"
,
ur_row
,
"
\n
UR col"
,
ur_col
,
"
\n
BL row"
,
bl_row
,
"
\n
BL col"
,
bl_col
)
for
r_i
in
range
(
bl_row
,
ur_row
+
1
):
for
r_i
in
range
(
bl_row
,
ur_row
+
1
):
for
c_i
in
range
(
bl_col
,
ur_col
+
1
):
for
c_i
in
range
(
bl_col
,
ur_col
+
1
):
print
(
r_i
,
c_i
)
# construct block based on current cell row/col
# construct block based on current cell row/col
grid_cell_block
=
Block
(
grid_cell_block
=
Block
(
x_max
=
(
c_i
+
1
)
*
self
.
grid_width
,
x_max
=
(
c_i
+
1
)
*
self
.
grid_width
,
...
@@ -514,9 +509,6 @@ class PlacementCost(object):
...
@@ -514,9 +509,6 @@ class PlacementCost(object):
# if abs(self.grid_occupied[self.grid_row * r_i + c_i] - 1) < 1e-6:
# if abs(self.grid_occupied[self.grid_row * r_i + c_i] - 1) < 1e-6:
# self.grid_occupied[self.grid_row * r_i + c_i] = 1
# self.grid_occupied[self.grid_row * r_i + c_i] = 1
print
(
"module_block"
,
module_block
)
def
get_grid_cells_density
(
self
):
def
get_grid_cells_density
(
self
):
# by default grid row/col is 10/10
# by default grid row/col is 10/10
self
.
grid_width
=
float
(
self
.
width
/
self
.
grid_col
)
self
.
grid_width
=
float
(
self
.
width
/
self
.
grid_col
)
...
@@ -685,11 +677,10 @@ class PlacementCost(object):
...
@@ -685,11 +677,10 @@ class PlacementCost(object):
Compute Adjacency Matrix (Unclustered PORTs)
Compute Adjacency Matrix (Unclustered PORTs)
"""
"""
# NOTE: in pb.txt, netlist input count exceed certain threshold will be ommitted
# NOTE: in pb.txt, netlist input count exceed certain threshold will be ommitted
macro_adj
=
[
0
]
*
self
.
module_cnt
*
self
.
module_cnt
#[MACRO][macro]
assert
len
(
macro_adj
)
==
self
.
module_cnt
*
self
.
module_cnt
module_indices
=
self
.
hard_macro_indices
+
self
.
soft_macro_indices
macro_adj
=
[
0
]
*
(
self
.
hard_macro_cnt
+
self
.
soft_macro_cnt
)
*
(
self
.
hard_macro_cnt
+
self
.
soft_macro_cnt
)
#[MACRO][macro][PORT]
assert
len
(
macro_adj
)
==
(
self
.
hard_macro_cnt
+
self
.
soft_macro_cnt
)
*
(
self
.
hard_macro_cnt
+
self
.
soft_macro_cnt
)
module_indices
=
self
.
hard_macro_indices
+
self
.
soft_macro_indices
+
self
.
port_indices
for
row_idx
,
module_idx
in
enumerate
(
module_indices
):
for
row_idx
,
module_idx
in
enumerate
(
module_indices
):
# row index
# row index
...
@@ -712,7 +703,8 @@ class PlacementCost(object):
...
@@ -712,7 +703,8 @@ class PlacementCost(object):
if
h_module_name
in
curr_module
.
get_connection
():
if
h_module_name
in
curr_module
.
get_connection
():
entry
+=
curr_module
.
get_connection
()[
h_module_name
]
entry
+=
curr_module
.
get_connection
()[
h_module_name
]
macro_adj
[
row_idx
*
self
.
module_cnt
+
col_idx
]
=
entry
macro_adj
[
row_idx
*
(
self
.
hard_macro_cnt
+
self
.
soft_macro_cnt
)
+
col_idx
]
=
entry
macro_adj
[
col_idx
*
(
self
.
hard_macro_cnt
+
self
.
soft_macro_cnt
)
+
row_idx
]
=
entry
return
macro_adj
return
macro_adj
...
@@ -927,13 +919,12 @@ class PlacementCost(object):
...
@@ -927,13 +919,12 @@ class PlacementCost(object):
self
.
height
=
float
(
height
)
self
.
height
=
float
(
height
)
self
.
x
=
float
(
x
)
self
.
x
=
float
(
x
)
self
.
y
=
float
(
y
)
self
.
y
=
float
(
y
)
self
.
sink
=
{}
# [MACRO_NAME] => [PIN_NAME]
self
.
connection
=
{}
# [module_name] => edge degree
self
.
connection
=
{}
# [module_name] => edge degree
def
get_name
(
self
):
def
get_name
(
self
):
return
self
.
name
return
self
.
name
def
add_connection
(
self
,
module_name
):
def
add_connection
(
self
,
module_name
,
weight
):
# NOTE: assume PORT names does not contain slash
# NOTE: assume PORT names does not contain slash
ifPORT
=
False
ifPORT
=
False
module_name_splited
=
module_name
.
rsplit
(
'/'
,
1
)
module_name_splited
=
module_name
.
rsplit
(
'/'
,
1
)
...
@@ -942,18 +933,19 @@ class PlacementCost(object):
...
@@ -942,18 +933,19 @@ class PlacementCost(object):
if
ifPORT
:
if
ifPORT
:
# adding PORT
# adding PORT
self
.
connection
[
module_name
]
=
1
self
.
connection
[
module_name
]
=
1
*
weight
else
:
else
:
# adding soft/hard macros
# adding soft/hard macros
if
module_name_splited
[
0
]
in
self
.
connection
.
keys
():
if
module_name_splited
[
0
]
in
self
.
connection
.
keys
():
self
.
connection
[
module_name_splited
[
0
]]
+=
1
self
.
connection
[
module_name_splited
[
0
]]
+=
1
*
weight
else
:
else
:
self
.
connection
[
module_name_splited
[
0
]]
=
1
self
.
connection
[
module_name_splited
[
0
]]
=
1
*
weight
def
add_connections
(
self
,
module_names
):
def
add_connections
(
self
,
module_names
,
weight
):
# NOTE: assume PORT names does not contain slash
# NOTE: assume PORT names does not contain slash
# consider weight on soft macro pins
for
module_name
in
module_names
:
for
module_name
in
module_names
:
self
.
add_connection
(
module_name
)
self
.
add_connection
(
module_name
,
weight
)
def
set_pos
(
self
,
x
,
y
):
def
set_pos
(
self
,
x
,
y
):
self
.
x
=
x
self
.
x
=
x
...
@@ -962,9 +954,6 @@ class PlacementCost(object):
...
@@ -962,9 +954,6 @@ class PlacementCost(object):
def
get_pos
(
self
):
def
get_pos
(
self
):
return
self
.
x
,
self
.
y
return
self
.
x
,
self
.
y
def
get_sink
(
self
):
return
self
.
sink
def
get_type
(
self
):
def
get_type
(
self
):
return
"macro"
return
"macro"
...
@@ -982,7 +971,7 @@ class PlacementCost(object):
...
@@ -982,7 +971,7 @@ class PlacementCost(object):
class
SoftMacroPin
:
class
SoftMacroPin
:
def
__init__
(
self
,
name
,
def
__init__
(
self
,
name
,
x
=
0.0
,
y
=
0.0
,
macro_name
=
""
,
weight
=
0
.0
):
x
=
0.0
,
y
=
0.0
,
macro_name
=
""
,
weight
=
1
.0
):
self
.
name
=
name
self
.
name
=
name
self
.
x
=
float
(
x
)
self
.
x
=
float
(
x
)
self
.
y
=
float
(
y
)
self
.
y
=
float
(
y
)
...
@@ -1035,6 +1024,9 @@ class PlacementCost(object):
...
@@ -1035,6 +1024,9 @@ class PlacementCost(object):
def
get_sink
(
self
):
def
get_sink
(
self
):
return
self
.
sink
return
self
.
sink
def
get_weight
(
self
):
return
self
.
weight
def
get_type
(
self
):
def
get_type
(
self
):
return
"macro_pin"
return
"macro_pin"
...
@@ -1188,9 +1180,13 @@ def main():
...
@@ -1188,9 +1180,13 @@ def main():
# print(plc.set_placement_grid(5, 5))
# print(plc.set_placement_grid(5, 5))
print
(
plc
.
get_grid_cells_density
())
print
(
plc
.
get_grid_cells_density
())
print
(
plc
.
get_density_cost
())
print
(
plc
.
get_density_cost
())
print
(
plc
.
display_canvas
())
print
(
len
(
plc
.
get_macro_and_clustered_port_adjacency
()))
temppins
=
plc
.
soft_macros_to_inpins
[
plc
.
modules_w_pins
[
plc
.
soft_macro_indices
[
0
]]
.
get_name
()]
print
(
plc
.
modules_w_pins
[
plc
.
mod_name_to_indices
[
temppins
[
17
]]]
.
get_name
())
print
(
plc
.
modules_w_pins
[
plc
.
mod_name_to_indices
[
temppins
[
17
]]]
.
get_sink
())
print
(
plc
.
modules_w_pins
[
plc
.
soft_macro_indices
[
54
]]
.
get_name
())
temppins2
=
plc
.
soft_macros_to_inpins
[
plc
.
modules_w_pins
[
plc
.
soft_macro_indices
[
54
]]
.
get_name
()]
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
main
()
main
()
CodeElements/Plc_client/plc_client_os_test.py
View file @
05aa7fe6
import
unittest
from
absl
import
flags
import
os
from
absl
import
app
from
Plc_client
import
plc_client_os
as
plc_client_os
from
Plc_client
import
plc_client_os
as
plc_client_os
from
Plc_client
import
plc_client
as
plc_client
from
Plc_client
import
plc_client
as
plc_client
import
numpy
as
np
import
sys
np
.
set_printoptions
(
threshold
=
sys
.
maxsize
)
FLAGS
=
flags
.
FLAGS
class
CircuitDataBaseTest
():
class
CircuitDataBaseTest
(
unittest
.
TestCase
):
# NETLIST_PATH = "./Plc_client/test/ariane_hard2soft/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/ariane_hard2soft/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/ariane_soft2hard/netlist.pb.txt"
# 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/ariane_port2soft/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/sample_clustered_nomacro/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/ariane/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/ariane133/netlist.pb.txt"
# NETLIST_PATH = "./Plc_client/test/ariane133/netlist.pb.txt"
def
test_proxy_cost
(
self
):
def
test_proxy_cost
(
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
)
print
(
self
.
plc
.
get_canvas_width_height
())
# Open-sourced Implementation
# 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
)
# Google's Ariane
# Google's Ariane
CANVAS_
HEIGHT
=
CANVAS_
WIDTH
=
356.592
CANVAS_
WIDTH
=
CANVAS_
HEIGHT
=
356.640
GRID_COL
=
35
GRID_COL
=
35
GRID_ROW
=
33
GRID_ROW
=
33
# Ariane133
# Ariane133
CANVAS_HEIGHT
=
# CANVAS_WIDTH = 1599.99
CANVAS_WIDTH
=
# CANVAS_HEIGHT = 1598.8
GRID_COL
=
35
# GRID_COL = 50
GRID_ROW
=
33
# GRID_ROW = 50
# Sample clustered
CANVAS_WIDTH
=
80
CANVAS_HEIGHT
=
80
GRID_COL
=
5
GRID_ROW
=
5
print
(
self
.
plc
.
set_canvas_size
(
CANVAS_WIDTH
,
CANVAS_HEIGHT
))
self
.
plc
.
set_canvas_size
(
CANVAS_WIDTH
,
CANVAS_HEIGHT
)
print
(
self
.
plc
.
set_placement_grid
(
GRID_COL
,
GRID_ROW
))
self
.
plc
.
set_placement_grid
(
GRID_COL
,
GRID_ROW
)
self
.
plc_os
.
set_canvas_size
(
CANVAS_WIDTH
,
CANVAS_HEIGHT
)
self
.
plc_os
.
set_placement_grid
(
GRID_COL
,
GRID_ROW
)
assert
int
(
self
.
plc_os
.
get_wirelength
())
==
int
(
self
.
plc
.
get_wirelength
())
assert
int
(
self
.
plc_os
.
get_wirelength
())
==
int
(
self
.
plc
.
get_wirelength
())
assert
int
(
sum
(
self
.
plc_os
.
get_grid_cells_density
()))
==
int
(
sum
(
self
.
plc
.
get_grid_cells_density
()))
assert
int
(
self
.
plc_os
.
get_density_cost
())
==
int
(
self
.
plc
.
get_density_cost
())
assert
int
(
self
.
plc_os
.
get_density_cost
())
==
int
(
self
.
plc
.
get_density_cost
())
def
test_metadata
(
self
):
def
test_metadata
(
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
# 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
)
assert
self
.
plc_os
.
get_block_name
()
==
self
.
plc_os
.
get_block_name
()
assert
self
.
plc_os
.
get_project_name
()
==
self
.
plc_os
.
get_project_name
()
assert
int
(
self
.
plc_os
.
get_area
())
==
int
(
self
.
plc
.
get_area
())
assert
int
(
self
.
plc_os
.
get_area
())
==
int
(
self
.
plc_os
.
get_area
())
self
.
plc
.
set_routes_per_micron
(
1.0
,
2.0
)
self
.
plc
.
set_routes_per_micron
(
1.0
,
2.0
)
self
.
plc_os
.
set_routes_per_micron
(
1.0
,
2.0
)
self
.
plc_os
.
set_routes_per_micron
(
1.0
,
2.0
)
...
@@ -67,7 +78,7 @@ class CircuitDataBaseTest(unittest.TestCase):
...
@@ -67,7 +78,7 @@ class CircuitDataBaseTest(unittest.TestCase):
self
.
plc_os
.
set_macro_routing_allocation
(
3.0
,
4.0
)
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
()
assert
self
.
plc
.
get_macro_routing_allocation
()
==
self
.
plc_os
.
get_macro_routing_allocation
()
assert
s
elf
.
plc
.
get_macro_adjacency
()
==
self
.
plc_os
.
get_macro_adjacency
(
)
assert
s
um
(
self
.
plc
.
get_macro_adjacency
())
==
sum
(
self
.
plc_os
.
get_macro_adjacency
()
)
def
test_miscellaneous
(
self
):
def
test_miscellaneous
(
self
):
# Google's Binary Executable
# Google's Binary Executable
...
@@ -77,6 +88,11 @@ class CircuitDataBaseTest(unittest.TestCase):
...
@@ -77,6 +88,11 @@ class CircuitDataBaseTest(unittest.TestCase):
macro_macro_x_spacing
=
50
,
macro_macro_x_spacing
=
50
,
macro_macro_y_spacing
=
50
)
macro_macro_y_spacing
=
50
)
def
main
(
argv
):
temp
=
CircuitDataBaseTest
()
temp
.
test_proxy_cost
()
temp
.
test_metadata
()
temp
.
test_miscellaneous
()
if
__name__
==
'__main__'
:
if
__name__
==
"__main__"
:
unittest
.
main
()
app
.
run
(
main
)
\ No newline at end of file
\ No newline at end of file
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