MCPcopy Create free account
hub / github.com/MegEngine/MegCC / BenchMarkRunnerBase

Class BenchMarkRunnerBase

benchmark/python/src/benchmark.py:33–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31
32
33class BenchMarkRunnerBase:
34 model = None
35 benchmark_build_dir = ""
36 benchmark_arch = ""
37 benchmark_framework = ""
38 output_dir = None
39 log_level = -1
40 benchmark_exec_func = ""
41
42 def __init__(self, benchmark_build_dir="", benchmark_arch="x86"):
43 if benchmark_build_dir == "":
44 benchmark_build_dir = "{}/benchmark/build_{}".format(
45 megcc_path, benchmark_arch)
46 self.benchmark_build_dir = benchmark_build_dir
47 self.benchmark_arch = benchmark_arch
48
49 def build(self, x86_target="fallback", build_options=""):
50 # build prepare
51 if not os.path.exists(self.benchmark_build_dir) or os.path.isfile(
52 self.benchmark_build_dir):
53 os.makedirs(self.benchmark_build_dir)
54 # build megengine lib and set cmake build options
55 cmd = "cd {} && cmake {}/benchmark {} -G Ninja && ninja install/strip".format(
56 self.benchmark_build_dir, megcc_path, build_options)
57 subprocess.check_call(cmd, shell=True)
58
59 def set_config(
60 self,
61 profile_kernel=False,
62 benchmark_framework="megcc",
63 model=None,
64 output_dir=None,
65 ):
66 if profile_kernel:
67 self.log_level = 0
68 else:
69 self.log_level = 3
70 self.benchmark_framework = benchmark_framework
71 self.output_dir = output_dir
72 self.model = model
73 self.benchmark_exec_func = "{}/install/bin/benchmarker".format(
74 self.benchmark_build_dir)
75
76 def run_local(self):
77 if not os.path.exists(self.output_dir.local_path) or os.path.isfile(
78 self.output_dir.local_path):
79 os.makedirs(self.output_dir.local_path)
80 logfile = open(
81 "{}/{}-{}-{}-{}-log-local.txt".format(
82 self.output_dir.local_path,
83 self.benchmark_framework,
84 self.benchmark_arch,
85 self.model.name,
86 self.log_level,
87 ),
88 "w",
89 )
90 run_options = ""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected