Mentions légales du service

Skip to content
Snippets Groups Projects
Commit b2e16978 authored by GRUBER Fabian's avatar GRUBER Fabian
Browse files

benchmarks: added option '-o'/'--output' which controls where the benchmark...

benchmarks: added option '-o'/'--output' which controls where the benchmark results are printed (default is still stdout).
parent 00685293
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ import sys ...@@ -17,6 +17,7 @@ import sys
import tempfile import tempfile
import time import time
import typing as ty import typing as ty
from typing.io import IO
from pipedream.benchmark.types import * from pipedream.benchmark.types import *
...@@ -32,7 +33,8 @@ from pipedream.utils import terminal ...@@ -32,7 +33,8 @@ from pipedream.utils import terminal
def main(*, argv: ty.List[str] = None, def main(*, argv: ty.List[str] = None,
make_perf_counters: ty.Callable[[ty.List[str]], 'Perf_Counter_Spec'], make_perf_counters: ty.Callable[[ty.List[str]], 'Perf_Counter_Spec'],
benchmark_kind: Benchmark_Kind): benchmark_kind: Benchmark_Kind):
_Benchmark_Runner().main(argv=argv, make_perf_counters=make_perf_counters, benchmark_kind=benchmark_kind) _Benchmark_Runner().main(
argv=argv, make_perf_counters=make_perf_counters, benchmark_kind=benchmark_kind)
def run_benchmarks(*, def run_benchmarks(*,
...@@ -78,6 +80,8 @@ class _Benchmark_Runner: ...@@ -78,6 +80,8 @@ class _Benchmark_Runner:
perf_counters = make_perf_counters(args.run.extra_events) perf_counters = make_perf_counters(args.run.extra_events)
output: IO[str] = args.output.output
for results in run_benchmarks(arch = args.architecture, for results in run_benchmarks(arch = args.architecture,
benchmarks = benchmark_specs, benchmarks = benchmark_specs,
perf_counters = perf_counters, perf_counters = perf_counters,
...@@ -88,10 +92,10 @@ class _Benchmark_Runner: ...@@ -88,10 +92,10 @@ class _Benchmark_Runner:
tmp_dir = args.output.tmp_dir, tmp_dir = args.output.tmp_dir,
debug = args.debug,): debug = args.debug,):
self.info.clear() self.info.clear()
sys.stdout.write('---\n') output.write('---\n')
yaml.dump(results, sys.stdout) yaml.dump(results, output)
sys.stdout.write('...\n') output.write('...\n')
sys.stdout.flush() output.flush()
def run_benchmarks(self, *, def run_benchmarks(self, *,
arch: ir.Architecture, arch: ir.Architecture,
...@@ -377,6 +381,16 @@ class _Benchmark_Runner: ...@@ -377,6 +381,16 @@ class _Benchmark_Runner:
output = parser.add_argument_group('output options') output = parser.add_argument_group('output options')
output_file = output.add_argument(
'-o', '--output',
help='''file to print benchmark results to''',
)
output_append = output.add_argument(
'-a', '--append',
help='''append to output file insted of overwriting it''',
action='store_true', default=False,
)
tmp_dir = output.add_argument( tmp_dir = output.add_argument(
'--tmp-dir', '--tmp-dir',
help='''directory for temporary files''', help='''directory for temporary files''',
...@@ -438,6 +452,17 @@ class _Benchmark_Runner: ...@@ -438,6 +452,17 @@ class _Benchmark_Runner:
## ##
if not args.output:
args.output = sys.stdout
else:
mode = 'a' if args.append else 'w'
try:
args.output = argparse.FileType(mode)(args.output)
except argparse.ArgumentTypeError as e:
parser.error(str(e))
##
class Immutable_Bag(collections.abc.Mapping): class Immutable_Bag(collections.abc.Mapping):
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.__dict__.update(kwargs) self.__dict__.update(kwargs)
...@@ -470,7 +495,7 @@ class _Benchmark_Runner: ...@@ -470,7 +495,7 @@ class _Benchmark_Runner:
kernels, tags, kernel_size, unroll_factor, different_instructions, dynamic_instructions, num_iterations, kernels, tags, kernel_size, unroll_factor, different_instructions, dynamic_instructions, num_iterations,
num_warmup_iterations, outlier_lo, outlier_hi, events), num_warmup_iterations, outlier_lo, outlier_hi, events),
output=Immutable_Namespace( output=Immutable_Namespace(
tmp_dir, debug) tmp_dir, debug, output_file)
) )
return out return out
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment