36#error "RF_ARCH should always be defined"
62#error "It's unexpected that _QUOTEVAL_ is defined at this point!"
64#define _QUOTEVAL_(x) _QUOTE_(x)
67 std::transform(out.begin(), out.end(), out.begin(), [](
unsigned char c) { return std::tolower(c); });
84 static std::vector<double> buffer;
91 std::size_t nEventsPerThread = nEvents / nThreads + (nEvents % nThreads > 0);
94 nThreads = nEvents / nEventsPerThread + (nEvents % nEventsPerThread > 0);
96 auto task = [&](std::size_t idx) ->
int {
99 Batches batches(
output, nEventsPerThread, vars, extraArgs, buffer.data());
103 if (idx == nThreads - 1) {
119 std::vector<std::size_t> indices(nThreads);
120 for (
unsigned int i = 1; i < nThreads; i++) {
123 ex.Map(task, indices);
127 Batches batches(
output, nEvents, vars, extraArgs, buffer.data());
149inline std::pair<double, double> getLog(
double prob,
ReduceNLLOutput &out)
151 if (std::abs(prob) > 1e6) {
157 return {std::log(prob), -prob};
160 if (std::isnan(prob)) {
165 return {std::log(prob), 0.0};
181 double badness = 0.0;
183 for (std::size_t i = 0; i < probas.size(); ++i) {
185 const double eventWeight = weightSpan.
size() > 1 ? weightSpan[i] : weightSpan[0];
187 if (0. == eventWeight)
190 std::pair<double, double> logOut = getLog(probas[i], out);
191 double term = logOut.first;
192 badness += logOut.second;
194 if (!binVolumes.
empty()) {
195 term -= std::log(weights[i]) - std::log(binVolumes[i]) - std::log(weightSum);
198 term *= -eventWeight;
224 : _extraArgs{extraArgs.
data()},
226 _nBatches(vars.
size()),
227 _nExtraArgs(extraArgs.
size()),
230 _arrays.resize(vars.size());
231 for (
size_t i = 0; i < vars.size(); i++) {
234 std::stringstream ss;
235 ss <<
"The span number " << i <<
" passed to Batches::Batches() is empty!";
236 throw std::runtime_error(ss.str());
237 }
else if (span.
size() > 1)
238 _arrays[i].set(span.
data()[0], span.
data(),
true);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
This class implements the interface to execute the same task multiple times, sequentially or in paral...
unsigned GetPoolSize() const
Return the number of pooled workers.
The Kahan summation is a compensated summation algorithm, which significantly reduces numerical error...
static KahanSum< T, N > Accumulate(Iterator begin, Iterator end, T initialValue=T{})
Iterate over a range and return an instance of a KahanSum.
void Add(T x)
Single-element accumulation. Will not vectorise.
Batches(RestrictArr output, std::size_t nEvents, const VarVector &vars, ArgVector &extraArgs, double *buffer=nullptr)
__roodevice__ std::size_t getNEvents() const
void advance(std::size_t nEvents)
void setNEvents(std::size_t n)
This class overrides some RooBatchComputeInterface functions, for the purpose of providing a CPU spec...
std::string architectureName() const override
ReduceNLLOutput reduceNLL(cudaStream_t *, RooSpan< const double > probas, RooSpan< const double > weightSpan, RooSpan< const double > weights, double weightSum, RooSpan< const double > binVolumes) override
double reduceSum(cudaStream_t *, InputArr input, size_t n) override
Return the sum of an input array.
void compute(cudaStream_t *, Computer computer, RestrictArr output, size_t nEvents, const VarVector &vars, ArgVector &extraArgs) override
Compute multiple values using optimized functions.
Architecture architecture() const override
const std::vector< void(*)(BatchesHandle)> _computeFunctions
The interface which should be implemented to provide optimised computation functions for implementati...
A simple container to hold a batch of data values.
constexpr std::size_t size() const noexcept
constexpr std::span< T >::pointer data() const
constexpr bool empty() const noexcept
Bool_t IsImplicitMTEnabled()
Returns true if the implicit multi-threading in ROOT is enabled.
static RooBatchComputeClass computeObj
Static object to trigger the constructor which overwrites the dispatch pointer.
std::vector< void(*)(BatchesHandle)> getFunctions()
Returns a std::vector of pointers to the compute functions in this file.
Namespace for dispatching RooFit computations to various backends.
std::vector< RooSpan< const double > > VarVector
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
constexpr std::size_t bufferSize
const double *__restrict InputArr
std::vector< double > ArgVector
double *__restrict RestrictArr
ROOT::Math::KahanSum< double > nllSum
std::size_t nNonPositiveValues
__roodevice__ static __roohost__ double packFloatIntoNaN(float payload)
Pack float into mantissa of a NaN.
static float unpackNaN(double val)
If val is NaN and a this NaN has been tagged as containing a payload, unpack the float from the manti...