Logo ROOT  
Reference Guide
RunContext.h
Go to the documentation of this file.
1// Author: Stephan Hageboeck, CERN Jul 2020
2
3/*****************************************************************************
4 * RooFit
5 * Authors: *
6 * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7 * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8 * *
9 * Copyright (c) 2000-2020, Regents of the University of California *
10 * and Stanford University. All rights reserved. *
11 * *
12 * Redistribution and use in source and binary forms, *
13 * with or without modification, are permitted according to the terms *
14 * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15 *****************************************************************************/
16
17#ifndef ROOFIT_BATCHCOMPUTE_RUNCONTEXT_H
18#define ROOFIT_BATCHCOMPUTE_RUNCONTEXT_H
19
20#include "RooSpan.h"
21
22#include <map>
23#include <vector>
24
25class RooArgSet;
26class RooAbsArg;
27class RooArgProxy;
28
29namespace RooBatchCompute {
30
31struct RunContext {
32 /// Create an empty RunContext that doesn't have access to any computation results.
34 /// Deleted because copying the owned memory is expensive.
35 /// If needed, it can be implemented, though.
36 /// \warning Remember to relocate all spans in `spans` to new location
37 /// in `ownedMemory` after data have been copied!
38 RunContext(const RunContext&) = delete;
39 /// Move a RunContext. All spans pointing to data retrieved from the original remain valid.
40 RunContext(RunContext&&) = default;
42 RooSpan<const double> getBatch(const RooAbsArg* owner) const;
43 /// Retrieve a batch of data corresponding to the element passed as `owner`.
44 RooSpan<const double> operator[](const RooAbsArg* owner) const { return getBatch(owner); }
46 RooSpan<double> makeBatch(const RooAbsArg* owner, std::size_t size);
47
48 /// Clear all computation results without freeing memory.
49 void clear();
50
51 /// Once an object has computed its value(s), the span pointing to the results is registered here.
52 std::map<const RooAbsArg*, RooSpan<const double>> spans;
53 std::map<const RooAbsArg*, const double*> spansCuda;
54
55 /// Memory owned by this struct. It is associated to nodes in the computation graph using their pointers.
56 std::map<const RooAbsArg*, std::vector<double>> ownedMemory;
57 std::map<const RooAbsArg*, double*> ownedMemoryCuda;
58
59 const char* rangeName{nullptr}; ///< If evaluation should only occur in a range, the range name can be passed here.
60 std::vector<double> logProbabilities; ///< Possibility to register log probabilities.
61};
62
63}
64
65#endif
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
Definition: RooAbsArg.h:77
RooArgProxy is the abstract interface for RooAbsArg proxy classes.
Definition: RooArgProxy.h:24
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:57
A simple container to hold a batch of data values.
Definition: RooSpan.h:34
Namespace for dispatching RooFit computations to various backends.
This struct enables passing computation data around between elements of a computation graph.
Definition: RunContext.h:31
const char * rangeName
If evaluation should only occur in a range, the range name can be passed here.
Definition: RunContext.h:59
std::vector< double > logProbabilities
Possibility to register log probabilities.
Definition: RunContext.h:60
RooSpan< double > makeBatch(const RooAbsArg *owner, std::size_t size)
Create a writable batch.
Definition: RunContext.cxx:89
void clear()
Clear all computation results without freeing memory.
Definition: RunContext.cxx:105
RunContext(RunContext &&)=default
Move a RunContext. All spans pointing to data retrieved from the original remain valid.
std::map< const RooAbsArg *, std::vector< double > > ownedMemory
Memory owned by this struct. It is associated to nodes in the computation graph using their pointers.
Definition: RunContext.h:56
RunContext(const RunContext &)=delete
Deleted because copying the owned memory is expensive.
std::map< const RooAbsArg *, const double * > spansCuda
Definition: RunContext.h:53
std::map< const RooAbsArg *, double * > ownedMemoryCuda
Definition: RunContext.h:57
RooSpan< const double > getBatch(const RooArgProxy &proxy) const
std::map< const RooAbsArg *, RooSpan< const double > > spans
Once an object has computed its value(s), the span pointing to the results is registered here.
Definition: RunContext.h:52
RooSpan< const double > operator[](const RooAbsArg *owner) const
Retrieve a batch of data corresponding to the element passed as owner.
Definition: RunContext.h:44
RunContext()
Create an empty RunContext that doesn't have access to any computation results.
Definition: RunContext.h:33
RooSpan< double > getWritableBatch(const RooAbsArg *owner)
Check if there is a writable span of data corresponding to the object passed as owner.
Definition: RunContext.cxx:68