-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_examples.py
More file actions
100 lines (71 loc) · 3.05 KB
/
build_examples.py
File metadata and controls
100 lines (71 loc) · 3.05 KB
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
from pathlib import Path
from argparse import ArgumentParser
import subprocess
import sys
from typing import List
class Batch:
def __init__(self):
self.proc_args = []
def add(self, command, file):
self.proc_args.extend([command, file])
def run(self):
return subprocess.run(["fennel", "felvine.fnl", *self.proc_args])
class Individual:
def __init__(self):
self.proc_args_list = []
def add(self, command, file):
self.proc_args_list.append([command, file])
def run(self):
failure_cases = []
for proc_args in self.proc_args_list:
try:
subprocess.run(["fennel", "felvine.fnl", *proc_args]).check_returncode()
except subprocess.CalledProcessError:
failure_cases.append(proc_args)
if len(failure_cases) == 0: return
proportion_failed = len(failure_cases) / len(self.proc_args_list)
print(f"Failed {len(failure_cases)}/{len(self.proc_args_list)} ({proportion_failed*100:.2f}%) of cases:", file=sys.stderr)
for case in failure_cases:
print(f"\t{case}", file=sys.stderr)
sys.exit(1)
def validate(files: List[Path], optimize=False):
failure_cases = []
for file in files:
try:
if optimize:
result = subprocess.run(["spirv-opt", "--target-env=vulkan1.3", "--scalar-block-layout", str(file), "-O", "-o", str(file.with_suffix(".opt.spv"))])
else:
result = subprocess.run(["spirv-val", "--target-env", "vulkan1.3", "--scalar-block-layout", str(file)])
result.check_returncode()
except subprocess.CalledProcessError:
failure_cases.append(file)
if len(failure_cases) == 0: return
proportion_failed = len(failure_cases) / len(files)
print(f"Failed {len(failure_cases)}/{len(files)} ({proportion_failed*100:.2f}%) of cases:", file=sys.stderr)
for case in failure_cases:
print(f"\t{case}", file=sys.stderr)
sys.exit(1)
parser = ArgumentParser()
parser.add_argument("--mode", type=str, choices=["batch", "cases"], default="cases")
parser.add_argument("--folder", type=Path, default="examples")
parser.add_argument("--bench", action="store_true")
parser.add_argument("--command", type=str, choices=["c", "t", "S"], nargs="+", default=["c"])
parser.add_argument("--optimize", action="store_true")
args = parser.parse_args()
times = 10 if args.bench else 1
case_collector = Individual()
if args.mode == "batch":
case_collector = Batch()
files = list(args.folder.glob("**/*.fnl"))
print(f"Found: {' '.join(str(file) for file in files)}", file=sys.stderr)
for file in files:
for command in args.command:
for _ in range(times):
case_collector.add('-' + command, file)
case_collector.run()
if "-c" in args.command:
validate([
file
for file in args.folder.glob("**/*.spv")
if not file.name.endswith(".opt.spv")
], optimize=args.optimize)