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
e30b3206
Commit
e30b3206
authored
Nov 08, 2022
by
Dinple
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
bf6adde8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
307 additions
and
2 deletions
+307
-2
CodeElements/EvalCT/eval_ct.py
+1
-1
CodeElements/Plc_client/plc_client_os.py
+3
-1
CodeElements/StatTest/proxy_corr_test.py
+8
-0
CodeElements/StatTest/stat_test.py
+220
-0
CodeElements/StatTest/util.py
+75
-0
No files found.
CodeElements/EvalCT/eval_ct.py
View file @
e30b3206
...
...
@@ -29,7 +29,7 @@ from tf_agents.system import system_multiprocessing as multiprocessing
Example
At ./MacroPlacement/CodeElement/EvalCT, run the following command:
$ python3 -m eval_ct --netlist ./test/ariane/netlist.pb.txt
\
$
cd EvalCT &&
python3 -m eval_ct --netlist ./test/ariane/netlist.pb.txt
\
--plc ./test/ariane/initial.plc
\
--rundir run_00
\
--ckptID policy_checkpoint_0000103984
...
...
CodeElements/Plc_client/plc_client_os.py
View file @
e30b3206
...
...
@@ -144,6 +144,7 @@ class PlacementCost(object):
"""
private function: Protobuf Netlist Parser
"""
print
(
"#[INFO] Reading from "
+
self
.
netlist_file
)
with
open
(
self
.
netlist_file
)
as
fp
:
line
=
fp
.
readline
()
node_cnt
=
0
...
...
@@ -596,6 +597,7 @@ class PlacementCost(object):
# set meta information
if
ifReadComment
:
print
(
"[INFO] Retrieving Meta information from .plc comments"
)
self
.
set_canvas_size
(
info_dict
[
'width'
],
info_dict
[
'height'
])
self
.
set_placement_grid
(
info_dict
[
'columns'
],
info_dict
[
'rows'
])
self
.
set_block_name
(
info_dict
[
'block'
])
...
...
@@ -2407,7 +2409,7 @@ class PlacementCost(object):
# compute force in x and y direction
if
hypo_dist
<=
1e-5
:
return
1e5
,
1e5
return
math
.
sqrt
(
repel_factor
),
math
.
sqrt
(
repel_factor
)
else
:
f_x
=
repel_factor
*
x_dist
/
hypo_dist
f_y
=
repel_factor
*
y_dist
/
hypo_dist
...
...
CodeElements/StatTest/proxy_corr_test.py
0 → 100644
View file @
e30b3206
import
re
import
os
,
sys
import
math
import
numpy
as
np
import
logging
import
matplotlib.pyplot
as
plt
import
pandas
as
pd
\ No newline at end of file
CodeElements/StatTest/stat_test.py
0 → 100644
View file @
e30b3206
import
re
import
os
,
sys
import
math
import
numpy
as
np
import
logging
import
matplotlib.pyplot
as
plt
import
pandas
as
pd
from
StatTest
import
util
# disable scientific notation
np
.
set_printoptions
(
suppress
=
True
)
# print full array
np
.
set_printoptions
(
threshold
=
sys
.
maxsize
)
"""Statistical Test docstrings.
* Robustness
* Use EvalCT for fixed policy rollout on the same training
set but different initialization.
* Stability
* Macro Movement Range
* Additional Note
* Loading weight back for training
"""
######################## META INFO ########################
# Directory that stores all plc file (must come from the same netlist)
PLC_DIR
=
"StatTest/test/flow2_68_1.3_ct"
PLC_PATH_COLLECTION
=
[]
assert
os
.
path
.
isdir
(
PLC_DIR
)
# Top X% of largest movement range
TOP_X
=
1
# List to store every plc coordinate
PLC_COORD
=
[]
def
init_method
(
plc_dir
):
"""
Scan through every .plc file
"""
for
__
,
__
,
files
in
os
.
walk
(
plc_dir
):
for
plc_file
in
files
:
if
plc_file
.
endswith
((
".plc"
)):
plc_pth
=
os
.
path
.
join
(
plc_dir
,
plc_file
)
# plc path
PLC_PATH_COLLECTION
.
append
(
plc_pth
)
print
(
"#[INFO] Reading plc file {}"
.
format
(
plc_pth
))
# store in numpy array for ease of computation
temp_coord
=
np
.
empty
((
1
,
2
),
float
)
for
cnt
,
line
in
enumerate
(
open
(
plc_pth
,
'r'
)):
line_item
=
re
.
findall
(
r'[0-9A-Za-z\.\-]+'
,
line
)
# skip empty lines
if
len
(
line_item
)
==
0
:
continue
if
all
(
re
.
match
(
r'[0-9FNEWS\.\-]+'
,
it
)
for
it
in
line_item
)
\
and
len
(
line_item
)
==
5
:
# extract pos
temp_coord
=
np
.
append
(
temp_coord
,
np
.
array
([[
float
(
line_item
[
1
]),
float
(
line_item
[
2
])]]),
axis
=
0
)
# remove header row
temp_coord
=
temp_coord
[
1
:,
:]
# make sure every plc is aligned
if
PLC_COORD
:
assert
PLC_COORD
[
-
1
]
.
shape
==
temp_coord
.
shape
PLC_COORD
.
append
(
temp_coord
)
# print(temp_coord)
del
temp_coord
def
get_abs_dist
():
# store all pair-wise distance
abs_dist_plc
=
np
.
empty
((
PLC_COORD
[
-
1
]
.
shape
[
0
],
1
),
float
)
# pair-wise distance of all plc files
for
i
in
range
(
len
(
PLC_COORD
)):
for
j
in
range
(
len
(
PLC_COORD
)):
if
i
==
j
:
continue
# find x/y position diff
diff_coord
=
PLC_COORD
[
i
]
-
PLC_COORD
[
j
]
# x_diff^2, y_diff^2
diff_coord
=
np
.
power
(
diff_coord
,
2
)
# sqrt(x_diff^2 + y_diff^2)
abs_dist_coord
=
np
.
sqrt
(
diff_coord
[:,
0
]
+
diff_coord
[:,
1
])
abs_dist_plc
=
np
.
append
(
abs_dist_plc
,
abs_dist_coord
.
reshape
((
-
1
,
1
)),
axis
=
1
)
# remove header col
return
abs_dist_plc
[:,
1
:]
def
main
():
init_method
(
PLC_DIR
)
abs_dist_plc
=
get_abs_dist
()
TOP_N
=
int
(
math
.
floor
(
abs_dist_plc
.
shape
[
0
]
*
(
TOP_X
/
100.0
)))
print
(
"[INFO] Using TOP {}
%
Largest Macro Movement --- {} Macros in total."
.
format
(
TOP_X
,
TOP_N
))
############ MACRO placement range maximum distance + visual ###############
# across all the plc diff, the max distance [row wise]
max_dist
=
np
.
amax
(
abs_dist_plc
,
axis
=
1
)
# top-n max distance
topn_max_dist_idx
=
np
.
argpartition
(
max_dist
,
-
TOP_N
)[
-
TOP_N
:]
topn_max_dist_val
=
np
.
take
(
max_dist
,
topn_max_dist_idx
)
x
=
range
(
topn_max_dist_val
.
shape
[
0
])
y
=
topn_max_dist_val
n
=
topn_max_dist_idx
fig
,
ax
=
plt
.
subplots
()
ax
.
set_title
(
"Top {}
%
Maximum Placement Range"
.
format
(
TOP_X
))
ax
.
scatter
(
x
,
y
,
c
=
'b'
)
ax
.
set_xlabel
(
"module index"
)
ax
.
set_ylabel
(
"distance"
)
for
i
,
txt
in
enumerate
(
n
):
ax
.
annotate
(
txt
,
(
x
[
i
],
y
[
i
]))
plt
.
show
()
######################## MACRO placement range box plot visual #############
abs_dist_plc_df
=
pd
.
DataFrame
(
data
=
abs_dist_plc
)
topn_max_dist_df
=
abs_dist_plc_df
.
iloc
[
topn_max_dist_idx
,
:]
topn_max_dist_df
.
T
.
boxplot
()
plt
.
title
(
"Top {}
%
Placement Range"
.
format
(
TOP_X
))
plt
.
xlabel
(
"module index"
)
plt
.
ylabel
(
"distance"
)
plt
.
show
()
######################## Density Heatmap ########################
util
.
extract_density_map
(
os
.
path
.
join
(
PLC_DIR
,
"netlist.pb.txt"
),
PLC_PATH_COLLECTION
[
0
],
ifshow
=
True
)
######################## Congestion Heatmap #####################
util
.
extract_congestion_map
(
os
.
path
.
join
(
PLC_DIR
,
"netlist.pb.txt"
),
PLC_PATH_COLLECTION
[
0
],
marh
=
7.143
,
marv
=
8.339
,
rpmh
=
11.285
,
rpmv
=
12.605
,
congestion_smooth_range
=
2
,
ifshow
=
True
)
######################## L1 Norm & SSIM #####################
# pair-wise distance of all plc files
DENS_SMI
=
[]
DENS_L1
=
[]
VCONG_SMI
=
[]
VCONG_L1
=
[]
HCONG_SMI
=
[]
HCONG_L1
=
[]
for
i
in
range
(
len
(
PLC_PATH_COLLECTION
)):
for
j
in
range
(
len
(
PLC_PATH_COLLECTION
)):
if
i
==
j
:
continue
print
(
"####### Heat Map Comparison between {} and {} #######"
.
format
(
os
.
path
.
basename
(
PLC_PATH_COLLECTION
[
i
])
,
os
.
path
.
basename
(
PLC_PATH_COLLECTION
[
j
])))
dens_i
=
util
.
extract_density_map
(
os
.
path
.
join
(
PLC_DIR
,
"netlist.pb.txt"
),
PLC_PATH_COLLECTION
[
i
],
ifshow
=
False
)
dens_j
=
util
.
extract_density_map
(
os
.
path
.
join
(
PLC_DIR
,
"netlist.pb.txt"
),
PLC_PATH_COLLECTION
[
j
],
ifshow
=
False
)
print
(
"#[INFO] Density map SMI: {}"
.
format
(
util
.
SSIM
(
dens_i
,
dens_j
)))
print
(
"#[INFO] Density map L1 Dist: {}"
.
format
(
util
.
l1_norm
(
dens_i
,
dens_j
)))
DENS_SMI
.
append
(
util
.
SSIM
(
dens_i
,
dens_j
))
DENS_L1
.
append
(
util
.
l1_norm
(
dens_i
,
dens_j
))
vcong_i
,
hcong_i
=
util
.
extract_congestion_map
(
os
.
path
.
join
(
PLC_DIR
,
"netlist.pb.txt"
),
PLC_PATH_COLLECTION
[
i
],
marh
=
7.143
,
marv
=
8.339
,
rpmh
=
11.285
,
rpmv
=
12.605
,
congestion_smooth_range
=
2
,
ifshow
=
False
)
vcong_j
,
hcong_j
=
util
.
extract_congestion_map
(
os
.
path
.
join
(
PLC_DIR
,
"netlist.pb.txt"
),
PLC_PATH_COLLECTION
[
j
],
marh
=
7.143
,
marv
=
8.339
,
rpmh
=
11.285
,
rpmv
=
12.605
,
congestion_smooth_range
=
2
,
ifshow
=
False
)
print
(
"#[INFO] V Congestion map SMI: {}"
.
format
(
util
.
SSIM
(
vcong_i
,
vcong_j
)))
print
(
"#[INFO] V Congestion map L1 Dist: {}"
.
format
(
util
.
l1_norm
(
vcong_i
,
vcong_j
)))
print
(
"#[INFO] H Congestion map SMI: {}"
.
format
(
util
.
SSIM
(
hcong_i
,
hcong_j
)))
print
(
"#[INFO] H Congestion map L1 Dist: {}"
.
format
(
util
.
l1_norm
(
hcong_i
,
hcong_j
)))
VCONG_SMI
.
append
(
util
.
SSIM
(
vcong_i
,
vcong_j
))
VCONG_L1
.
append
(
util
.
l1_norm
(
vcong_i
,
vcong_j
))
HCONG_SMI
.
append
(
util
.
SSIM
(
hcong_i
,
hcong_j
))
HCONG_L1
.
append
(
util
.
l1_norm
(
hcong_i
,
hcong_j
))
print
(
"DENS_SMI Range ({} ~ {})"
.
format
(
min
(
DENS_SMI
),
max
(
DENS_SMI
)))
print
(
"DENS_L1 Range ({} ~ {})"
.
format
(
min
(
DENS_L1
),
max
(
DENS_L1
)))
print
(
"VCONG_SMI Range ({} ~ {})"
.
format
(
min
(
VCONG_SMI
),
max
(
VCONG_SMI
)))
print
(
"VCONG_L1 Range ({} ~ {})"
.
format
(
min
(
VCONG_L1
),
max
(
VCONG_L1
)))
print
(
"HCONG_SMI Range ({} ~ {})"
.
format
(
min
(
HCONG_SMI
),
max
(
HCONG_SMI
)))
print
(
"HCONG_L1 Range ({} ~ {})"
.
format
(
min
(
HCONG_L1
),
max
(
HCONG_L1
)))
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
CodeElements/StatTest/util.py
0 → 100644
View file @
e30b3206
import
os
,
sys
import
pandas
as
pd
import
numpy
as
np
import
seaborn
as
sns
from
Plc_client
import
plc_client_os
from
Plc_client
import
placement_util_os
as
placement_util
import
matplotlib.pyplot
as
plt
from
skimage.metrics
import
structural_similarity
def
heatmap
(
arr
,
title
,
show
=
True
):
"""
util function for generating heat map from numpy arrays
"""
sns
.
set
()
ax
=
sns
.
heatmap
(
arr
,
vmin
=
0
,
vmax
=
1
,
cmap
=
"YlGnBu"
)
ax
.
set_title
(
title
)
ax
.
set_xlabel
(
"Columns"
)
ax
.
set_ylabel
(
"Rows"
)
if
show
:
plt
.
show
()
else
:
plt
.
clf
()
def
extract_density_map
(
netlist_path
,
plc_path
,
ifshow
=
True
):
"""
wrapper function for extracting density map
"""
plc_util_os
=
placement_util
.
create_placement_cost
(
plc_client
=
plc_client_os
,
netlist_file
=
netlist_path
,
init_placement
=
plc_path
)
grid_cols
,
grid_rows
=
plc_util_os
.
get_grid_num_columns_rows
()
dens_map
=
np
.
array
(
plc_util_os
.
get_grid_cells_density
())
.
reshape
(
grid_rows
,
grid_cols
)
heatmap
(
dens_map
,
"Placement Density Heatmap"
,
ifshow
)
return
dens_map
def
extract_congestion_map
(
netlist_path
,
plc_path
,
rpmh
,
rpmv
,
marh
,
marv
,
congestion_smooth_range
,
ifshow
=
True
):
"""
wrapper function for extracting congestion map
"""
plc_util_os
=
placement_util
.
create_placement_cost
(
plc_client
=
plc_client_os
,
netlist_file
=
netlist_path
,
init_placement
=
plc_path
)
plc_util_os
.
set_routes_per_micron
(
rpmh
,
rpmv
)
plc_util_os
.
set_macro_routing_allocation
(
marh
,
marv
)
plc_util_os
.
set_congestion_smooth_range
(
congestion_smooth_range
)
grid_cols
,
grid_rows
=
plc_util_os
.
get_grid_num_columns_rows
()
# vertical routing congestion map
vcong_map
=
np
.
array
(
plc_util_os
.
get_vertical_routing_congestion
())
.
reshape
(
grid_rows
,
grid_cols
)
heatmap
(
vcong_map
,
"Placement Vertical Congestion Heatmap"
,
ifshow
)
# horizontal routing congestion map
hcong_map
=
np
.
array
(
plc_util_os
.
get_horizontal_routing_congestion
())
.
reshape
(
grid_rows
,
grid_cols
)
heatmap
(
hcong_map
,
"Placement Horizontal Congestion Heatmap"
,
ifshow
)
return
vcong_map
,
hcong_map
def
SSIM
(
a
,
b
):
return
structural_similarity
(
a
,
b
)
def
l1_norm
(
a
,
b
):
return
np
.
linalg
.
norm
(
normalize
(
a
)
-
normalize
(
b
),
ord
=
1
)
def
normalize
(
a
):
return
(
a
-
np
.
min
(
a
))
/
(
np
.
max
(
a
)
-
np
.
min
(
a
))
\ 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