Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-02-21 23:14:23

0001 #include "TString.h"
0002 #include "TColor.h"
0003 #include "TStyle.h"
0004 #include "TGraph.h"
0005 #include "TLegend.h"
0006 #include "TCanvas.h"
0007 
0008 #include <iostream>
0009 #include <vector>
0010 
0011 ///////////////////////
0012 // Structs for macro //
0013 ///////////////////////
0014 
0015 struct setStruct {
0016   setStruct() {}
0017   setStruct(const TString& label, const Double_t x) : label(label), x(x) {}
0018 
0019   TString label;
0020   UInt_t x;
0021 };
0022 
0023 struct xyStruct {
0024   xyStruct() {}
0025   xyStruct(const Double_t x, const Double_t y) : x(x), y(y) {}
0026 
0027   Double_t x;
0028   Double_t y;
0029 };
0030 
0031 struct testStruct {
0032   testStruct() {}
0033   testStruct(const TString& label, const Color_t color) : label(label), color(color) {}
0034 
0035   TString label;
0036   Color_t color;
0037 
0038   std::vector<xyStruct> xyPoints;
0039   TGraph* graph;
0040 };
0041 
0042 ////////////////
0043 // Main Macro //
0044 ////////////////
0045 
0046 void plotStress(const TString& infile_name, const TString& graph_label, const TString& outfile_name) {
0047   // no stats boxes
0048   gStyle->SetOptStat(0);
0049 
0050   // which tests to plot
0051   std::vector<testStruct> tests = {{"nTH1_nEV1", kBlue},
0052                                    {"nTH16_nEV16", kRed + 1},
0053                                    {"nTH32_nEV16", kGreen + 1},
0054                                    {"nTH32_nEV32", kMagenta},
0055                                    {"nTH64_nEV32", kOrange + 1},
0056                                    {"nTH64_nEV64", kBlack},
0057                                    {"nJOB32", kViolet - 1},
0058                                    {"nJOB64", kAzure + 10}};
0059 
0060   // which instruction sets (nVU) to use
0061   std::vector<setStruct> sets = {{"SSE3", 4}, {"AVX2", 8}, {"AVX512", 16}};
0062 
0063   // make label for x-axis
0064   const auto nset = sets.size();
0065   TString set_label;
0066   for (auto iset = 0U; iset < nset; iset++) {
0067     const auto& set = sets[iset];
0068     set_label += Form(" %s (x=%i)%s", set.label.Data(), set.x, (iset + 1 != nset ? "," : ""));
0069   }
0070 
0071   // read input file, fill testStruct vector
0072   std::ifstream input(infile_name.Data(), std::ios::in);
0073   TString test_set_label;
0074   Double_t y;
0075 
0076   // hacky read-in, but sufficient for small number of tests
0077   while (input >> test_set_label >> y) {
0078     for (auto& test : tests) {
0079       if (test_set_label.Contains(test.label)) {
0080         for (const auto& set : sets) {
0081           if (test_set_label.Contains(set.label)) {
0082             test.xyPoints.emplace_back(set.x, y);
0083             break;
0084           }  // end check over input label contains given instruction set label
0085         }    // end loop over instruction set labels
0086       }      // end check over input label contains given test label
0087     }        // end loop over instruction test labels
0088   }          // end loop over reading input file
0089 
0090   // setup canvas
0091   auto canv = new TCanvas();
0092   canv->cd();
0093   canv->SetTickx(1);
0094   canv->SetTicky(1);
0095   canv->SetGridy(1);
0096 
0097   // setup legend
0098   auto leg = new TLegend(0.77, 0.8, 0.99, 0.99);
0099   leg->SetNColumns(2);
0100 
0101   // loop tests, fill graphs, add to canvas + legend
0102   for (auto itest = 0U; itest < tests.size(); itest++) {
0103     // get test result
0104     auto& test = tests[itest];
0105 
0106     // get test info (points, label, color, graph)
0107     const auto& xyPoints = test.xyPoints;
0108     const auto& label = test.label;
0109     const auto color = test.color;
0110     auto& graph = test.graph;
0111 
0112     // make new graph, set style
0113     graph = new TGraph(test.xyPoints.size());
0114     graph->SetTitle("Time vs ISA Ext " + graph_label);
0115     graph->SetLineColor(color);
0116     graph->SetMarkerColor(color);
0117     graph->SetMarkerStyle(kFullCircle);
0118     graph->SetMarkerSize(1);
0119 
0120     // add graph points
0121     for (auto ixyPoint = 0U; ixyPoint < xyPoints.size(); ixyPoint++) {
0122       const auto& xyPoint = xyPoints[ixyPoint];
0123       graph->SetPoint(ixyPoint, xyPoint.x, xyPoint.y);
0124     }
0125 
0126     // draw graph
0127     graph->Draw(itest > 0 ? "CP SAME" : "ACP");
0128 
0129     // graphs can only set x-y axis info after being drawn
0130     graph->GetXaxis()->SetRangeUser(0, 20);
0131     graph->GetYaxis()->SetRangeUser(0, 0.2);
0132     graph->GetXaxis()->SetTitle("Floats in 1 vector [ISA Extensions: " + set_label + "]");
0133     graph->GetYaxis()->SetTitle("Time / evt / physical core [s]");
0134 
0135     // add graph to leg
0136     leg->AddEntry(graph, label.Data(), "lp");
0137   }
0138 
0139   // draw leg
0140   leg->Draw("same");
0141 
0142   // save it
0143   canv->SaveAs(outfile_name.Data());
0144 
0145   // delete it all
0146   for (auto& test : tests)
0147     delete test.graph;
0148   delete leg;
0149   delete canv;
0150 }