Skip to content

Commit e8c49f8

Browse files
committed
Making benchmark pseudo dynamic
1 parent 126d234 commit e8c49f8

1 file changed

Lines changed: 59 additions & 32 deletions

File tree

examples/baremetal/make.py

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
import argparse
66
import subprocess
77
import os
8+
import sys
89
from pathlib import Path
910
from jinja2 import Environment, FileSystemLoader
11+
from logikbench import *
1012

1113
if __name__ == "__main__":
12-
1314
parser = argparse.ArgumentParser(description="""\
1415
1516
LogikBench bare metal usage example
@@ -19,18 +20,22 @@
1920
make.py -tool yosys -group epfl
2021
""", formatter_class=argparse.RawDescriptionHelpFormatter)
2122

22-
23-
parser.add_argument("-tool",
24-
choices=['yosys', 'vivado'],
25-
required=True,
26-
help="Synthesis tool")
2723
parser.add_argument("-group",
28-
nargs='+',
24+
nargs='+',
2925
required=True,
3026
help="Benchmark group")
3127
parser.add_argument("-name",
3228
nargs='+',
3329
help="Benchmark name")
30+
parser.add_argument("-tool",
31+
choices=['yosys', 'vivado'],
32+
required=True,
33+
help="Benchmark tool")
34+
parser.add_argument("-target",
35+
choices=['ice40'],
36+
required=True,
37+
help="Benchmark target")
38+
3439

3540
args = parser.parse_args()
3641

@@ -42,39 +47,61 @@
4247
env = Environment(loader=FileSystemLoader('.'))
4348
template = env.get_template(f'{args.tool}_template.j2')
4449

45-
# generic runtime script
46-
script = "run.tcl"
47-
4850
# iterate over all groups
4951
for group in args.group:
5052
group_path = rootdir / "logikbench" / group
5153
if args.name:
52-
bench_list =args.name
54+
bench_list = args.name
5355
else:
54-
bench_list = [p.name for p in group_path.iterdir() if p.is_dir()]
56+
bench_list = [p.name for p in group_path.iterdir() if p.is_dir()]
57+
5558
# iterate over all benchmarks in group
5659
for name in bench_list:
60+
if args.tool == 'yosys':
61+
script = f"{name}.ys" # yosys corner case
62+
else:
63+
script = f"{name}.tcl"
5764

58-
os.makedirs(f"build/{group}/{name}", exist_ok=True)
59-
os.chdir(f"build/{group}/{name}")
65+
# get top module
66+
# TODO: find module by string?
67+
# TODO: generalize
68+
mod = sys.modules["logikbench.basic.binv.binv"]
69+
cls = getattr(mod, "Binv")
70+
d = cls()
71+
print(d.get_topmodule(fileset='rtl'))
6072

61-
# create tool script
62-
output = template.render(context)
63-
with open(script, 'w') as f:
64-
f.write(output)
73+
mod = importlib.import_module("logikbench.basic.binv.binv")
74+
cls = getattr(mod, "Binv")
75+
d = cls()
76+
print(d.get_topmodule(fileset='rtl'))
6577

66-
# run tool
78+
# create run dir
79+
os.makedirs(f"build/{group}/{name}", exist_ok=True)
80+
os.chdir(f"build/{group}/{name}")
81+
filename = group_path / name / "rtl" / f"{name}.v"
82+
83+
# create tool script
84+
context = {
85+
'name': name,
86+
'top': topmodule,
87+
'filename': filename,
88+
'target': args.target,
89+
}
90+
output = template.render(context)
91+
with open(script, 'w') as f:
92+
f.write(output)
93+
94+
# run benchmark
6795
try:
68-
result = subprocess.run(
69-
["yosys", script],
70-
check=True,
71-
capture_output=True,
72-
text=True)
73-
print("Yosys output:")
74-
print(result.stdout)
75-
76-
except subprocess.CalledProcessError as e:
77-
print("Yosys failed with error:")
78-
print(e.stderr)
79-
# go back home
80-
os.chdir(scriptdir)
96+
print(f"Running {name} benchmark in group '{group}'. Lofile: build/{group}/{name}/{name}.log")
97+
with open(f'{name}.log', "w") as log:
98+
result = subprocess.run([args.tool, script],
99+
stdout=log,
100+
stderr=subprocess.STDOUT,
101+
check=True)
102+
103+
except subprocess.CalledProcessError as e:
104+
print(f"Error...see logfile!!")
105+
106+
# go back home
107+
os.chdir(scriptdir)

0 commit comments

Comments
 (0)