diff --git a/roofit/histfactory/inc/RooStats/HistFactory/ParamHistFunc.h b/roofit/histfactory/inc/RooStats/HistFactory/ParamHistFunc.h index 56cd918c42384..b47c79d1f2cc2 100644 --- a/roofit/histfactory/inc/RooStats/HistFactory/ParamHistFunc.h +++ b/roofit/histfactory/inc/RooStats/HistFactory/ParamHistFunc.h @@ -105,7 +105,7 @@ class ParamHistFunc : public RooAbsReal { Int_t addParamSet( const RooArgList& params ); static Int_t GetNumBins( const RooArgSet& vars ); double evaluate() const override; - RooSpan evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* normSet) const override; + void computeBatch(cudaStream_t*, double* output, size_t size, RooBatchCompute::DataMap&) const override; private: static NumBins getNumBinsPerDim(RooArgSet const& vars); diff --git a/roofit/histfactory/inc/RooStats/HistFactory/PiecewiseInterpolation.h b/roofit/histfactory/inc/RooStats/HistFactory/PiecewiseInterpolation.h index e23aa015ab242..cac6d8fd87804 100644 --- a/roofit/histfactory/inc/RooStats/HistFactory/PiecewiseInterpolation.h +++ b/roofit/histfactory/inc/RooStats/HistFactory/PiecewiseInterpolation.h @@ -97,7 +97,7 @@ class PiecewiseInterpolation : public RooAbsReal { std::vector _interpCode; Double_t evaluate() const override; - RooSpan evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* normSet) const override; + void computeBatch(cudaStream_t*, double* output, size_t size, RooBatchCompute::DataMap&) const override; ClassDefOverride(PiecewiseInterpolation,4) // Sum of RooAbsReal objects }; diff --git a/roofit/histfactory/src/ParamHistFunc.cxx b/roofit/histfactory/src/ParamHistFunc.cxx index 2c199b1c0ed6d..acf754427e406 100644 --- a/roofit/histfactory/src/ParamHistFunc.cxx +++ b/roofit/histfactory/src/ParamHistFunc.cxx @@ -586,28 +586,19 @@ Double_t ParamHistFunc::evaluate() const } -//////////////////////////////////////////////////////////////////////////////// -/// Find all bins corresponding to the values of the observables in `evalData`, and evaluate -/// the associated parameters. -/// \param[in,out] evalData Input/output data for evaluating the ParamHistFunc. -/// \param[in] normSet Normalisation set passed on to objects that are serving values to us. -RooSpan ParamHistFunc::evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* normSet) const { +void ParamHistFunc::computeBatch(cudaStream_t*, double* output, size_t size, RooBatchCompute::DataMap& dataMap) const { std::vector oldValues; std::vector> data; - std::size_t batchSize = 0; // Retrieve data for all variables for (auto arg : _dataVars) { const auto* var = static_cast(arg); oldValues.push_back(var->getVal()); - data.push_back(var->getValues(evalData, normSet)); - batchSize = std::max(batchSize, data.back().size()); + data.push_back(dataMap[var]); } // Run computation for each entry in the dataset - RooSpan output = evalData.makeBatch(this, batchSize); - - for (std::size_t i = 0; i < batchSize; ++i) { + for (std::size_t i = 0; i < size; ++i) { for (unsigned int j = 0; j < _dataVars.size(); ++j) { assert(i < data[j].size()); auto& var = static_cast(_dataVars[j]); @@ -624,8 +615,6 @@ RooSpan ParamHistFunc::evaluateSpan(RooBatchCompute::RunContext& evalDat auto& var = static_cast(_dataVars[j]); var.setCachedValue(oldValues[j], /*notifyClients=*/false); } - - return output; } //////////////////////////////////////////////////////////////////////////////// diff --git a/roofit/histfactory/src/PiecewiseInterpolation.cxx b/roofit/histfactory/src/PiecewiseInterpolation.cxx index 0c35e85f7550c..6df1736bc8215 100644 --- a/roofit/histfactory/src/PiecewiseInterpolation.cxx +++ b/roofit/histfactory/src/PiecewiseInterpolation.cxx @@ -318,15 +318,16 @@ Double_t PiecewiseInterpolation::evaluate() const /// Interpolate between input distributions for all values of the observable in `evalData`. /// \param[in,out] evalData Struct holding spans pointing to input data. The results of this function will be stored here. /// \param[in] normSet Arguments to normalise over. -RooSpan PiecewiseInterpolation::evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* normSet) const { - auto nominal = _nominal->getValues(evalData, normSet); - auto sum = evalData.makeBatch(this, nominal.size()); - std::copy(nominal.begin(), nominal.end(), sum.begin()); +void PiecewiseInterpolation::computeBatch(cudaStream_t*, double* sum, size_t /*size*/, RooBatchCompute::DataMap& dataMap) const { + auto nominal = dataMap[&*_nominal]; + for(unsigned int j=0; j < nominal.size(); ++j) { + sum[j] = nominal[j]; + } for (unsigned int i=0; i < _paramSet.size(); ++i) { const double param = static_cast(_paramSet.at(i))->getVal(); - auto low = static_cast(_lowSet.at(i) )->getValues(evalData, normSet); - auto high = static_cast(_highSet.at(i))->getValues(evalData, normSet); + auto low = dataMap[_lowSet.at(i)]; + auto high = dataMap[_highSet.at(i)]; const int icode = _interpCode[i]; switch(icode) { @@ -436,13 +437,11 @@ RooSpan PiecewiseInterpolation::evaluateSpan(RooBatchCompute::RunContext } if (_positiveDefinite) { - for (double& val : sum) { - if (val < 0.) - val = 0.; + for(unsigned int j=0; j < nominal.size(); ++j) { + if (sum[j] < 0.) + sum[j] = 0.; } } - - return sum; } //////////////////////////////////////////////////////////////////////////////// diff --git a/roofit/roofitcore/inc/RooBinWidthFunction.h b/roofit/roofitcore/inc/RooBinWidthFunction.h index 3548d14ee8c16..1cf717f27e75a 100644 --- a/roofit/roofitcore/inc/RooBinWidthFunction.h +++ b/roofit/roofitcore/inc/RooBinWidthFunction.h @@ -71,7 +71,7 @@ class RooBinWidthFunction : public RooAbsReal { bool divideByBinWidth() const { return _divideByBinWidth; } const RooHistFunc& histFunc() const { return (*_histFunc); } double evaluate() const override; - RooSpan evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* normSet) const override; + void computeBatch(cudaStream_t*, double* output, size_t size, RooBatchCompute::DataMap&) const override; private: RooTemplateProxy _histFunc; diff --git a/roofit/roofitcore/inc/RooHistFunc.h b/roofit/roofitcore/inc/RooHistFunc.h index 3859e9aa22f2d..0752f3ee34d46 100644 --- a/roofit/roofitcore/inc/RooHistFunc.h +++ b/roofit/roofitcore/inc/RooHistFunc.h @@ -86,7 +86,7 @@ class RooHistFunc : public RooAbsReal { Int_t getBin() const; - std::vector getBins(RooBatchCompute::RunContext& evalData) const; + std::vector getBins(RooBatchCompute::DataMap& dataMap) const; protected: @@ -94,7 +94,7 @@ class RooHistFunc : public RooAbsReal { Bool_t areIdentical(const RooDataHist& dh1, const RooDataHist& dh2) ; Double_t evaluate() const override; - RooSpan evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* /*normSet*/) const override; + void computeBatch(cudaStream_t*, double* output, size_t size, RooBatchCompute::DataMap&) const override; friend class RooAbsCachedReal ; void ioStreamerPass2() override ; diff --git a/roofit/roofitcore/src/RooBinWidthFunction.cxx b/roofit/roofitcore/src/RooBinWidthFunction.cxx index ffbafccf639fb..204b5427d43cd 100644 --- a/roofit/roofitcore/src/RooBinWidthFunction.cxx +++ b/roofit/roofitcore/src/RooBinWidthFunction.cxx @@ -46,22 +46,18 @@ double RooBinWidthFunction::evaluate() const { /// Compute bin index for all values of the observable(s) in `evalData`, and return their volumes or inverse volumes, depending /// on the configuration chosen in the constructor. /// If a bin is not valid, return a volume of 1. -RooSpan RooBinWidthFunction::evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* /*normSet*/) const { +void RooBinWidthFunction::computeBatch(cudaStream_t*, double* output, size_t, RooBatchCompute::DataMap& dataMap) const { const RooDataHist& dataHist = _histFunc->dataHist(); - std::vector bins = _histFunc->getBins(evalData); + std::vector bins = _histFunc->getBins(dataMap); auto volumes = dataHist.binVolumes(0, dataHist.numEntries()); - auto results = evalData.makeBatch(this, bins.size()); - if (_divideByBinWidth) { for (std::size_t i=0; i < bins.size(); ++i) { - results[i] = bins[i] >= 0 ? 1./volumes[bins[i]] : 1.; + output[i] = bins[i] >= 0 ? 1./volumes[bins[i]] : 1.; } } else { for (std::size_t i=0; i < bins.size(); ++i) { - results[i] = bins[i] >= 0 ? volumes[bins[i]] : 1.; + output[i] = bins[i] >= 0 ? volumes[bins[i]] : 1.; } } - - return results; } diff --git a/roofit/roofitcore/src/RooFitDriver.cxx b/roofit/roofitcore/src/RooFitDriver.cxx index 5d12b584894b5..e200fbd498265 100644 --- a/roofit/roofitcore/src/RooFitDriver.cxx +++ b/roofit/roofitcore/src/RooFitDriver.cxx @@ -223,7 +223,7 @@ void RooFitDriver::init() // Some checks and logging of used architectures { auto log = [](std::string_view message) { - oocxcoutI(static_cast(nullptr), FastEvaluations) << message << std::endl; + oocxcoutI(static_cast(nullptr), Fitting) << message << std::endl; }; if (_batchMode == RooFit::BatchModeOption::Cuda && !RooBatchCompute::dispatchCUDA) { diff --git a/roofit/roofitcore/src/RooHistFunc.cxx b/roofit/roofitcore/src/RooHistFunc.cxx index df34dfb4e2405..cda3206b5b92c 100644 --- a/roofit/roofitcore/src/RooHistFunc.cxx +++ b/roofit/roofitcore/src/RooHistFunc.cxx @@ -202,26 +202,19 @@ Double_t RooHistFunc::evaluate() const } -//////////////////////////////////////////////////////////////////////////////// -/// Compute value of the HistFunc for every entry in `evalData`. -/// \param[in,out] evalData Struct with input data. The computation results will be stored here. -RooSpan RooHistFunc::evaluateSpan(RooBatchCompute::RunContext& evalData, const RooArgSet* /*normSet*/) const { +void RooHistFunc::computeBatch(cudaStream_t*, double* output, size_t size, RooBatchCompute::DataMap& dataMap) const { std::vector> inputValues; - std::size_t batchSize = 0; for (const auto& obs : _depList) { auto realObs = dynamic_cast(obs); if (realObs) { - auto inputs = realObs->getValues(evalData, nullptr); - batchSize = std::max(batchSize, inputs.size()); + auto inputs = dataMap[realObs]; inputValues.push_back(std::move(inputs)); } else { inputValues.emplace_back(); } } - auto results = evalData.makeBatch(this, batchSize); - - for (std::size_t i = 0; i < batchSize; ++i) { + for (std::size_t i = 0; i < size; ++i) { bool skip = false; for (auto j = 0u; j < _histObsList.size(); ++j) { @@ -236,10 +229,8 @@ RooSpan RooHistFunc::evaluateSpan(RooBatchCompute::RunContext& evalData, } } - results[i] = skip ? 0. : _dataHist->weightFast(_histObsList, _intOrder, false, _cdfBoundaries); + output[i] = skip ? 0. : _dataHist->weightFast(_histObsList, _intOrder, false, _cdfBoundaries); } - - return results; } @@ -606,12 +597,12 @@ Int_t RooHistFunc::getBin() const { //////////////////////////////////////////////////////////////////////////////// /// Compute bin numbers corresponding to all coordinates in `evalData`. /// \return Vector of bin numbers. If a bin is not in the current range of the observables, return -1. -std::vector RooHistFunc::getBins(RooBatchCompute::RunContext& evalData) const { +std::vector RooHistFunc::getBins(RooBatchCompute::DataMap& dataMap) const { std::vector> depData; for (const auto dep : _depList) { auto real = dynamic_cast(dep); if (real) { - depData.push_back(real->getValues(evalData, nullptr)); + depData.push_back(dataMap[real]); } else { depData.emplace_back(nullptr, 0); }