Commit 42fe986f authored by Philippe SWARTVAGHER's avatar Philippe SWARTVAGHER
Browse files

plot_model.py: print error of the model

parent 7023bfad
......@@ -4,6 +4,7 @@ import argparse
import glob
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
import statistics
from memory_contention import *
......@@ -16,6 +17,11 @@ def get_model(comp_kernel, numa_node, nb_cores_to_consider):
return CommCompModel(files_for_model)
def compute_error(observation, model):
return statistics.mean(map(lambda o, m: abs(o-m)/o, observation, model))
cli_parser = argparse.ArgumentParser()
cli_parser.add_argument("comp_kernel", help="computing kernel - folder where the input files are stored")
cli_parser.add_argument("hwloc_file", help="hwloc XML file")
......@@ -68,6 +74,10 @@ print("** Modeling all placement combinaisons...")
max_comp = 0
max_comm = 0
graphs = []
comm_errors = []
comm_errors_sample = []
comp_errors = []
comp_errors_sample = []
for numa_comp in range(topo.nb_numa_nodes_total):
graphs.append([])
......@@ -104,15 +114,15 @@ for numa_comp in range(topo.nb_numa_nodes_total):
x_span_zone=x_span_zone)
if len(parser.comm_bw_alone_results) > 0:
values = [parser.comm_bw_alone_results[x]['d9'] for x in real_x_values]
max_comm = max(max_comm, max(values))
comm_alone_upper_values = [parser.comm_bw_alone_results[x]['d9'] for x in real_x_values]
max_comm = max(max_comm, max(comm_alone_upper_values))
graph.add_comm_curve(
[parser.comm_bw_alone_results[x]['med'] for x in real_x_values],
"alone",
CommCompGraphCurveType.ALONE,
False,
[parser.comm_bw_alone_results[x]['d1'] for x in real_x_values],
values
comm_alone_upper_values
)
else:
graph.add_comm_curve(
......@@ -123,15 +133,16 @@ for numa_comp in range(topo.nb_numa_nodes_total):
)
max_comm = max(max_comm, parser.comm_bw_with_comp_results[1]['med'])
values = [parser.comm_bw_with_comp_results[x]['d9'] for x in real_x_values]
max_comm = max(max_comm, max(values))
comm_with_comp_values = [parser.comm_bw_with_comp_results[x]['med'] for x in real_x_values]
comm_with_comp_upper_values = [parser.comm_bw_with_comp_results[x]['d9'] for x in real_x_values]
max_comm = max(max_comm, max(comm_with_comp_upper_values))
graph.add_comm_curve(
[parser.comm_bw_with_comp_results[x]['med'] for x in real_x_values],
comm_with_comp_values,
"while Computations",
CommCompGraphCurveType.PARALLEL,
True,
[parser.comm_bw_with_comp_results[x]['d1'] for x in real_x_values],
values
comm_with_comp_upper_values
)
# Decision of which model to apply for communications:
......@@ -149,21 +160,29 @@ for numa_comp in range(topo.nb_numa_nodes_total):
display_line=False
)
error = compute_error(comm_with_comp_values, comm_values_model)
print(f"Communication model error: {error*100:3.2f}%")
if (numa_comp == 0 and numa_comm == 0) or (numa_comp == topo.nb_numa_nodes_per_socket and numa_comm == topo.nb_numa_nodes_per_socket):
comm_errors_sample.append(error)
else:
comm_errors.append(error)
op = "memset" # TODO: handle other cases
metric = parser.compute_bench_type.default_metric
values = [parser.comp_alone_results[op][x][metric]['max'] for x in real_x_values]
max_comp = max(max_comp, max(values))
comp_alone_upper_values = [parser.comp_alone_results[op][x][metric]['max'] for x in real_x_values]
max_comp = max(max_comp, max(comp_alone_upper_values))
graph.add_comp_curve(
[parser.comp_alone_results[op][x][metric]['avg'] for x in real_x_values],
f"{cli_args.comp_kernel} alone",
CommCompGraphCurveType.ALONE,
False,
[parser.comp_alone_results[op][x][metric]['min'] for x in real_x_values],
values
comp_alone_upper_values
)
comp_with_comm_values = [parser.comp_with_comm_results[op][x][metric]['avg'] for x in real_x_values]
graph.add_comp_curve(
[parser.comp_with_comm_results[op][x][metric]['avg'] for x in real_x_values],
comp_with_comm_values,
f"{cli_args.comp_kernel} while Ping-Pongs",
CommCompGraphCurveType.PARALLEL,
True,
......@@ -196,6 +215,13 @@ for numa_comp in range(topo.nb_numa_nodes_total):
display_line=False
)
error = compute_error(comp_with_comm_values, comp_values_model)
print(f"Computation model error: {error*100:3.2f}%")
if (numa_comp == 0 and numa_comm == 0) or (numa_comp == topo.nb_numa_nodes_per_socket and numa_comm == topo.nb_numa_nodes_per_socket):
comp_errors_sample.append(error)
else:
comp_errors.append(error)
graphs[numa_comp].append(graph)
# Stacked plot:
......@@ -242,3 +268,17 @@ for numa_comp in range(topo.nb_numa_nodes_total):
merged_image.save()
merged_stacked_image.save()
if cli_args.model:
print("** Error of the model:")
print(f"Communication model on sample executions: {statistics.mean(comm_errors_sample)*100:3.2f}%")
if len(comm_errors) > 0:
print(f"Communication model on non-sample executions: {statistics.mean(comm_errors)*100:3.2f}%")
print(f"Communication model on all executions: {statistics.mean(comm_errors_sample+comm_errors)*100:3.2f}%")
print(f"Computation model on sample executions: {statistics.mean(comp_errors_sample)*100:3.2f}%")
if len(comp_errors) > 0:
print(f"Computation model on non-sample executions: {statistics.mean(comp_errors)*100:3.2f}%")
print(f"Computation model on all executions: {statistics.mean(comp_errors_sample+comp_errors)*100:3.2f}%")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment