-
Notifications
You must be signed in to change notification settings - Fork 33
/
benchmark.py
executable file
·152 lines (120 loc) · 4.09 KB
/
benchmark.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
145
146
147
148
149
150
151
152
#!/usr/bin/env python3
# Adapted from OpenLane by Donn.
#
# Copyright 2020 Efabless Corporation
# Copyright 2021 The American University in Cairo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import yaml
import glob
import queue
import threading
import subprocess
import pathlib
import click
class Design(object):
def __init__(self, count, width, variant):
self.count = count
self.width = width
self.variant = variant
@staticmethod
def from_yaml_object(yaml_object):
return Design(
yaml_object["count"], yaml_object["width"], yaml_object["variant"]
)
@staticmethod
def get_all():
gha_string = open("./.github/workflows/main.yml").read()
gha = yaml.safe_load(gha_string)
jobs = gha["jobs"]
test_flow = jobs["test_flow"]
designs = test_flow["strategy"]["matrix"]["include"]
return [Design.from_yaml_object(design) for design in designs]
@property
def size(self):
return f"{self.count}x{self.width}"
@property
def tag(self):
return f"{self.size}_{self.variant}"
def get_density(self, build_folder):
density_file = glob.glob(os.path.join(build_folder, self.tag, "*.density.txt"))[
0
]
density = float(open(density_file).read())
return density
@click.group()
def start():
pass
@click.command("run_designs")
@click.option(
"-w",
"--worker-count",
required=not os.getenv("WORKERS"),
default=os.getenv("WORKERS"),
)
def run_designs(worker_count):
worker_count = int(worker_count)
designs = Design.get_all()
q = queue.Queue()
for design in designs:
q.put(design)
def run_design():
while not q.empty():
design = q.get(timeout=3)
build_folder = os.path.join("./benchmark_build", design.tag)
print(f"Started {design.tag}...")
pathlib.Path(build_folder).mkdir(parents=True, exist_ok=True)
stdout = open(os.path.join(build_folder, "stdout.log"), "w")
stderr = open(os.path.join(build_folder, "stderr.log"), "w")
try:
subprocess.check_call(
[
"python3",
"./dffram.py",
"--variant",
design.variant,
"--size",
f"{design.count}x{design.width}",
"--output-dir",
"./benchmark_build",
],
stdout=stdout,
stderr=stderr,
)
print(
f"Finished {design.tag}: Density {design.get_density('./benchmark_build')}."
)
except Exception:
print(f"Failed {design.tag}.")
stdout.close()
stderr.close()
worker_threads = []
for i in range(worker_count):
worker_threads.append(threading.Thread(target=run_design))
worker_threads[i].start()
for i in range(worker_count):
while worker_threads[i].is_alive():
worker_threads[i].join(100)
print(f"Exiting thread {i}...")
start.add_command(run_designs)
@click.command("compile_densities")
def compile_densities():
designs = Design.get_all()
with open("./benchmark_build/densities.csv", "w") as f:
print("tag,density", file=f)
for design in designs:
print(f"{design.tag},{design.get_density('./benchmark_build')}", file=f)
start.add_command(compile_densities)
if __name__ == "__main__":
start()