@@ -62,15 +62,22 @@ std::unique_ptr<RooAbsPdf> createModel(RooRealVar &x, std::string const &channel
6262 return std::unique_ptr<RooAbsPdf>{static_cast <RooAbsPdf *>(model.cloneTree ())};
6363}
6464
65+ enum backend {
66+ Reference,
67+ BatchMode,
68+ CodeSquashNumDiff,
69+ CodeSquashAD
70+ };
71+
6572static void BM_RooFuncWrapper_ManyParams_Minimization (benchmark::State &state)
6673{
6774 using namespace RooFit ;
6875
6976 counter++;
7077
71- gInterpreter ->ProcessLine (" gErrorIgnoreLevel = 2001;" );
72- auto &msg = RooMsgService::instance ();
73- msg.setGlobalKillBelow (RooFit::WARNING);
78+ // gInterpreter->ProcessLine("gErrorIgnoreLevel = 2001;");
79+ // auto &msg = RooMsgService::instance();
80+ // msg.setGlobalKillBelow(RooFit::WARNING);
7481
7582 // Generate the same dataset for all backends.
7683 RooRandom::randomGenerator ()->SetSeed (100 );
@@ -117,26 +124,28 @@ static void BM_RooFuncWrapper_ManyParams_Minimization(benchmark::State &state)
117124 RooArgSet origParams;
118125 params.snapshot (origParams);
119126
120- std::unique_ptr<RooAbsReal> nllRef{model.createNLL (data, EvalBackend::Legacy (), Offset (" off" ))};
121- std::unique_ptr<RooAbsReal> nllRefBatch{model.createNLL (data, EvalBackend::Cpu (), Offset (" off" ))};
122- std::unique_ptr<RooAbsReal> nllFunc{model.createNLL (data, EvalBackend::Codegen (), Offset (" off" ))};
123- std::unique_ptr<RooAbsReal> nllFuncNoGrad{model.createNLL (data, EvalBackend::CodegenNoGrad (), Offset (" off" ))};
127+ std::cout << " nparams: " << params.size () << std::endl;
128+
129+ std::unique_ptr<RooAbsReal> nllRef{model.createNLL (data, EvalBackend::Legacy (), Offset (" initial" ))};
130+ std::unique_ptr<RooAbsReal> nllRefBatch{model.createNLL (data, EvalBackend::Cpu (), Offset (" initial" ))};
131+ std::unique_ptr<RooAbsReal> nllFunc{model.createNLL (data, EvalBackend::Codegen (), Offset (" initial" ))};
132+ std::unique_ptr<RooAbsReal> nllFuncNoGrad{model.createNLL (data, EvalBackend::CodegenNoGrad (), Offset (" initial" ))};
124133
125134 std::unique_ptr<RooMinimizer> m = nullptr ;
126135
127136 int code = state.range (0 );
128- if (code == RooFitADBenchmarksUtils:: backend::Reference) {
137+ if (code == backend::Reference) {
129138 m = std::make_unique<RooMinimizer>(*nllRef);
130- } else if (code == RooFitADBenchmarksUtils:: backend::CodeSquashNumDiff) {
139+ } else if (code == backend::CodeSquashNumDiff) {
131140 m = std::make_unique<RooMinimizer>(*nllFuncNoGrad);
132- } else if (code == RooFitADBenchmarksUtils:: backend::BatchMode) {
141+ } else if (code == backend::BatchMode) {
133142 m = std::make_unique<RooMinimizer>(*nllRefBatch);
134- } else if (code == RooFitADBenchmarksUtils:: backend::CodeSquashAD) {
143+ } else if (code == backend::CodeSquashAD) {
135144 m = std::make_unique<RooMinimizer>(*nllFunc);
136145 }
137146
138147 for (auto _ : state) {
139- m->setPrintLevel (-1 );
148+ // m->setPrintLevel(-1);
140149 m->setStrategy (0 );
141150 params.assign (origParams);
142151
@@ -146,7 +155,33 @@ static void BM_RooFuncWrapper_ManyParams_Minimization(benchmark::State &state)
146155
147156int main (int argc, char **argv)
148157{
149- RooFitADBenchmarksUtils::doBenchmarks (BM_RooFuncWrapper_ManyParams_Minimization, 2 , 2 , 1 , 20 );
158+ std::vector<long int > rangeLow{1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 12 , 17 , 23 , 28 , 33 , 38 , 43 , 49 , 54 , 59 };
159+ std::vector<long int > rangeHigh{64 , 70 , 75 , 80 , 85 , 90 , 96 , 100 , 110 , 120 , 130 , 140 ,
160+ 150 , 160 , 170 , 180 , 190 , 200 , 225 , 250 , 275 , 300 , 325 };
161+ std::vector<long int > range;
162+ range.insert (range.end (), rangeLow.begin (), rangeLow.end ());
163+ range.insert (range.end (), rangeHigh.begin (), rangeHigh.end ());
164+
165+ // Run the minimization with the reference NLL
166+ RooFitADBenchmarksUtils::doBenchmarks (" NllReferenceMinimization" , Reference,
167+ BM_RooFuncWrapper_ManyParams_Minimization, range, 1 );
168+
169+ // Run the minimization with the reference NLL (BatchMode)
170+ RooFitADBenchmarksUtils::doBenchmarks (" NllBatchModeMinimization" , BatchMode,
171+ BM_RooFuncWrapper_ManyParams_Minimization, range, 1 );
172+
173+ // Run the minimization with the code-squashed version with AD.
174+ RooFitADBenchmarksUtils::doBenchmarks (" NllCodeSquash_AD" , CodeSquashAD, BM_RooFuncWrapper_ManyParams_Minimization,
175+ range, 1 );
176+ // RooFitADBenchmarksUtils::doBenchmarks("NllCodeSquash_AD", CodeSquashAD,
177+ // BM_RooFuncWrapper_ManyParams_Minimization, {250}, 1);
178+
179+ // Run the minimization with the code-squashed version with numerical-diff.
180+ // We can't go to more than 59 channels here, because since offsetting is
181+ // not supported, the fit will not converge anymore if the number of bins is
182+ // sufficiently high.
183+ RooFitADBenchmarksUtils::doBenchmarks (" NllCodeSquash_NumDiff" , CodeSquashNumDiff,
184+ BM_RooFuncWrapper_ManyParams_Minimization, rangeLow, 1 );
150185
151186 benchmark::Initialize (&argc, argv);
152187 benchmark::RunSpecifiedBenchmarks ();
0 commit comments