|
5 | 5 | import argparse |
6 | 6 | import subprocess |
7 | 7 | import os |
| 8 | +import sys |
8 | 9 | from pathlib import Path |
9 | 10 | from jinja2 import Environment, FileSystemLoader |
| 11 | +from logikbench import * |
10 | 12 |
|
11 | 13 | if __name__ == "__main__": |
12 | | - |
13 | 14 | parser = argparse.ArgumentParser(description="""\ |
14 | 15 |
|
15 | 16 | LogikBench bare metal usage example |
|
19 | 20 | make.py -tool yosys -group epfl |
20 | 21 | """, formatter_class=argparse.RawDescriptionHelpFormatter) |
21 | 22 |
|
22 | | - |
23 | | - parser.add_argument("-tool", |
24 | | - choices=['yosys', 'vivado'], |
25 | | - required=True, |
26 | | - help="Synthesis tool") |
27 | 23 | parser.add_argument("-group", |
28 | | - nargs='+', |
| 24 | + nargs='+', |
29 | 25 | required=True, |
30 | 26 | help="Benchmark group") |
31 | 27 | parser.add_argument("-name", |
32 | 28 | nargs='+', |
33 | 29 | 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 | + |
34 | 39 |
|
35 | 40 | args = parser.parse_args() |
36 | 41 |
|
|
42 | 47 | env = Environment(loader=FileSystemLoader('.')) |
43 | 48 | template = env.get_template(f'{args.tool}_template.j2') |
44 | 49 |
|
45 | | - # generic runtime script |
46 | | - script = "run.tcl" |
47 | | - |
48 | 50 | # iterate over all groups |
49 | 51 | for group in args.group: |
50 | 52 | group_path = rootdir / "logikbench" / group |
51 | 53 | if args.name: |
52 | | - bench_list =args.name |
| 54 | + bench_list = args.name |
53 | 55 | 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 | + |
55 | 58 | # iterate over all benchmarks in group |
56 | 59 | 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" |
57 | 64 |
|
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')) |
60 | 72 |
|
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')) |
65 | 77 |
|
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 |
67 | 95 | 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