Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Evaluator.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN 2021
5 * Emmanouil Michalainas, CERN 2021
6 *
7 * Copyright (c) 2023, CERN
8 *
9 * Redistribution and use in source and binary forms,
10 * with or without modification, are permitted according to the terms
11 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
12 */
13
14#ifndef RooFit_Evaluator_h
15#define RooFit_Evaluator_h
16
17#include <RooAbsReal.h>
18#include <RooFit/EvalContext.h>
19
20#include <ROOT/RConfig.hxx>
21
22#include <memory>
23
25class RooAbsArg;
26
27namespace RooBatchCompute {
28class AbsBufferManager;
29namespace CudaInterface {
30class CudaStream;
31}
32} // namespace RooBatchCompute
33
34namespace RooFit {
35
36struct NodeInfo;
37
38class Evaluator {
39public:
40 Evaluator(const RooAbsReal &absReal, bool useGPU = false);
41 ~Evaluator();
42
43 std::span<const double> run();
44 void setInput(std::string const &name, std::span<const double> inputArray, bool isOnDevice);
46 void print(std::ostream &os);
47
48 void setNThreads(int nThreads);
49
51
52 std::unique_ptr<ChangeOperModeRAII> setOperModes(RooAbsArg::OperMode opMode);
53
54private:
58 std::span<const double> getValHeterogeneous();
59 void markGPUNodes();
61 void computeCPUNode(const RooAbsArg *node, NodeInfo &info);
63 void syncDataTokens();
64 void updateOutputSizes();
65
66 std::unique_ptr<RooBatchCompute::AbsBufferManager> _bufferManager;
68 const bool _useGPU = false;
73 std::vector<NodeInfo> _nodes; // the ordered computation graph
74 std::unordered_map<TNamed const *, NodeInfo *> _nodesMap; // for quick lookup of nodes
75 std::unique_ptr<ChangeOperModeRAII> _operModeChanges;
76 // the single CUDA stream on which all GPU work of this Evaluator is enqueued
78};
79
80} // end namespace RooFit
81
82#endif
char name[80]
Definition TGX11.cxx:142
Scope guard that temporarily changes the operation mode of one or more RooAbsArg instances.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
Definition RooAbsArg.h:76
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:24
Evaluates a RooAbsReal object in other ways than recursive graph traversal.
Definition Evaluator.h:38
void print(std::ostream &os)
void setClientsDirty(NodeInfo &nodeInfo)
Flags all the clients of a given node dirty.
std::unique_ptr< ChangeOperModeRAII > setOperModes(RooAbsArg::OperMode opMode)
RooArgSet getParameters() const
Gets all the parameters of the RooAbsReal.
void setOffsetMode(RooFit::EvalContext::OffsetMode)
Sets the offset mode for evaluation.
void syncDataTokens()
If there are servers with the same name that got de-duplicated in the _nodes list,...
const bool _useGPU
Definition Evaluator.h:68
std::unordered_map< TNamed const *, NodeInfo * > _nodesMap
Definition Evaluator.h:74
std::unique_ptr< ChangeOperModeRAII > _operModeChanges
Definition Evaluator.h:75
std::vector< NodeInfo > _nodes
Definition Evaluator.h:73
bool _needToUpdateOutputSizes
Definition Evaluator.h:70
std::span< const double > getValHeterogeneous()
Returns the value of the top node in the computation graph.
std::span< const double > run()
Returns the value of the top node in the computation graph.
Evaluator(const RooAbsReal &absReal, bool useGPU=false)
Construct a new Evaluator.
void setNThreads(int nThreads)
Sets the number of threads to use for the evaluation of a single node.
void processVariable(NodeInfo &nodeInfo)
Process a variable in the computation graph.
void processCategory(NodeInfo &nodeInfo)
Process a category in the computation graph.
RooBatchCompute::CudaInterface::CudaStream * _cudaStream
Definition Evaluator.h:77
std::unique_ptr< RooBatchCompute::AbsBufferManager > _bufferManager
Definition Evaluator.h:66
void markGPUNodes()
Decides which nodes are assigned to the GPU in a CUDA fit.
void assignToGPU(NodeInfo &info)
Enqueue the computation of a node on the GPU.
void setInput(std::string const &name, std::span< const double > inputArray, bool isOnDevice)
RooFit::EvalContext _evalContextCUDA
Definition Evaluator.h:72
RooFit::EvalContext _evalContextCPU
Definition Evaluator.h:71
void computeCPUNode(const RooAbsArg *node, NodeInfo &info)
void setOperMode(RooAbsArg *arg, RooAbsArg::OperMode opMode)
Temporarily change the operation mode of a RooAbsArg until the Evaluator gets deleted.
RooAbsReal & _topNode
Definition Evaluator.h:67
Namespace for dispatching RooFit computations to various backends.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:73
A struct used by the Evaluator to store information on the RooAbsArgs in the computation graph.
Definition Evaluator.cxx:97