This struct enables passing computation data around between elements of a computation graph.
The RunContext stores read-only spans to data that has already been computed. This can be data of the observables (which is constant during a fit) or intermediate computation results from evaluating PDFs or formulae for every point in a dataset. The latter may change as fit parameters change.
Instead of storing information about these data inside nodes of the computation graph (requiring a change of their state, possibly violating const-correctness), this information is stored in RunContext::spans using the pointer of the element that produced those results as a key. In this way, one or multiple RunContext instances can be passed around when computations are running, leaving the objects of the computation graph invariant.
The RunContext can provide memory for temporary data, that is, data that can vanish after a fit converges. Using RunContext::makeBatch(), a suitable amount of memory is allocated to store computation results. When intermediate data are cleared, this memory is not freed. In this way, temporary data can be invalidated when fit parameters change, but the memory is only allocated once per fit.
When a RunContext goes out of scope, the memory is freed. That means that in between fit cycles, a RunContext should be cleared using clear(), or single results should be invalidated by removing these from RunContext::spans. The RunContext object should be destroyed only after a fit completes.
Definition at line 32 of file RunContext.h.
Public Member Functions | |
RunContext () | |
Create an empty RunContext that doesn't have access to any computation results. | |
RunContext (const RunContext &)=delete | |
Deleted because copying the owned memory is expensive. | |
RunContext (RunContext &&)=default | |
Move a RunContext. All spans pointing to data retrieved from the original remain valid. | |
void | clear () |
Clear all computation results without freeing memory. | |
RooSpan< const double > | getBatch (const RooAbsArg *owner) const |
Check if there is a span of data corresponding to the object passed as owner. | |
RooSpan< const double > | getBatch (const RooArgProxy &proxy) const |
RooSpan< double > | getWritableBatch (const RooAbsArg *owner) |
Check if there is a writable span of data corresponding to the object passed as owner. | |
RooSpan< double > | makeBatch (const RooAbsArg *owner, std::size_t size) |
Create a writable batch. | |
RooSpan< const double > | operator[] (const RooAbsArg *owner) const |
Retrieve a batch of data corresponding to the element passed as owner . | |
Public Attributes | |
std::vector< double > | logProbabilities |
Possibility to register log probabilities. | |
std::map< RooFit::Detail::DataKey, std::vector< double > > | ownedMemory |
Memory owned by this struct. It is associated to nodes in the computation graph using their pointers. | |
std::map< RooFit::Detail::DataKey, double * > | ownedMemoryCuda |
const char * | rangeName {nullptr} |
If evaluation should only occur in a range, the range name can be passed here. | |
std::map< RooFit::Detail::DataKey, RooSpan< const double > > | spans |
Once an object has computed its value(s), the span pointing to the results is registered here. | |
std::map< RooFit::Detail::DataKey, const double * > | spansCuda |
#include <RunContext.h>
|
inline |
Create an empty RunContext that doesn't have access to any computation results.
Definition at line 34 of file RunContext.h.
|
delete |
Deleted because copying the owned memory is expensive.
If needed, it can be implemented, though.
spans
to new location in ownedMemory
after data have been copied!
|
default |
Move a RunContext. All spans pointing to data retrieved from the original remain valid.
void RooBatchCompute::RunContext::clear | ( | ) |
Clear all computation results without freeing memory.
Definition at line 105 of file RunContext.cxx.
Check if there is a span of data corresponding to the object passed as owner.
Definition at line 57 of file RunContext.cxx.
RooSpan< const double > RooBatchCompute::RunContext::getBatch | ( | const RooArgProxy & | proxy | ) | const |
Check if there is a writable span of data corresponding to the object passed as owner.
The span can be used both for reading and writing.
Definition at line 68 of file RunContext.cxx.
RooSpan< double > RooBatchCompute::RunContext::makeBatch | ( | const RooAbsArg * | owner, |
std::size_t | size | ||
) |
Create a writable batch.
If the RunContext already owns memory for the object owner
, just resize the memory. If it doesn't exist yet, allocate it.
NaN
to help detect such errors.A read-only reference to the memory will be stored in spans
.
owner | RooFit object whose value should be written into the memory. |
size | Requested size of the span. |
Definition at line 89 of file RunContext.cxx.
|
inline |
Retrieve a batch of data corresponding to the element passed as owner
.
Definition at line 45 of file RunContext.h.
std::vector<double> RooBatchCompute::RunContext::logProbabilities |
Possibility to register log probabilities.
Definition at line 61 of file RunContext.h.
std::map<RooFit::Detail::DataKey, std::vector<double> > RooBatchCompute::RunContext::ownedMemory |
Memory owned by this struct. It is associated to nodes in the computation graph using their pointers.
Definition at line 57 of file RunContext.h.
std::map<RooFit::Detail::DataKey, double*> RooBatchCompute::RunContext::ownedMemoryCuda |
Definition at line 58 of file RunContext.h.
const char* RooBatchCompute::RunContext::rangeName {nullptr} |
If evaluation should only occur in a range, the range name can be passed here.
Definition at line 60 of file RunContext.h.
std::map<RooFit::Detail::DataKey, RooSpan<const double> > RooBatchCompute::RunContext::spans |
Once an object has computed its value(s), the span pointing to the results is registered here.
Definition at line 53 of file RunContext.h.
std::map<RooFit::Detail::DataKey, const double*> RooBatchCompute::RunContext::spansCuda |
Definition at line 54 of file RunContext.h.