-
Notifications
You must be signed in to change notification settings - Fork 10
/
compute-score.py
144 lines (129 loc) · 4.68 KB
/
compute-score.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright (C) 2023-2024, Advanced Micro Devices, Inc. All rights reserved.
#
# Author: Eddie Hung, AMD
#
# SPDX-License-Identifier: MIT
#
import sys
import re
import argparse
from scoring_formula.scoring_formula import score_benchmark_results
def route_result(checkfile):
"""
Read the result of CheckPhysNetlist.
Args:
checkfile: the name of the file containing the output of
CheckPhysNetlist
Returns:
True if the checkfile has the result 'PASS' False otherwise
"""
try:
with open(checkfile) as fp:
return fp.readline().rstrip() == 'PASS'
except FileNotFoundError:
return False
def runtime_results(physlogfile):
"""
Read the runtime of the router being scored.
Args:
physlogfile: the name of the Physical Netlist log file
Returns:
the wall clock and user-cpu runtimes in seconds as floating
point numbers if available.
Floating point infinity otherwise.
"""
reWallClockSeconds = re.compile(r'Wall-clock time \(sec\): ([0-9.]+)')
reUserCpuSeconds = re.compile(r'User-CPU time \(sec\): ([0-9.]+)')
result = [float('inf')] * 2
try:
with open(physlogfile) as fp:
last2,last1 = fp.readlines()[-2:]
m2 = reWallClockSeconds.match(last2)
if m2:
result[0] = float(m2.group(1))
m1 = reUserCpuSeconds.match(last1)
if m1:
result[1] = float(m1.group(1))
except FileNotFoundError:
pass
return result
def wirelength_result(wirelengthfile):
"""
Read the Critical-Path Wirelength of the routed Physical Netlist.
Args:
wirelengthfile: the name of the wirelength file generated by running
wa.py on the final Physical Netlist
Returns:
The Critical-Path Wirelength as a floating point number if available.
Floating point infinity otherwise.
"""
try:
with open(wirelengthfile) as fp:
lines = fp.readlines()
for l in lines:
if 'Wirelength: ' in l:
return float(l.split()[-1])
except FileNotFoundError:
pass
return float('inf')
def print_results_table(results):
"""
Given a list of results print a nice table.
Args:
results: a list of tuples. Each tuple is assumed to be the same length.
Items in each tuple are placed in individual columns
"""
column_widths = [0]*len(results[0])
for row in results:
for index, item in enumerate(row):
if len(str(item)) > column_widths[index]:
column_widths[index] = len(str(item))
sep = '|'
header_format_str = sep
body_format_str = sep
horiz = '+'
for index, width in enumerate(column_widths):
header_format_str += ' %-' + str(width) + 's ' + sep
horiz += '-' + '-'*width + '-' + '+'
if index == 0:
body_format_str += ' %-' + str(width) + 's ' + sep
else:
body_format_str += ' %' + str(width) + 's ' + sep
print(horiz)
print(header_format_str % results[0])
print(horiz)
for row in results[1:]:
print(body_format_str % row)
print(horiz)
def main():
"""
Main entry point to compute-score. This program reads the `.check`,
`.phys.log` and `.wirelength` files associated with each of the benchmarks
passed on the commandline. Based on the results collected from these files
a score for each benchmark is computed according the the contest scoring
rules. Finally a table showing each benchmark, the scoring data and the
final score is printed.
"""
parser = argparse.ArgumentParser(
prog="compute-score",
description="Compute the score achieved on a set of benchmarks by a router",
)
parser.add_argument('benchmarks',
metavar="<benchmark name>_<router name>",
type=str,
nargs='+',
help="List of data file prefixes")
args = parser.parse_args()
rt_format = '{:.2f}'
cpw_format = '{:.0f}'
score_format = '{:.2f}'
results = [('Benchmark', 'Pass', 'User CPU (sec)', 'Wall Clock (sec)', 'Critical-Path Wirelength', 'Score')]
for benchmark in args.benchmarks:
check = route_result(benchmark + '.check')
(walltime,usertime) = runtime_results(benchmark + '.phys.log')
cpw = wirelength_result(benchmark + '.wirelength')
score = score_benchmark_results(check, walltime, cpw)
results.append((benchmark,check,rt_format.format(usertime),rt_format.format(walltime),cpw_format.format(cpw),score_format.format(score)))
print_results_table(results)
if __name__ == '__main__':
main()