-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[RF] Implement RooFormulaVar and RooGenericPdf evalutation path without TFormula #23209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
guitargeek
wants to merge
5
commits into
root-project:master
Choose a base branch
from
guitargeek:roofit-jit-free-formula
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+4,728
−23
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
40f65c4
[RF] Add JIT-free AST evaluator for RooFormula
guitargeek d8e80c9
[RF] Emit C++ from RooFormula AST for codegen and AD
guitargeek 0e79371
[RF] Add differential and workspace-IO tests for the formula AST eval…
guitargeek 9760a19
[RF] Add regression test for cling OOM with many formulas (#21052)
guitargeek 2107291
[RF] Vectorize batch evaluation of RooFormula AST programs
guitargeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * Project: RooFit | ||
| * | ||
| * Copyright (c) 2026, CERN | ||
| * | ||
| * Redistribution and use in source and binary forms, | ||
| * with or without modification, are permitted according to the terms | ||
| * listed in LICENSE (http://roofit.sourceforge.net/license.txt) | ||
| */ | ||
|
|
||
| #ifndef ROOFIT_BATCHCOMPUTE_ROOEXPRPROGRAM_H | ||
| #define ROOFIT_BATCHCOMPUTE_ROOEXPRPROGRAM_H | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
|
|
||
| namespace RooBatchCompute { | ||
|
|
||
| /// Opcodes of the postfix expression programs compiled by RooFit's JIT-free | ||
| /// formula backend (see RooFormulaParser in RooFitCore). The same instruction | ||
| /// sequence drives both the scalar per-event evaluation in RooFitCore and the | ||
| /// chunked, vectorized batch evaluation in | ||
| /// RooBatchComputeInterface::computeExprProgram(). | ||
| enum class ExprOp : std::uint8_t { | ||
| Const, ///< push konst | ||
| Var, ///< push vars[arg] | ||
| Add, ///< a + b | ||
| Sub, ///< a - b | ||
| Mul, ///< a * b | ||
| Div, ///< a / b | ||
| Neg, ///< -a | ||
| Not, ///< !a (exactly 0.0 or 1.0) | ||
| LT, ///< a < b (exactly 0.0 or 1.0, likewise below) | ||
| LE, ///< a <= b | ||
| GT, ///< a > b | ||
| GE, ///< a >= b | ||
| EQ, ///< a == b | ||
| NE, ///< a != b | ||
| And, ///< a && b (no short-circuit: both operands are always evaluated) | ||
| Or, ///< a || b (no short-circuit) | ||
| Select, ///< c ? a : b (both branches are always evaluated) | ||
| Pow, ///< std::pow(a, b), from the `^`/`**` operator or pow() | ||
| Sq, ///< a * a, from TFormula's `expr^2` -> TMath::Sq(expr) rewrite | ||
| IntNorm, ///< a + 0.0: maps -0.0 to +0.0 where cling would have used integer arithmetic | ||
| // Unary calls whose semantics are exactly the corresponding std/libm | ||
| // function, split out from Call1 so that batch backends can substitute a | ||
| // fast vectorizable implementation (VDT, hardware sqrt). fn1 carries the | ||
| // exact scalar function, which is what per-event evaluation calls. | ||
| Exp, ///< std::exp(a) | ||
| Log, ///< std::log(a) | ||
| Sin, ///< std::sin(a) | ||
| Cos, ///< std::cos(a) | ||
| Sqrt, ///< std::sqrt(a) | ||
| Call1, ///< fn1(a) | ||
| Call2, ///< fn2(a, b) | ||
| Call3, ///< fn3(a, b, c) | ||
| Call4 ///< fn4(a, b, c, d) | ||
| }; | ||
|
|
||
| /// One instruction of a postfix expression program. Call instructions carry | ||
| /// the resolved function pointer, so evaluation involves no lookup table; | ||
| /// `arg` additionally keeps the index into RooFitCore's function allow-list | ||
| /// (RooFormulaFunctions) that the call was resolved from, which C++ emission | ||
| /// uses to reproduce the exact spelling. | ||
| struct ExprInstr { | ||
| ExprOp op = ExprOp::Const; | ||
| std::uint32_t arg = 0; ///< Var: variable index; calls: function-table index | ||
| union { | ||
| double konst = 0.0; ///< Const | ||
| double (*fn1)(double); ///< Call1 and Exp...Sqrt | ||
| double (*fn2)(double, double); ///< Call2 | ||
| double (*fn3)(double, double, double); ///< Call3 | ||
| double (*fn4)(double, double, double, double); ///< Call4 | ||
| }; | ||
| }; | ||
|
|
||
| /// Maximum expression stack depth accepted by computeExprProgram(), which | ||
| /// stack-allocates one bufferSize-sized chunk buffer per stack slot. Deeper | ||
| /// programs must be evaluated with the scalar per-event fallback. | ||
| constexpr std::uint32_t maxExprProgramStackDepth = 24; | ||
|
|
||
| } // End namespace RooBatchCompute | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
side note: https://www.partow.net/programming/exprtk/index.html
is being used by tree/dataframe and is maybe helpful for some of this stuff.