File indexing completed on 2024-04-06 12:28:23
0001 #include "PlotBenchmarks.hh"
0002
0003 #include <iostream>
0004
0005 PlotBenchmarks::PlotBenchmarks(const TString& arch, const TString& sample, const TString& suite)
0006 : arch(arch), sample(sample), suite(suite) {
0007
0008 setupStyle();
0009
0010
0011 file = TFile::Open("benchmark_" + arch + "_" + sample + ".root");
0012
0013
0014 setupARCHEnum(arch);
0015
0016
0017 setupArch();
0018
0019
0020 setupSUITEEnum(suite);
0021
0022
0023 setupBuilds(true, false);
0024 }
0025
0026 PlotBenchmarks::~PlotBenchmarks() { delete file; }
0027
0028 void PlotBenchmarks::RunBenchmarkPlots() {
0029
0030 const TString nth = "1";
0031 const TString nvu = Form("%iint", arch_opt.vumax);
0032
0033
0034 const TString xtitlevu = "Matriplex Vector Width [floats]";
0035 const TString xtitleth = "Number of Threads";
0036
0037
0038 const TString ytitletime = "Average Build Time per Event [s]";
0039 const TString ytitlespeedup = "Average Build Speedup per Event";
0040
0041
0042 PlotBenchmarks::MakeOverlay("VU_time",
0043 sample + " Vectorization Benchmark on " + arch + " [nTH=" + nth + "]",
0044 xtitlevu,
0045 ytitletime,
0046 arch_opt.vumin,
0047 arch_opt.vumax,
0048 arch_opt.vutimemin,
0049 arch_opt.vutimemax);
0050
0051 PlotBenchmarks::MakeOverlay("TH_time",
0052 sample + " Parallelization Benchmark on " + arch + " [nVU=" + nvu + "]",
0053 xtitleth,
0054 ytitletime,
0055 arch_opt.thmin,
0056 arch_opt.thmax,
0057 arch_opt.thtimemin,
0058 arch_opt.thtimemax);
0059
0060 PlotBenchmarks::MakeOverlay("VU_speedup",
0061 sample + " Vectorization Speedup on " + arch + " [nTH=" + nth + "]",
0062 xtitlevu,
0063 ytitlespeedup,
0064 arch_opt.vumin,
0065 arch_opt.vumax,
0066 arch_opt.vuspeedupmin,
0067 arch_opt.vuspeedupmax);
0068
0069 PlotBenchmarks::MakeOverlay("TH_speedup",
0070 sample + " Parallelization Speedup on " + arch + " [nVU=" + nvu + "]",
0071 xtitleth,
0072 ytitlespeedup,
0073 arch_opt.thmin,
0074 arch_opt.thmax,
0075 arch_opt.thspeedupmin,
0076 arch_opt.thspeedupmax);
0077 }
0078
0079 void PlotBenchmarks::MakeOverlay(const TString& text,
0080 const TString& title,
0081 const TString& xtitle,
0082 const TString& ytitle,
0083 const Double_t xmin,
0084 const Double_t xmax,
0085 const Double_t ymin,
0086 const Double_t ymax) {
0087
0088 const Bool_t isVU = text.Contains("VU", TString::kExact);
0089 const Bool_t isSpeedup = text.Contains("speedup", TString::kExact);
0090
0091
0092 auto canv = new TCanvas();
0093 canv->cd();
0094 canv->SetGridy();
0095 if (!isVU && !isSpeedup)
0096 canv->SetLogy();
0097
0098
0099 const Double_t x1 = (isSpeedup ? 0.20 : 0.60);
0100 const Double_t y1 = 0.65;
0101 const Double_t ylength = builds.size() * 0.05;
0102 auto leg = new TLegend(x1, y1, x1 + 0.25, y1 + ylength);
0103 leg->SetBorderSize(0);
0104
0105
0106 TGEVec graphs(nbuilds);
0107 PlotBenchmarks::GetGraphs(graphs, text, title, xtitle, ytitle);
0108
0109
0110 TGEVec graphs_int(nbuilds);
0111 if (isVU)
0112 PlotBenchmarks::GetGraphs(graphs_int, text + "_int", title, xtitle, ytitle);
0113
0114
0115 for (auto i = 0U; i < nbuilds; i++) {
0116 auto& graph = graphs[i];
0117 auto& graph_int = graphs_int[i];
0118 auto& build = builds[i];
0119
0120
0121 if (graph) {
0122 graph->GetXaxis()->SetRangeUser(xmin, xmax);
0123 graph->GetYaxis()->SetRangeUser(ymin, ymax);
0124 graph->Draw(i > 0 ? "LP SAME" : "ALP");
0125
0126
0127 if (isVU && graph_int) {
0128 graph_int->GetXaxis()->SetRangeUser(xmin, xmax);
0129 graph_int->GetYaxis()->SetRangeUser(ymin, ymax);
0130 graph_int->Draw("P SAME");
0131 }
0132
0133
0134 leg->AddEntry(graph, build.label.Data(), "LP");
0135 }
0136 }
0137
0138
0139 TF1* scaling = NULL;
0140 if (isSpeedup) {
0141 scaling = new TF1("ideal_scaling",
0142 "x",
0143 (isVU ? arch_opt.vumin : arch_opt.thmin),
0144 (isVU ? arch_opt.vuspeedupmax : arch_opt.thspeedupmax));
0145 scaling->SetLineColor(kBlack);
0146 scaling->SetLineStyle(kDashed);
0147 scaling->SetLineWidth(2);
0148 scaling->Draw("SAME");
0149 leg->AddEntry(scaling, "Ideal Scaling", "l");
0150 }
0151
0152
0153 leg->Draw("SAME");
0154
0155
0156 const TString outname = arch + "_" + sample + "_" + text;
0157 canv->SaveAs(outname + ".png");
0158
0159
0160 canv->SetLogx();
0161 for (auto i = 0U; i < nbuilds; i++) {
0162 auto& graph = graphs[i];
0163 auto& graph_int = graphs_int[i];
0164
0165
0166 if (graph) {
0167 graph->GetXaxis()->SetRangeUser(xmin, xmax);
0168 graph->GetYaxis()->SetRangeUser(ymin, ymax);
0169 if (isVU && graph_int) {
0170 graph_int->GetXaxis()->SetRangeUser(xmin, xmax);
0171 graph_int->GetYaxis()->SetRangeUser(ymin, ymax);
0172 }
0173 }
0174 }
0175 canv->Update();
0176 canv->SaveAs(outname + "_logx.png");
0177
0178
0179 for (auto i = 0U; i < nbuilds; i++) {
0180 delete graphs[i];
0181 if (isVU)
0182 delete graphs_int[i];
0183 }
0184 if (isSpeedup)
0185 delete scaling;
0186 delete leg;
0187 delete canv;
0188 }
0189
0190 void PlotBenchmarks::GetGraphs(
0191 TGEVec& graphs, const TString& text, const TString& title, const TString& xtitle, const TString& ytitle) {
0192
0193 const Bool_t isInt = text.Contains("_int", TString::kExact);
0194
0195 for (auto i = 0U; i < nbuilds; i++) {
0196 const auto& build = builds[i];
0197 auto& graph = graphs[i];
0198
0199
0200 graph = (TGraphErrors*)file->Get("g_" + build.name + "_" + text);
0201
0202
0203 if (graph) {
0204 graph->SetTitle(title + ";" + xtitle + ";" + ytitle);
0205
0206 graph->SetLineWidth(2);
0207 graph->SetLineColor(build.color);
0208 graph->SetMarkerStyle(isInt ? kOpenCircle : kFullCircle);
0209 graph->SetMarkerColor(build.color);
0210 }
0211 }
0212 }