Skip to content

Commit 33ea434

Browse files
committed
[RF] Use checkpointing for loops in codegen
This reduces gradient JIT time by 25 % for Higgs combination models and also makes the generated gradient faster.
1 parent b337e97 commit 33ea434

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

roofit/codegen/src/CodegenImpl.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ void codegenImpl(RooRealIntegral &arg, CodegenContext &ctx)
629629
<< " const int n = 1000; // number of sampling points\n"
630630
<< " double d = " << intVar.getMax(arg.intRange()) << " - " << intVar.getMin(arg.intRange()) << ";\n"
631631
<< " double eps = d / n;\n"
632+
<< " #pragma clad checkpoint loop\n"
632633
<< " for (int i = 0; i < n; ++i) {\n"
633634
<< " " << obsName << "[0] = " << intVar.getMin(arg.intRange()) << " + eps * i;\n"
634635
<< " double tmpA = " << funcName << "(params, " << obsName << ", xlArr);\n"

roofit/roofitcore/inc/RooFit/Detail/MathFuncs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ template <typename DoubleArray>
177177
double constraintSum(DoubleArray comp, unsigned int compSize)
178178
{
179179
double sum = 0;
180+
#ifdef __CLING__
181+
#pragma clad checkpoint loop
182+
#endif
180183
for (unsigned int i = 0; i < compSize; i++) {
181184
sum -= std::log(comp[i]);
182185
}
@@ -364,6 +367,9 @@ double flexibleInterp(unsigned int code, ParamsArray params, unsigned int n, Dou
364367
double boundary, double nominal, int doCutoff)
365368
{
366369
double total = nominal;
370+
#ifdef __CLING__
371+
#pragma clad checkpoint loop
372+
#endif
367373
for (std::size_t i = 0; i < n; ++i) {
368374
total += flexibleInterpSingle(code, low[i], high[i], boundary, nominal, params[i], total);
369375
}

roofit/roofitcore/src/RooFit/CodegenContext.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ std::unique_ptr<CodegenContext::LoopScope> CodegenContext::beginLoop(RooAbsArg c
186186
}
187187

188188
// Make sure that the name of this variable doesn't clash with other stuff
189+
addToCodeBody(in, "#pragma clad checkpoint loop\n");
189190
addToCodeBody(in, "for(int " + idx + " = 0; " + idx + " < " + std::to_string(numEntries) + "; " + idx + "++) {\n");
190191

191192
return std::make_unique<LoopScope>(*this, std::move(vars));

0 commit comments

Comments
 (0)