Skip to content
Snippets Groups Projects

Draft: Develop

Closed Markus Holzer requested to merge holzer/pystencils:develop into master
1 file
+ 19
2
Compare changes
  • Side-by-side
  • Inline
import subprocess
import subprocess
import warnings
import warnings
import tempfile
import tempfile
 
from shutil import which
from pathlib import Path
from pathlib import Path
from jinja2 import Environment, PackageLoader, StrictUndefined
from jinja2 import Environment, PackageLoader, StrictUndefined
@@ -91,7 +92,8 @@ def generate_benchmark(ast, likwid=False, openmp=False, timing=False):
@@ -91,7 +92,8 @@ def generate_benchmark(ast, likwid=False, openmp=False, timing=False):
return env.get_template('benchmark.c').render(**jinja_context)
return env.get_template('benchmark.c').render(**jinja_context)
def run_c_benchmark(ast, inner_iterations, outer_iterations=3, path=None):
def run_c_benchmark(ast, inner_iterations, outer_iterations=3, path=None,
 
pin_with_likwid=False, threads=1):
"""Runs the given kernel with outer loop in C
"""Runs the given kernel with outer loop in C
Args:
Args:
@@ -99,6 +101,11 @@ def run_c_benchmark(ast, inner_iterations, outer_iterations=3, path=None):
@@ -99,6 +101,11 @@ def run_c_benchmark(ast, inner_iterations, outer_iterations=3, path=None):
inner_iterations: timings are recorded around this many iterations
inner_iterations: timings are recorded around this many iterations
outer_iterations: number of timings recorded
outer_iterations: number of timings recorded
path: path where the benchmark file is stored. If None a tmp folder is created
path: path where the benchmark file is stored. If None a tmp folder is created
 
pin_with_likwid: If True the benchmark runns with pinning. This is important to bind hardware threads to
 
application threads. If no pinning is used the benchmark might be significantily slower
 
than expected. In order to use pinning with likwid `likwid-pin` must be available.
 
For more information check: https://github.com/RRZE-HPC/likwid/wiki/Likwid-Pin
 
threads: The number of threads which are used for pinning.
Returns:
Returns:
list of times per iterations for each outer iteration
list of times per iterations for each outer iteration
@@ -131,8 +138,18 @@ def run_c_benchmark(ast, inner_iterations, outer_iterations=3, path=None):
@@ -131,8 +138,18 @@ def run_c_benchmark(ast, inner_iterations, outer_iterations=3, path=None):
]
]
run_compile_step(compile_cmd)
run_compile_step(compile_cmd)
 
if which("likwid-pin") is None and pin_with_likwid:
 
warnings.warn("likwid-pin is not in the PATH. No pinning will be used!"
 
"The benchmark output might be slower than expected.")
 
pin_with_likwid = False
 
 
if pin_with_likwid:
 
call_command = ['likwid-pin', '-q', '-c', f'N:0-{threads - 1}', './' / path / 'bench', str(inner_iterations)]
 
else:
 
call_command = ['./' / path / 'bench', str(inner_iterations)]
 
results = []
results = []
for _ in range(outer_iterations):
for _ in range(outer_iterations):
benchmark_time = float(subprocess.check_output(['./' / path / 'bench', str(inner_iterations)]))
benchmark_time = float(subprocess.check_output(call_command))
results.append(benchmark_time)
results.append(benchmark_time)
return results
return results
Loading