Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Batches.h
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Emmanouil Michalainas, CERN 3 March 2021
5 *
6 * Copyright (c) 2021, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13/**
14\file Batches.h
15\class Batch
16\class Batches
17\ingroup RooBatchCompute
18
19These classes encapsulate the necessary data for the computations.
20They are lightweight objects designed to be passed by value and also flexible,
21so that they can contain data for every kind of compute function.
22**/
23#ifndef ROOFIT_BATCHCOMPUTE_BATCHES_H
24#define ROOFIT_BATCHCOMPUTE_BATCHES_H
25
27
28#include <cstdint>
29
30namespace RooBatchCompute {
31
32constexpr std::size_t bufferSize = 64;
33
34namespace RF_ARCH {
35
36class Batch {
37public:
38 const double *__restrict _array = nullptr;
39 bool _isVector = false;
40
41 Batch() = default;
42 inline Batch(InputArr array, bool isVector) : _array{array}, _isVector{isVector} {}
43
44 __roodevice__ constexpr bool isItVector() const { return _isVector; }
45 inline void set(InputArr array, bool isVector)
46 {
47 _array = array;
48 _isVector = isVector;
49 }
50 inline void advance(std::size_t _nEvents) { _array += _isVector * _nEvents; }
51#ifdef __CUDACC__
52 __roodevice__ constexpr double operator[](std::size_t i) const noexcept { return _isVector ? _array[i] : _array[0]; }
53#else
54 constexpr double operator[](std::size_t i) const noexcept { return _array[i]; }
55#endif // #ifdef __CUDACC__
56};
57
58/////////////////////////////////////////////////////////////////////////////////////////////////////////
59
60class Batches {
61public:
62 Batch *_arrays = nullptr;
63 double *_extraArgs = nullptr;
64 std::size_t _nEvents = 0;
65 std::size_t _nBatches = 0;
66 std::size_t _nExtraArgs = 0;
68
69 __roodevice__ std::size_t getNEvents() const { return _nEvents; }
70 __roodevice__ std::size_t getNExtraArgs() const { return _nExtraArgs; }
71 __roodevice__ double extraArg(std::size_t i) const { return _extraArgs[i]; }
72 __roodevice__ void setExtraArg(std::size_t i, double val) { _extraArgs[i] = val; }
73 __roodevice__ Batch operator[](int batchIdx) const { return _arrays[batchIdx]; }
74 inline void setNEvents(std::size_t n) { _nEvents = n; }
75 inline void advance(std::size_t nEvents)
76 {
77 for (std::size_t i = 0; i < _nBatches; i++)
78 _arrays[i].advance(nEvents);
79 _output += nEvents;
80 }
81};
82
83// Defines the actual argument type of the compute function.
85
86} // End namespace RF_ARCH
87} // end namespace RooBatchCompute
88
89#endif // #ifdef ROOFIT_BATCHCOMPUTE_BATCHES_H
#define __roodevice__
void advance(std::size_t _nEvents)
Definition Batches.h:50
const double *__restrict _array
Definition Batches.h:38
constexpr double operator[](std::size_t i) const noexcept
Definition Batches.h:54
void set(InputArr array, bool isVector)
Definition Batches.h:45
__roodevice__ constexpr bool isItVector() const
Definition Batches.h:44
Batch(InputArr array, bool isVector)
Definition Batches.h:42
__roodevice__ std::size_t getNEvents() const
Definition Batches.h:69
__roodevice__ Batch operator[](int batchIdx) const
Definition Batches.h:73
__roodevice__ std::size_t getNExtraArgs() const
Definition Batches.h:70
void advance(std::size_t nEvents)
Definition Batches.h:75
__roodevice__ void setExtraArg(std::size_t i, double val)
Definition Batches.h:72
__roodevice__ double extraArg(std::size_t i) const
Definition Batches.h:71
void setNEvents(std::size_t n)
Definition Batches.h:74
const Int_t n
Definition legend1.C:16
Namespace for dispatching RooFit computations to various backends.
constexpr std::size_t bufferSize
Definition Batches.h:32
const double *__restrict InputArr
double *__restrict RestrictArr