-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_experiment_on_scope.py
More file actions
210 lines (190 loc) · 6.89 KB
/
run_experiment_on_scope.py
File metadata and controls
210 lines (190 loc) · 6.89 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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import argparse
import csv
import json
import os
from pathlib import Path
import subprocess
def run_experiments(args):
with open(args.file, "r") as f:
scope = json.load(f)
exp_id = (
args.experiment_id
if args.experiment_id is not None
else list(scope.keys())[-1]
)
scope = scope[exp_id]
run_dir = os.path.join(
os.getcwd(), "experiments", "results_1", exp_id
)
run_index = os.path.join(
run_dir, "index.json"
)
run_specs = {
"CPU": args.cpu,
"GPU": args.gpu,
"Baseline": args.baseline,
"TVM": args.tvm,
"JAX": args.jax,
"TORCH_C": args.torch_compile,
"TORCH_N": args.torch_nocompile,
"repeat": args.repeat,
"dataset": os.path.join(args.dataset, scope["data_size"], f"{args.sample}.npy"),
"max_threads": args.max_threads,
}
if os.path.isfile(run_index):
with open(run_index, "r") as f:
content = json.load(f)
curr_run = len(content.keys()) + 1
with open(run_index, "w") as f:
content[curr_run] = run_specs
json.dump(content, f, indent=4)
else:
curr_run = 1
Path(run_dir).mkdir(parents=True, exist_ok=True)
with open(run_index, "w") as f:
json.dump({curr_run: run_specs}, f, indent=4)
csv_file = os.path.join(
os.getcwd(), "experiments", "results_1", exp_id, f"Run{curr_run:02d}.csv"
)
with open(csv_file, "w") as f:
writer = csv.writer(f)
writer.writerow(
[
"attr",
"env",
"threads",
*[f"d1t{i+1}" for i in range(args.repeat)],
*[f"d2t{i+1}" for i in range(args.repeat)],
]
)
base_path = ""
if args.tvm != None:
base_path = os.path.join(
os.getcwd(), "experiments", "modules_1", exp_id
)
if run_specs["CPU"]:
for spec in ["Baseline", "TVM", "JAX", "TORCH_C", "TORCH_N"]:
if run_specs[spec]:
process = subprocess.run(
[
f"./scripts/run_{spec.lower()}_cpu.sh"
if spec == "Baseline"
else f"./scripts/run_{spec.lower()}_cpu.sh",
csv_file,
str(run_specs["repeat"]),
os.path.join(os.getcwd(), "data", run_specs["dataset"]),
scope["dtype"],
str(run_specs["max_threads"]),
os.path.join(base_path, "Build01"),
"1"
],
capture_output=True,
)
with open(f"{spec.lower()}_cpu_stdout_{exp_id}.log", "w") as f:
f.write(process.stdout.decode("ascii"))
with open(f"{spec.lower()}_cpu_stderr_{exp_id}.log", "w") as f:
f.write(process.stderr.decode("ascii"))
if spec == "TVM":
process = subprocess.run(
[
f"./scripts/run_{spec.lower()}_cpu.sh"
if spec == "Baseline"
else f"./scripts/run_{spec.lower()}_cpu.sh",
csv_file,
str(run_specs["repeat"]),
os.path.join(os.getcwd(), "data", run_specs["dataset"]),
scope["dtype"],
str(run_specs["max_threads"]),
os.path.join(base_path, "Build02"),
"2"
],
capture_output=True,
)
with open(f"{spec.lower()}_2_cpu_stdout_{exp_id}.log", "w") as f:
f.write(process.stdout.decode("ascii"))
with open(f"{spec.lower()}_2_cpu_stderr_{exp_id}.log", "w") as f:
f.write(process.stderr.decode("ascii"))
if run_specs["GPU"]:
for spec in ["Baseline", "TVM", "JAX", "TORCH_C", "TORCH_N"]:
if run_specs[spec]:
process = subprocess.run(
[
f"./scripts/run_{spec.lower()}_gpu.sh",
csv_file,
str(run_specs["repeat"]),
os.path.join(os.getcwd(), "data", run_specs["dataset"]),
scope["dtype"],
os.path.join(base_path, "Build03"),
"3"
],
capture_output=True,
)
with open(f"{spec.lower()}_gpu_stdout_{exp_id}.log", "w") as f:
f.write(process.stdout.decode("ascii"))
with open(f"{spec.lower()}_gpu_stderr_{exp_id}.log", "w") as f:
f.write(process.stderr.decode("ascii"))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"-f",
"--file",
help="Experiment Index JSON file path",
type=Path,
default=os.path.join("experiments", "index.json"),
)
parser.add_argument(
"-c",
"--cpu",
help="CPU will be used, needs to be set on scope as well",
action="store_true",
)
parser.add_argument(
"-g",
"--gpu",
help="GPU will be used, needs to be set on scope as well",
action="store_true",
)
parser.add_argument("-b", "--baseline", help="Run baselines", action="store_true")
parser.add_argument("-t", "--tvm", help="Run TVM operators", action="store_true")
parser.add_argument("-j", "--jax", help="Run JAX operators", action="store_true")
parser.add_argument("-o", "--torch-compile", help="Run Torch Compile operators", action="store_true")
parser.add_argument("-n", "--torch-nocompile", help="Run Torch operators without compile", action="store_true")
parser.add_argument(
"-d",
"--dataset",
help="dataset to use",
type=str,
choices=["parihaka"],
default="parihaka",
)
parser.add_argument(
"-s",
"--sample",
help="dataset sample to use",
type=int,
choices=[1, 2, 3, 4, 5],
default=1,
)
parser.add_argument(
"-r",
"--repeat",
help="Number of timeit repeat samples",
type=int,
default=5,
)
parser.add_argument(
"-m",
"--max-threads",
help="Max number of threads (OMP_NUM_THREADS) to test, will set OMP_NUM_THREADS",
type=int,
default=1,
)
parser.add_argument(
"-e",
"--experiment-id",
help="Experiment ID to use, if not set defaults to last on the file",
type=str,
default=None,
)
args = parser.parse_args()
run_experiments(args)