34 throw std::runtime_error(
"ScalarBufferContainer can only be of size 1");
36 std::size_t
size()
const {
return 1; }
51 std::size_t
size()
const {
return _vec.size(); }
56 throw std::bad_function_call();
63 throw std::bad_function_call();
72class GPUBufferContainer {
74 GPUBufferContainer(std::size_t
size) : _arr(
size) {}
75 std::size_t
size()
const {
return _arr.size(); }
77 double const *cpuReadPtr()
const
79 throw std::bad_function_call();
82 double const *gpuReadPtr()
const {
return _arr.data(); }
84 double *cpuWritePtr()
const
86 throw std::bad_function_call();
89 double *gpuWritePtr()
const {
return const_cast<double *
>(_arr.data()); }
95class PinnedBufferContainer {
97 PinnedBufferContainer(std::size_t
size) : _arr{
size}, _gpuBuffer{
size} {}
98 std::size_t
size()
const {
return _arr.size(); }
100 void setCudaStream(CudaStream *stream) { _cudaStream = stream; }
102 double const *cpuReadPtr()
const
105 if (_lastAccess == LastAccessType::GPU_WRITE) {
110 _lastAccess = LastAccessType::CPU_READ;
111 return const_cast<double *
>(_arr.data());
113 double const *gpuReadPtr()
const
116 if (_lastAccess == LastAccessType::CPU_WRITE) {
120 _lastAccess = LastAccessType::GPU_READ;
121 return _gpuBuffer.gpuReadPtr();
124 double *cpuWritePtr()
126 _lastAccess = LastAccessType::CPU_WRITE;
129 double *gpuWritePtr()
131 _lastAccess = LastAccessType::GPU_WRITE;
132 return _gpuBuffer.gpuWritePtr();
136 enum class LastAccessType { CPU_READ, GPU_READ, CPU_WRITE, GPU_WRITE };
139 GPUBufferContainer _gpuBuffer;
140 CudaStream *_cudaStream =
nullptr;
141 mutable LastAccessType _lastAccess = LastAccessType::CPU_READ;
145template <
class Container>
148 using Queue = std::queue<std::unique_ptr<Container>>;
154 _vec = std::make_unique<Container>(
size);
172 std::unique_ptr<Container>
_vec;
187 GPUBuffer::QueuesMap gpuBufferQueuesMap;
188 PinnedBuffer::QueuesMap pinnedBufferQueuesMap;
194 _queuesMaps = std::make_unique<BufferQueuesMaps>();
201 return std::make_unique<ScalarBuffer>(1,
_queuesMaps->scalarBufferQueuesMap);
205 return std::make_unique<CPUBuffer>(
size,
_queuesMaps->cpuBufferQueuesMap);
208std::unique_ptr<AbsBuffer> BufferManager::makeGpuBuffer(std::size_t
size)
210 return std::make_unique<GPUBuffer>(
size,
_queuesMaps->gpuBufferQueuesMap);
212std::unique_ptr<AbsBuffer> BufferManager::makePinnedBuffer(std::size_t
size, CudaStream *stream)
214 auto out = std::make_unique<PinnedBuffer>(
size,
_queuesMaps->pinnedBufferQueuesMap);
215 out->vec().setCudaStream(stream);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
std::map< std::size_t, Queue > QueuesMap
std::unique_ptr< Container > _vec
double * gpuWritePtr() override
BufferImpl(std::size_t size, QueuesMap &queuesMap)
double * cpuWritePtr() override
double const * gpuReadPtr() const override
std::queue< std::unique_ptr< Container > > Queue
double const * cpuReadPtr() const override
std::unique_ptr< AbsBuffer > makeScalarBuffer()
std::unique_ptr< BufferQueuesMaps > _queuesMaps
std::unique_ptr< AbsBuffer > makeCpuBuffer(std::size_t size)
CPUBufferContainer(std::size_t size)
std::vector< double > _vec
double const * gpuReadPtr() const
double const * cpuReadPtr() const
A templated class for managing an array of data using a specified memory type.
ScalarBufferContainer(std::size_t size)
double const * gpuReadPtr() const
double const * cpuReadPtr() const
void copyDeviceToHost(const T *src, T *dest, std::size_t n, CudaStream *=nullptr)
Copies data from the CUDA device to the host.
void copyHostToDevice(const T *src, T *dest, std::size_t n, CudaStream *=nullptr)
Copies data from the host to the CUDA device.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
ScalarBuffer::QueuesMap scalarBufferQueuesMap
CPUBuffer::QueuesMap cpuBufferQueuesMap