Add all_facets & segment code in multiple functions

This commit is contained in:
augustin64 2024-06-13 10:47:14 +02:00
parent f894161143
commit 170d954c1b

View File

@ -6,7 +6,6 @@
import pandas as pd import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import seaborn as sns import seaborn as sns
from sys import exit
import numpy as np import numpy as np
from scipy import optimize from scipy import optimize
import argparse import argparse
@ -84,10 +83,10 @@ stats = pd.read_csv(args.path + ".stats.csv",
slice_mapping = pd.read_csv(args.path + ".slices.csv") slice_mapping = pd.read_csv(args.path + ".slices.csv")
core_mapping = pd.read_csv(args.path + ".cores.csv") core_mapping = pd.read_csv(args.path + ".cores.csv")
print("core mapping:\n", core_mapping.to_string()) # print("core mapping:\n", core_mapping.to_string())
print("slice mapping:\n", slice_mapping.to_string()) # print("slice mapping:\n", slice_mapping.to_string())
#print("core {} is mapped to '{}'".format(4, repr(core_mapping.iloc[4]))) # print("core {} is mapped to '{}'".format(4, repr(core_mapping.iloc[4])))
min_time_miss = stats["clflush_miss_n"].min() min_time_miss = stats["clflush_miss_n"].min()
max_time_miss = stats["clflush_miss_n"].max() max_time_miss = stats["clflush_miss_n"].max()
@ -106,6 +105,8 @@ def plot(filename, g=None):
g.savefig(img_dir+filename) g.savefig(img_dir+filename)
else: else:
plt.savefig(img_dir+filename) plt.savefig(img_dir+filename)
# tikzplotlib.save(img_dir+filename+".tex", axis_width=r'0.175\textwidth', axis_height=r'0.25\textwidth')
print(filename, "saved")
plt.close() plt.close()
plt.show() plt.show()
@ -123,12 +124,8 @@ stats["slice_group"] = stats["hash"].apply(lambda h: slice_mapping["slice_group"
graph_lower_miss = int((min_time_miss // 10) * 10) graph_lower_miss = int((min_time_miss // 10) * 10)
graph_upper_miss = int(((max_time_miss + 9) // 10) * 10) graph_upper_miss = int(((max_time_miss + 9) // 10) * 10)
print("Graphing from {} to {}".format(graph_lower_miss, graph_upper_miss)) # print("Graphing from {} to {}".format(graph_lower_miss, graph_upper_miss))
g_ = sns.FacetGrid(stats, col="main_core_fixed", row="slice_group")
g_.map(sns.histplot, 'clflush_miss_n', bins=range(graph_lower_miss, graph_upper_miss), color="b", edgecolor="b", alpha=0.2)
plot("medians_miss_grid.png", g=g_)
# also explains remote # also explains remote
# shared needs some thinking as there is something weird happening there. # shared needs some thinking as there is something weird happening there.
@ -138,10 +135,10 @@ plot("medians_miss_grid.png", g=g_)
# #
print(stats.head()) # print(stats.head())
num_core = len(stats["main_core_fixed"].unique()) num_core = len(stats["main_core_fixed"].unique())
print("Found {}".format(num_core)) # print("Found {}".format(num_core))
def miss_topology(main_core_fixed, slice_group, C, h): def miss_topology(main_core_fixed, slice_group, C, h):
@ -151,16 +148,9 @@ def miss_topology_df(x, C, h):
return x.apply(lambda x, C, h: miss_topology(x["main_core_fixed"], x["slice_group"], C, h), args=(C, h), axis=1) return x.apply(lambda x, C, h: miss_topology(x["main_core_fixed"], x["slice_group"], C, h), args=(C, h), axis=1)
res_miss = optimize.curve_fit(miss_topology_df, stats[["main_core_fixed", "slice_group"]], stats["clflush_miss_n"])
print("Miss topology:")
print(res_miss)
memory = -1 memory = -1
gpu_if_any = num_core gpu_if_any = num_core
def exclusive_hit_topology_gpu(main_core, slice_group, helper_core, C, h1, h2): def exclusive_hit_topology_gpu(main_core, slice_group, helper_core, C, h1, h2):
round_trip = gpu_if_any - memory round_trip = gpu_if_any - memory
@ -178,11 +168,9 @@ def exclusive_hit_topology_gpu(main_core, slice_group, helper_core, C, h1, h2):
r = C + h1 * abs(main_core - slice_group) + h2 * abs(helper_core - slice_group) r = C + h1 * abs(main_core - slice_group) + h2 * abs(helper_core - slice_group)
return r return r
def exclusive_hit_topology_gpu_df(x, C, h1, h2): def exclusive_hit_topology_gpu_df(x, C, h1, h2):
return x.apply(lambda x, C, h1, h2: exclusive_hit_topology_gpu(x["main_core_fixed"], x["slice_group"], x["helper_core_fixed"], C, h1, h2), args=(C, h1, h2), axis=1) return x.apply(lambda x, C, h1, h2: exclusive_hit_topology_gpu(x["main_core_fixed"], x["slice_group"], x["helper_core_fixed"], C, h1, h2), args=(C, h1, h2), axis=1)
def exclusive_hit_topology_gpu2(main_core, slice_group, helper_core, C, h1, h2): def exclusive_hit_topology_gpu2(main_core, slice_group, helper_core, C, h1, h2):
round_trip = gpu_if_any + 1 - memory round_trip = gpu_if_any + 1 - memory
@ -200,11 +188,9 @@ def exclusive_hit_topology_gpu2(main_core, slice_group, helper_core, C, h1, h2):
r = C + h1 * abs(main_core - slice_group) + h2 * abs(helper_core - slice_group) r = C + h1 * abs(main_core - slice_group) + h2 * abs(helper_core - slice_group)
return r return r
def exclusive_hit_topology_gpu2_df(x, C, h1, h2): def exclusive_hit_topology_gpu2_df(x, C, h1, h2):
return x.apply(lambda x, C, h1, h2: exclusive_hit_topology_gpu2(x["main_core_fixed"], x["slice_group"], x["helper_core_fixed"], C, h1, h2), args=(C, h1, h2), axis=1) return x.apply(lambda x, C, h1, h2: exclusive_hit_topology_gpu2(x["main_core_fixed"], x["slice_group"], x["helper_core_fixed"], C, h1, h2), args=(C, h1, h2), axis=1)
# unlikely # unlikely
def exclusive_hit_topology_nogpu(main_core, slice_group, helper_core, C, h1, h2): def exclusive_hit_topology_nogpu(main_core, slice_group, helper_core, C, h1, h2):
round_trip = (num_core-1) - memory round_trip = (num_core-1) - memory
@ -223,32 +209,15 @@ def exclusive_hit_topology_nogpu(main_core, slice_group, helper_core, C, h1, h2)
r = C + h1 * abs(main_core - slice_group) + h2 * abs(helper_core - slice_group) r = C + h1 * abs(main_core - slice_group) + h2 * abs(helper_core - slice_group)
return r return r
def exclusive_hit_topology_nogpu_df(x, C, h1, h2): def exclusive_hit_topology_nogpu_df(x, C, h1, h2):
return x.apply(lambda x, C, h1, h2: exclusive_hit_topology_nogpu(x["main_core_fixed"], x["slice_group"], x["helper_core_fixed"], C, h1, h2), args=(C, h1, h2), axis=1) return x.apply(lambda x, C, h1, h2: exclusive_hit_topology_nogpu(x["main_core_fixed"], x["slice_group"], x["helper_core_fixed"], C, h1, h2), args=(C, h1, h2), axis=1)
#res_no_gpu = optimize.curve_fit(exclusive_hit_topology_nogpu_df, stats[["main_core_fixed", "slice_group", "helper_core_fixed"]], stats["clflush_remote_hit"])
#print("Exclusive hit topology (No GPU):")
#print(res_no_gpu)
res_gpu = optimize.curve_fit(exclusive_hit_topology_gpu_df, stats[["main_core_fixed", "slice_group", "helper_core_fixed"]], stats["clflush_remote_hit"])
print("Exclusive hit topology (GPU):")
print(res_gpu)
#res_gpu2 = optimize.curve_fit(exclusive_hit_topology_gpu2_df, stats[["main_core_fixed", "slice_group", "helper_core_fixed"]], stats["clflush_remote_hit"])
#print("Exclusive hit topology (GPU2):")
#print(res_gpu2)
def remote_hit_topology_2(x, C, h): def remote_hit_topology_2(x, C, h):
main_core = x["main_core_fixed"] main_core = x["main_core_fixed"]
slice_group = x["slice_group"] slice_group = x["slice_group"]
helper_core = x["helper_core_fixed"] helper_core = x["helper_core_fixed"]
return C + h * abs(main_core - slice_group) + h * abs(slice_group - helper_core) + h * abs(helper_core - main_core) return C + h * abs(main_core - slice_group) + h * abs(slice_group - helper_core) + h * abs(helper_core - main_core)
def shared_hit_topology_1(x, C, h): def shared_hit_topology_1(x, C, h):
main_core = x["main_core_fixed"] main_core = x["main_core_fixed"]
slice_group = x["slice_group"] slice_group = x["slice_group"]
@ -256,67 +225,48 @@ def shared_hit_topology_1(x, C, h):
return C + h * abs(main_core - slice_group) + h * max(abs(slice_group - main_core), abs(slice_group - helper_core)) return C + h * abs(main_core - slice_group) + h * max(abs(slice_group - main_core), abs(slice_group - helper_core))
def plot_func(function, *params): def do_predictions(df):
def plot_it(x, **kwargs): res_miss = optimize.curve_fit(miss_topology_df, df[["main_core_fixed", "slice_group"]], df["clflush_miss_n"])
# plot_x = [] # print("Miss topology:")
# plot_y = [] # print(res_miss)
# for x in set(x):
# plot_y.append(function(x, *params))
# plot_x = x
print(x)
plot_y = function(x, *params)
sns.lineplot(x, plot_y, **kwargs)
return plot_it
stats["predicted_miss"] = miss_topology_df(stats, *(res_miss[0])) res_gpu = optimize.curve_fit(exclusive_hit_topology_gpu_df, df[["main_core_fixed", "slice_group", "helper_core_fixed"]], df["clflush_remote_hit"])
# print("Exclusive hit topology (GPU):")
# print(res_gpu)
figure_median_I = sns.FacetGrid(stats, col="main_core_fixed") #res_gpu2 = optimize.curve_fit(exclusive_hit_topology_gpu2_df, df[["main_core_fixed", "slice_group", "helper_core_fixed"]], df["clflush_remote_hit"])
figure_median_I.map(sns.scatterplot, 'slice_group', 'clflush_miss_n', color="b") #print("Exclusive hit topology (GPU2):")
figure_median_I.map(sns.lineplot, 'slice_group', 'predicted_miss', color="b") #print(res_gpu2)
figure_median_I.set_titles(col_template="$A$ = {col_name}")
figure_median_I.tight_layout()
# import tikzplotlib #res_no_gpu = optimize.curve_fit(exclusive_hit_topology_nogpu_df, df[["main_core_fixed", "slice_group", "helper_core_fixed"]], df["clflush_remote_hit"])
#print("Exclusive hit topology (No GPU):")
# tikzplotlib.save("fig-median-I.tex", axis_width=r'0.175\textwidth', axis_height=r'0.25\textwidth') #print(res_no_gpu)
plot("medians_miss.png")
#stats["predicted_remote_hit_no_gpu"] = exclusive_hit_topology_nogpu_df(stats, *(res_no_gpu[0]))
stats["predicted_remote_hit_gpu"] = exclusive_hit_topology_gpu_df(stats, *(res_gpu[0]))
#stats["predicted_remote_hit_gpu2"] = exclusive_hit_topology_gpu_df(stats, *(res_gpu2[0]))
stats_A0 = stats[stats["main_core_fixed"] == 0] # df["predicted_miss"] = miss_topology_df(df, *(res_miss[0]))
figure_median_E_A0 = sns.FacetGrid(stats_A0, col="slice_group")
figure_median_E_A0.map(sns.scatterplot, 'helper_core_fixed', 'clflush_remote_hit', color="r")
figure_median_E_A0.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_gpu', color="r")
figure_median_E_A0.set_titles(col_template="$S$ = {col_name}")
# tikzplotlib.save("fig-median-E-A0.tex", axis_width=r'0.175\textwidth', axis_height=r'0.25\textwidth')
plot("medians_remote_hit.png")
g = sns.FacetGrid(stats, row="main_core_fixed") #df["predicted_remote_hit_no_gpu"] = exclusive_hit_topology_nogpu_df(df, *(res_no_gpu[0]))
g.map(sns.scatterplot, 'slice_group', 'clflush_miss_n', color="b") df["predicted_remote_hit_gpu"] = exclusive_hit_topology_gpu_df(df, *(res_gpu[0]))
g.map(sns.scatterplot, 'slice_group', 'clflush_local_hit_n', color="g") #df["predicted_remote_hit_gpu2"] = exclusive_hit_topology_gpu_df(df, *(res_gpu2[0]))
plot("medians_miss_v_localhit_core.png", g=g)
g0 = sns.FacetGrid(stats, row="slice_group")
g0.map(sns.scatterplot, 'main_core_fixed', 'clflush_miss_n', color="b")
g0.map(sns.scatterplot, 'main_core_fixed', 'clflush_local_hit_n', color="g") # this gives away the trick I think !
# possibility of sending a general please discard this everyone around one of the ring + wait for ACK - direction depends on the core.
plot("medians_miss_v_localhit_slice.png", g=g0)
g2 = sns.FacetGrid(stats, row="main_core_fixed", col="slice_group")
g2.map(sns.scatterplot, 'helper_core_fixed', 'clflush_remote_hit', color="r")
g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_gpu', color="r")
#g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_gpu2', color="g")
#g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_no_gpu', color="g")
#g2.map(plot_func(exclusive_hit_topology_nogpu_df, *(res_no_gpu[0])), 'helper_core_fixed', color="g")
plot("medians_remote_hit_grid.png", g=g2)
if args.rslice: df_A0 = df[df["main_core_fixed"] == 0]
figure_median_E_A0 = sns.FacetGrid(df_A0, col="slice_group")
figure_median_E_A0.map(sns.scatterplot, 'helper_core_fixed', 'clflush_remote_hit', color="r")
figure_median_E_A0.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_gpu', color="r")
figure_median_E_A0.set_titles(col_template="$S$ = {col_name}")
plot("medians_remote_hit.png")
g2 = sns.FacetGrid(df, row="main_core_fixed", col="slice_group")
g2.map(sns.scatterplot, 'helper_core_fixed', 'clflush_remote_hit', color="r")
g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_gpu', color="r")
#g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_gpu2', color="g")
#g2.map(sns.lineplot, 'helper_core_fixed', 'predicted_remote_hit_no_gpu', color="g")
plot("medians_remote_hit_grid.png", g=g2)
def rslice():
for core in stats["main_core_fixed"].unique(): for core in stats["main_core_fixed"].unique():
os.makedirs(img_dir+f"slices{core}", exist_ok=True) os.makedirs(img_dir+f"slices{core}", exist_ok=True)
for slice in stats["slice_group"].unique(): for slice in stats["slice_group"].unique():
@ -327,8 +277,47 @@ if args.rslice:
plt.close() plt.close()
g3 = sns.FacetGrid(stats, row="main_core_fixed", col="slice_group") def facet_grid(
g3.map(sns.scatterplot, 'helper_core_fixed', 'clflush_shared_hit', color="y") df, row, col, third,
plot("medians_sharedhit.png", g=g3) draw_fn=sns.scatterplot,
# more ideas needed shown=["clflush_shared_hit", "clflush_remote_hit", "clflush_local_hit_n", "clflush_miss_n"],
colors=["y", "r", "g", "b"],
title=None
):
"""
Creates a facet grid showing all points
"""
grid = sns.FacetGrid(df, row=row, col=col)
for i, el in enumerate(shown):
grid.map(draw_fn, third, el, color=colors[i%len(colors)])
if title is not None:
plot(title, g=grid)
else:
print("Hey, title is None, are U sure ?")
return grid
def all_facets(df, id, *args, **kwargs):
"""
df : panda dataframe
id: the str to append to filenames
"""
facet_grid(df, "main_core_fixed", "helper_core_fixed", "slice_group", title=f"medians_facet_{id}s.png", *args, **kwargs)
facet_grid(df, "helper_core_fixed", "slice_group", "main_core_fixed", title=f"medians_facet_{id}c.png", *args, **kwargs)
facet_grid(df, "slice_group", "main_core_fixed", "helper_core_fixed", title=f"medians_facet_{id}h.png", *args, **kwargs)
if args.rslice:
rslice()
do_predictions(stats)
all_facets(stats, "")
for main in (0, 1):
for helper in (0, 1):
print(f"Doing all facets {main}x{helper}")
filtered_df = stats[(stats["main_core_fixed"]//(num_core/2) == main) & (stats["helper_core_fixed"]//(num_core/2) == helper)]
all_facets(filtered_df, f"m{main}h{helper}_")