forked from undertherain/benchmarker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarker.py
More file actions
60 lines (48 loc) · 1.47 KB
/
benchmarker.py
File metadata and controls
60 lines (48 loc) · 1.47 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
import importlib
import json
import os
import datetime
import begin
import sys
from sysinfo import sysinfo
sys.path.append("modules")
sys.path.append("data_helpers")
def get_time_str():
d = datetime.datetime.now()
s = d.strftime("%y.%m.%d_%H.%M.%S")
return s
def gen_name_output_file(params):
name = "{}_{}_{}_{}.json".format(
params["problem"],
params["framework"],
params["device"],
get_time_str()
)
return name
def save_params(params):
str_result=json.dumps(params, sort_keys=True, indent=4, separators=(',', ': '))
print(str_result)
path_out = params["path_out"]
name_file = gen_name_output_file(params)
with open(os.path.join(path_out, name_file), "w") as f:
f.write(str_result)
@begin.start
def main(framework: "Framework to test" = "theano",
problem: "problem to solve" = "conv2d_1",
path_out: "path to store results" = "./",
gpus: "list of gpus to use" = ""
):
params = sysinfo.get_sys_info()
params["framework"] = framework
params["path_out"] = path_out
params["gpus"] = list(map(int, gpus.split(',')))
params["nb_gpus"] = len(gpus)
params["problem"] = problem
if params["nb_gpus"] > 0:
params["device"] = params["gpu"]
else:
params["device"] = params["cpu_brand"]
mod = importlib.import_module("modules.do_"+params["framework"])
run = getattr(mod, 'run')
params = run(params)
save_params(params)