-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpearson_corr.py
146 lines (119 loc) · 4.27 KB
/
pearson_corr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import os
import numpy as np
from scipy.stats import pearsonr
from functools import reduce
from pathlib import Path
def get_metrics_idxs(lines):
res = []
for i, line in enumerate(lines):
if line.startswith("TABLE,Group") and "Metric," in line:
how_many = int(line.strip(",\n").split(",")[-1])
res.append((i + 2, i + 2 + how_many))
return res
def get_running_time(file):
with open(file) as f:
for line in f:
if line.startswith("Time"):
return eval(line.split("\t")[-1].split(" ")[0])
return 0
def get_first_metric(line):
line = line.strip(",\n").split(",")
return line[0], float(line[1] if line[1] != "-" else 0)
def get_metrics(f_name):
with open(f_name) as f:
lines = f.readlines()
metrics_lines = map(
get_first_metric,
reduce(
lambda a,b: a + b,
map(
lambda e: lines[e[0]: e[1]],
get_metrics_idxs(lines)
)
)
)
res = []
distinct_metrics = set()
metrics = []
for metric, value in metrics_lines:
if metric in distinct_metrics: continue
metrics.append(metric)
res.append(value)
distinct_metrics.add(metric)
run_time = get_running_time(f_name.with_suffix(".stdout"))
return [run_time] + res, ["Run time"] + metrics
def build_name(pref, thread, ht, freq):
ht = "-HT" if ht else ""
return pref + str(thread) + ht + "-" + str(freq) + ".csv"
if __name__ == "__main__":
res, met = get_metrics(Path("data_aggregated/FPU-core-1-HT-1.2.csv"))
print(len(met))
DIR = Path("data_aggregated/")
OUT_DIR = Path("correlations/")
benchs = [
"ALU-mem-",
"ALU-core-",
"AVX-cache-",
"Copy-mem-",
"Copy-cache-",
"FPU-mem-",
"FPU-core-",
"Scattered-mem-",
]
thread_values = [1, 3, 6]
freq_values = [1.2, 1.7, 2.2]
for bench in benchs:
# Pearson correlation wrt freq
header = ",".join(["#Threads", "HT"] + met)
out = open(OUT_DIR / (bench + "freq.csv"), "w")
print(header, file=out)
for ht in [False, True]:
for thread in thread_values:
vals = []
for freq in freq_values:
f = DIR / build_name(bench, thread, ht, freq)
val, _ = get_metrics(f)
vals.append(val)
vals = np.array(vals)
corrs = []
for metric in range(vals.shape[1]):
corrs.append(str(pearsonr(freq_values, vals[:, metric])[0]))
line = ",".join([str(thread), str(ht)] + corrs)
print(line, file=out)
out.close()
# Pearson correlation wrt thread
header = ",".join(["Freq", "HT"] + met)
out = open(OUT_DIR / (bench + "threads.csv"), "w")
print(header, file=out)
for ht in [False, True]:
for freq in freq_values:
vals = []
for thread in thread_values:
f = DIR / build_name(bench, thread, ht, freq)
val, _ = get_metrics(f)
vals.append(val)
vals = np.array(vals)
corrs = []
for metric in range(vals.shape[1]):
corrs.append(str(pearsonr(thread_values, vals[:, metric])[0]))
line = ",".join([str(freq), str(ht)] + corrs)
print(line, file=out)
out.close()
# Pearson correlation wrt HT
header = ",".join(["Freq", "#Threads"] + met)
out = open(OUT_DIR / (bench + "HT.csv"), "w")
print(header, file=out)
for thread in thread_values:
for freq in freq_values:
vals = []
for ht in [False, True]:
f = DIR / build_name(bench, thread, ht, freq)
val, _ = get_metrics(f)
vals.append(val)
vals = np.array(vals)
corrs = []
for metric in range(vals.shape[1]):
corrs.append(str(pearsonr([0, 1], vals[:, metric])[0]))
line = ",".join([str(freq), str(thread)] + corrs)
print(line, file=out)
out.close()