Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RooBatchCompute::RunContext Struct Reference

This struct enables passing computation data around between elements of a computation graph.

Separating data and 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.

Memory ownership model

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 doublegetBatch (const RooAbsArg *owner) const
 Check if there is a span of data corresponding to the object passed as owner.
 
RooSpan< const doublegetBatch (const RooArgProxy &proxy) const
 
RooSpan< doublegetWritableBatch (const RooAbsArg *owner)
 Check if there is a writable span of data corresponding to the object passed as owner.
 
RooSpan< doublemakeBatch (const RooAbsArg *owner, std::size_t size)
 Create a writable batch.
 
RooSpan< const doubleoperator[] (const RooAbsArg *owner) const
 Retrieve a batch of data corresponding to the element passed as owner.
 

Public Attributes

std::vector< doublelogProbabilities
 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>

Constructor & Destructor Documentation

◆ RunContext() [1/3]

RooBatchCompute::RunContext::RunContext ( )
inline

Create an empty RunContext that doesn't have access to any computation results.

Definition at line 34 of file RunContext.h.

◆ RunContext() [2/3]

RooBatchCompute::RunContext::RunContext ( const RunContext )
delete

Deleted because copying the owned memory is expensive.

If needed, it can be implemented, though.

Warning
Remember to relocate all spans in spans to new location in ownedMemory after data have been copied!

◆ RunContext() [3/3]

RooBatchCompute::RunContext::RunContext ( RunContext &&  )
default

Move a RunContext. All spans pointing to data retrieved from the original remain valid.

Member Function Documentation

◆ clear()

void RooBatchCompute::RunContext::clear ( )

Clear all computation results without freeing memory.

Definition at line 105 of file RunContext.cxx.

◆ getBatch() [1/2]

RooSpan< const double > RooBatchCompute::RunContext::getBatch ( const RooAbsArg owner) const

Check if there is a span of data corresponding to the object passed as owner.

Definition at line 57 of file RunContext.cxx.

◆ getBatch() [2/2]

RooSpan< const double > RooBatchCompute::RunContext::getBatch ( const RooArgProxy proxy) const

◆ getWritableBatch()

RooSpan< double > RooBatchCompute::RunContext::getWritableBatch ( const RooAbsArg owner)

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.

◆ makeBatch()

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.

Warning
The memory will be uninitialised, so every entry must be overwritten. On first use, all values are initialised to NaN to help detect such errors.

A read-only reference to the memory will be stored in spans.

Parameters
ownerRooFit object whose value should be written into the memory.
sizeRequested size of the span.
Returns
A writeable RooSpan of the requested size, whose memory is owned by the RunContext.

Definition at line 89 of file RunContext.cxx.

◆ operator[]()

RooSpan< const double > RooBatchCompute::RunContext::operator[] ( const RooAbsArg owner) const
inline

Retrieve a batch of data corresponding to the element passed as owner.

Definition at line 45 of file RunContext.h.

Member Data Documentation

◆ logProbabilities

std::vector<double> RooBatchCompute::RunContext::logProbabilities

Possibility to register log probabilities.

Definition at line 61 of file RunContext.h.

◆ ownedMemory

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.

◆ ownedMemoryCuda

std::map<RooFit::Detail::DataKey, double*> RooBatchCompute::RunContext::ownedMemoryCuda

Definition at line 58 of file RunContext.h.

◆ rangeName

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.

◆ spans

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.

◆ spansCuda

std::map<RooFit::Detail::DataKey, const double*> RooBatchCompute::RunContext::spansCuda

Definition at line 54 of file RunContext.h.

Collaboration diagram for RooBatchCompute::RunContext:
[legend]

The documentation for this struct was generated from the following files: