-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathbm_streams.C
253 lines (229 loc) · 9.65 KB
/
bm_streams.C
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
R__LOAD_LIBRARY(libMathMore)
#include "bm_util.C"
void bm_streams(TString dataSet="result_streams",
std::string title = "TITLE",
TString output_path = "graph_streams.root")
{
std::ifstream file_timing(Form("%s.txt", dataSet.Data()));
std::string sample;
std::string compression;
std::string media;
Int_t nstreams;
std::array<float, 6> timings;
int max_streams = 0;
// sample --> compresseion --> mean/error
std::map<std::string, std::map<string, std::pair<float, float>>> data_mem;
// sample -> compression -> nstreams -> mean/error
std::map<std::string, std::map<std::string, std::map<int, std::pair<float, float>>>> data;
// sample -> compression -> nstreams -> mean/error
std::map<std::string, std::map<std::string, std::map<int, std::pair<float, float>>>> speedup;
// sample -> compression -> mean/error
std::map<std::string, std::map<std::string, std::pair<float, float>>> speedup_mem;
// sample -> compression -> graph
std::map<std::string, std::map<std::string, TGraphErrors *>> graphs;
// sample -> compression -> graph
std::map<std::string, std::map<std::string, TGraphErrors *>> graphs_mem;
while (file_timing >> media >> sample >> compression >> nstreams >>
timings[0] >> timings[1] >> timings[2] >>
timings[3] >> timings[4] >> timings[5])
{
float mean;
float error;
GetStats(timings.data(), 6, mean, error);
std::cout << media << " " << sample << " " << compression << " " << nstreams << " " <<
mean << " +/- " << error << std::endl;
if (media == "mem") {
data_mem[sample][compression] = std::pair<float, float>(mean, error);
if (graphs.count(sample) == 0) {
graphs_mem[sample] = std::map<std::string, TGraphErrors *>();
}
graphs_mem[sample][compression] = new TGraphErrors();
} else {
data[sample][compression][nstreams] = std::pair<float, float>(mean, error);
if (graphs.count(sample) == 0) {
graphs[sample] = std::map<std::string, TGraphErrors *>();
}
if (graphs[sample].count(compression) == 0) {
graphs[sample][compression] = new TGraphErrors();
}
max_streams = std::max(max_streams, nstreams);
}
}
float min_ratio = 1.0;
float max_ratio = 1.0;
for (const auto &samples : data) {
for (const auto &compressions : samples.second) {
for (const auto &streams : compressions.second) {
auto ref_val = data[samples.first][compressions.first][1].first;
auto ref_err = data[samples.first][compressions.first][1].second;
auto this_val = streams.second.first;
auto this_err = streams.second.second;
auto ratio_val = ref_val / this_val;
auto ratio_err = ratio_val *
sqrt(this_err * this_err / this_val / this_val +
ref_err * ref_err / ref_val / ref_val);
speedup[samples.first][compressions.first][streams.first] =
std::pair<float, float>(ratio_val, ratio_err);
std::cout << samples.first << " " << compressions.first << " " << streams.first << " " <<
ratio_val << " +/- " << ratio_err << std::endl;
min_ratio = std::min(min_ratio, ratio_val - ratio_err);
max_ratio = std::max(max_ratio, ratio_val + ratio_err);
auto step = graphs[samples.first][compressions.first]->GetN();
graphs[samples.first][compressions.first]->SetPoint(step, streams.first, ratio_val);
graphs[samples.first][compressions.first]->SetPointError(step, 0, ratio_err);
}
}
}
std::map<std::string, int> x_offsets{{"lhcb", 32}, {"h1X10", 20}, {"cms", 8}};
for (const auto &samples : data_mem) {
for (const auto &compressions : samples.second) {
auto ref_val = data[samples.first][compressions.first][1].first;
auto ref_err = data[samples.first][compressions.first][1].second;
auto this_val = compressions.second.first;
auto this_err = compressions.second.second;
auto ratio_val = ref_val / this_val;
auto ratio_err = ratio_val *
sqrt(this_err * this_err / this_val / this_val +
ref_err * ref_err / ref_val / ref_val);
speedup_mem[samples.first][compressions.first] =
std::pair<float, float>(ratio_val, ratio_err);
std::cout << "MEM REF: " << samples.first << " " << compressions.first << " " <<
ratio_val << " +/- " << ratio_err << " @" << 2 * max_streams << std::endl;
min_ratio = std::min(min_ratio, ratio_val - ratio_err);
max_ratio = std::max(max_ratio, ratio_val + ratio_err);
graphs_mem[samples.first][compressions.first]->SetPoint(
0, 2 * max_streams - x_offsets[samples.first], ratio_val);
graphs_mem[samples.first][compressions.first]->SetPointError(0, 0, ratio_err);
}
}
SetStyle(); // Has to be at the beginning of painting
gStyle->SetTitleSize(0.03, "T");
TCanvas *canvas = new TCanvas("MyCanvas", "MyCanvas");
canvas->cd();
canvas->SetCanvasSize(1600, 850);
canvas->SetFillColor(GetTransparentColor());
gPad->SetLogx(1);
gPad->SetFillColor(GetTransparentColor());
gPad->SetGridy();
auto ymax = 7;
TH1F * helper = new TH1F("", "", 2 * max_streams + 8, 0.9, 2 * max_streams + 8);
helper->SetMinimum(0);
helper->SetMaximum(/*max_ratio * 1.25*/ymax);
helper->GetXaxis()->SetTitle("# Streams ");
helper->GetXaxis()->SetTitleOffset(1);
helper->GetXaxis()->SetLabelSize(0.06);
helper->GetXaxis()->SetTitleSize(0.04);
//helper->GetXaxis()->SetNdivisions(1);
//helper->GetXaxis()->SetBinLabel(1, "1");
helper->GetXaxis()->SetTickSize(0);
helper->GetXaxis()->SetLabelSize(0);
//helper->GetXaxis()->SetBinLabel(2, " 2");
//helper->GetXaxis()->SetBinLabel(4, " 4");
//helper->GetXaxis()->SetBinLabel(8, " 8");
//helper->GetXaxis()->SetBinLabel(16, " 16");
//helper->GetXaxis()->SetBinLabel(32, " 32");
//helper->GetXaxis()->SetBinLabel(64, " 64");
//helper->GetXaxis()->LabelsOption("h");
//gPad->SetLogx(1);
helper->GetYaxis()->SetTitle("Speed-up wrt. single stream");
helper->GetYaxis()->SetLabelSize(0.04);
helper->GetYaxis()->SetTitleSize(0.04);
helper->GetYaxis()->SetTitleOffset(0.7);
//helper->SetTitle(title);
helper->Draw();
std::map<std::string, int> sample_colors;
sample_colors["cms"] = kGreen + 2;
sample_colors["lhcb"] = kCyan + 2;
sample_colors["h1X10"] = kMagenta + 2;
std::map<std::string, int> compression_styles;
compression_styles["none"] = 1;
compression_styles["zstd"] = 7;
std::map<std::string, int> marker_styles{{"none", 20}, {"zstd", 47}};
for (const auto &samples : graphs) {
for (const auto &compressions : samples.second) {
auto g = compressions.second;
g->SetMarkerStyle(kStar);
g->SetMarkerColor(sample_colors[samples.first]);
g->SetLineColor(sample_colors[samples.first]);
g->SetLineStyle(compression_styles[compressions.first]);
g->SetLineWidth(2);
g->SetMarkerStyle(marker_styles[compressions.first]);
g->SetMarkerSize(1.5);
g->Draw("LP");
}
}
for (const auto &samples : graphs_mem) {
for (const auto &compressions : samples.second) {
auto g = compressions.second;
g->SetMarkerStyle(kStar);
g->SetMarkerColor(sample_colors[samples.first]);
g->SetLineColor(sample_colors[samples.first]);
g->SetLineStyle(compression_styles[compressions.first]);
g->SetLineWidth(2);
g->SetMarkerStyle(marker_styles[compressions.first]);
g->SetMarkerSize(2);
g->Draw("P");
}
}
TLegend *leg = new TLegend(0.15, 0.71, 0.6, 0.86);
leg->SetNColumns(3);
leg->SetHeader("\"LHCb\" \"H1\" \"CMS\"");
leg->AddEntry(graphs["lhcb"]["none"], "uncompressed", "lp");
leg->AddEntry(graphs["h1X10"]["none"], "uncompressed", "lp");
leg->AddEntry(graphs["cms"]["none"], "uncompressed", "lp");
leg->AddEntry(graphs["lhcb"]["zstd"], "zstd", "lp");
leg->AddEntry(graphs["h1X10"]["zstd"], "zstd", "lp");
leg->AddEntry(graphs["cms"]["zstd"], "zstd", "lp");
leg->SetBorderSize(1);
leg->SetTextSize(0.03);
leg->Draw();
TText l;
l.SetTextSize(0.025);
l.SetTextAlign(13);
l.DrawTextNDC(0.15, 0.71 - 0.01, "95% CL");
for (unsigned i = 1; i <= 64; i *= 2) {
auto tlabel = new TText;
tlabel->SetTextFont(helper->GetXaxis()->GetTitleFont());
tlabel->SetTextSize(0.04);
tlabel->SetTextAlign(22);
tlabel->DrawText(i, -0.25, std::to_string(i).c_str());
TLine *line = new TLine(i, 0., i, 0.2);
line->SetLineColor(kBlack);
line->Draw();
}
auto tlabel = new TText;
tlabel->SetTextFont(helper->GetXaxis()->GetTitleFont());
tlabel->SetTextSize(0.04);
tlabel->SetTextAlign(22);
tlabel->DrawText(128 - 16, -0.25, "warm cache");
TLine *line = new TLine(75, 0, 75, ymax);
line->SetLineColor(kBlack);
//line->SetLineStyle(2);
line->Draw();
TText mbs_cms;
mbs_cms.SetTextSize(0.03);
mbs_cms.SetTextColor(sample_colors["cms"]);
mbs_cms.SetTextAlign(31);
mbs_cms.DrawText(64, 3.2, "700 MB/s");
TText mbs_h1;
mbs_h1.SetTextSize(0.03);
mbs_h1.SetTextColor(sample_colors["h1X10"]);
mbs_h1.SetTextAlign(31);
mbs_h1.DrawText(64, 2.2, "1.2 GB/s");
TText mbs_lhcb;
mbs_lhcb.SetTextSize(0.03);
mbs_lhcb.SetTextColor(sample_colors["lhcb"]);
mbs_lhcb.SetTextAlign(31);
mbs_lhcb.DrawText(64, 0.5, "680 MB/s");
TText ttitle;
ttitle.SetTextFont(helper->GetXaxis()->GetTitleFont());
ttitle.SetTextSize(0.03);
ttitle.SetTextAlign(22);
ttitle.DrawText(10, ymax + 0.25, title.c_str());
auto output = TFile::Open(output_path, "RECREATE");
output->cd();
canvas->Write();
std::string pdf_path = output_path.View().to_string();
canvas->Print(TString(pdf_path.substr(0, pdf_path.length() - 4) + "pdf"));
output->Close();
}