|
@@ -25,8 +25,14 @@ CURRENT_FOLDER_NAME = "performance"
|
|
|
|
|
|
PORTS = set()
|
|
|
|
|
|
+OPTIMIZATION_LEVEL_LEGACY_INTERPRETER = "legacy-interpreter"
|
|
|
OPTIMIZATION_LEVEL_INTERPRETER = "interpreter"
|
|
|
OPTIMIZATION_LEVEL_BASELINE_JIT = "baseline-jit"
|
|
|
+ALL_OPTIMIZATION_LEVELS = [
|
|
|
+ OPTIMIZATION_LEVEL_LEGACY_INTERPRETER,
|
|
|
+ OPTIMIZATION_LEVEL_INTERPRETER,
|
|
|
+ OPTIMIZATION_LEVEL_BASELINE_JIT
|
|
|
+]
|
|
|
|
|
|
class ModelverseTerminated(Exception):
|
|
|
"""An exception that tells the user that the Modelverse has terminated."""
|
|
@@ -117,7 +123,7 @@ def compile_file(address, mod_filename, filename, mode, proc):
|
|
|
except UnboundLocalError:
|
|
|
pass
|
|
|
|
|
|
-def run_file(files, parameters, mode, handle_output):
|
|
|
+def run_file(files, parameters, mode, handle_output, optimization_level=None):
|
|
|
"""Compiles the given sequence of files, feeds them the given input in the given mode,
|
|
|
and handles their output."""
|
|
|
# Resolve file
|
|
@@ -128,7 +134,10 @@ def run_file(files, parameters, mode, handle_output):
|
|
|
address = "http://127.0.0.1:%i" % port
|
|
|
try:
|
|
|
# Run Modelverse server
|
|
|
- proc = execute("run_local_modelverse", [str(port)], wait=False)
|
|
|
+ modelverse_args = [str(port)]
|
|
|
+ if optimization_level is not None:
|
|
|
+ modelverse_args.append('--kernel=%s' % optimization_level)
|
|
|
+ proc = execute("run_local_modelverse", modelverse_args, wait=False)
|
|
|
|
|
|
threads = []
|
|
|
mod_files = []
|
|
@@ -207,7 +216,7 @@ def run_file_to_completion(files, parameters, mode):
|
|
|
except ModelverseTerminated:
|
|
|
return results
|
|
|
|
|
|
-def run_file_fixed_output_count(files, parameters, mode, output_count):
|
|
|
+def run_file_fixed_output_count(files, parameters, mode, output_count, optimization_level=None):
|
|
|
"""Compiles the given sequence of files, feeds them the given input in the given mode,
|
|
|
and then collects and returns a fixed number of outputs."""
|
|
|
results = []
|
|
@@ -219,13 +228,13 @@ def run_file_fixed_output_count(files, parameters, mode, output_count):
|
|
|
else:
|
|
|
return False
|
|
|
|
|
|
- run_file(files, parameters, mode, handle_output)
|
|
|
+ run_file(files, parameters, mode, handle_output, optimization_level)
|
|
|
return results
|
|
|
|
|
|
-def run_file_single_output(files, parameters, mode):
|
|
|
+def run_file_single_output(files, parameters, mode, optimization_level=None):
|
|
|
"""Compiles the given sequence of files, feeds them the given input in the given mode,
|
|
|
and then collects and returns a single output."""
|
|
|
- return run_file_fixed_output_count(files, parameters, mode, 1)[0]
|
|
|
+ return run_file_fixed_output_count(files, parameters, mode, 1, optimization_level)[0]
|
|
|
|
|
|
def run_perf_test(files, parameters, optimization_level, n_iterations=1):
|
|
|
"""Compiles the given sequence of files, feeds them the given input in the given mode,
|
|
@@ -235,13 +244,27 @@ def run_perf_test(files, parameters, optimization_level, n_iterations=1):
|
|
|
for _ in xrange(n_iterations):
|
|
|
result += float(
|
|
|
run_file_single_output(
|
|
|
- files, [optimization_level] + parameters + [0], 'CO')) / float(n_iterations)
|
|
|
+ files, [optimization_level] + parameters + [0], 'CO',
|
|
|
+ optimization_level)) / float(n_iterations)
|
|
|
return result
|
|
|
|
|
|
def format_output(output):
|
|
|
"""Formats the output of `run_file_to_completion` as a string."""
|
|
|
return '\n'.join(output)
|
|
|
|
|
|
+def define_perf_test(target_class, test_function, optimization_level):
|
|
|
+ """Defines a performance test in the given class. The performance test calls the given function
|
|
|
+ at the given optimization level."""
|
|
|
+ setattr(
|
|
|
+ target_class,
|
|
|
+ 'test_%s' % optimization_level.replace('-', '_').lower(),
|
|
|
+ lambda self: test_function(self, optimization_level))
|
|
|
+
|
|
|
+def define_perf_tests(target_class, test_function):
|
|
|
+ """Defines performance tests in the given class. Each test calls the given function."""
|
|
|
+ for optimization_level in ALL_OPTIMIZATION_LEVELS:
|
|
|
+ define_perf_test(target_class, test_function, optimization_level)
|
|
|
+
|
|
|
DEFAULT_PERF_FILE_NAME = 'perf_data.txt'
|
|
|
|
|
|
def write_perf_to_file(test_name, optimization_level, result, file_name=DEFAULT_PERF_FILE_NAME):
|