13#ifndef CudaInterface_h
14#define CudaInterface_h
24#define ERRCHECK(err) RooBatchCompute::CudaInterface::checkCudaErrors((err), __func__, __FILE__, __LINE__)
27namespace CudaInterface {
29inline void checkCudaErrors(cudaError_t error, std::string
const &func, std::string
const &file,
int line)
31 if (error != cudaSuccess) {
32 std::stringstream errMsg;
33 errMsg << func <<
"(), " << file <<
":" << std::to_string(
line) <<
" : " << cudaGetErrorString(error);
34 throw std::runtime_error(errMsg.str());
52namespace CudaInterface {
58 void operator()(
void *ptr);
72 inline cudaStream_t *get() {
return reinterpret_cast<cudaStream_t *&
>(
_ptr); }
73 inline operator cudaStream_t() {
return *
reinterpret_cast<cudaStream_t *
>(
_ptr.get()); }
76 std::unique_ptr<void, Deleter<CudaStream>>
_ptr;
80void copyHostToDeviceImpl(
const void *
src,
void *
dest, std::size_t
n,
CudaStream * =
nullptr);
81void copyDeviceToHostImpl(
const void *
src,
void *
dest, std::size_t
n,
CudaStream * =
nullptr);
82void copyDeviceToDeviceImpl(
const void *
src,
void *
dest, std::size_t
n,
CudaStream * =
nullptr);
96 copyHostToDeviceImpl(
src,
dest,
sizeof(T) *
n, stream);
110 copyDeviceToHostImpl(
src,
dest,
sizeof(T) *
n, stream);
124 copyDeviceToDeviceImpl(
src,
dest,
sizeof(T) *
n, stream);
134 DeviceMemory(std::size_t
n, std::size_t typeSize);
136 std::size_t
size()
const {
return _size; }
137 void *
data() {
return _data.get(); }
138 void const *
data()
const {
return _data.get(); }
141 std::unique_ptr<void, Deleter<DeviceMemory>> _data;
142 std::size_t _size = 0;
145class PinnedHostMemory {
147 PinnedHostMemory(std::size_t
n, std::size_t typeSize);
149 std::size_t
size()
const {
return _size; }
150 void *
data() {
return _data.get(); }
151 void const *
data()
const {
return _data.get(); }
154 std::unique_ptr<void, Deleter<PinnedHostMemory>> _data;
155 std::size_t _size = 0;
170template <
class Data_t,
class Memory_t>
186 inline std::size_t
size()
const {
return Memory_t::size(); }
195 inline Data_t *
data() {
return static_cast<Data_t *
>(Memory_t::data()); }
204 inline Data_t
const *
data()
const {
return static_cast<Data_t
const *
>(Memory_t::data()); }
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
A templated class for managing an array of data using a specified memory type.
Array(std::size_t n)
Constructor to create an Array object with a specified size.
Data_t * data()
Get a pointer to the start of the array.
Data_t const * data() const
Get a const pointer to the start of the array.
std::size_t size() const
Get the size of the array.
CudaStream()
Creates a new CUDA stream.
std::unique_ptr< void, Deleter< CudaStream > > _ptr
void copyDeviceToDevice(const T *src, T *dest, std::size_t n, CudaStream *stream=nullptr)
Copies data from the CUDA device to the CUDA device.
void copyHostToDevice(const T *src, T *dest, std::size_t n, CudaStream *stream=nullptr)
Copies data from the host to the CUDA device.
void copyDeviceToHost(const T *src, T *dest, std::size_t n, CudaStream *stream=nullptr)
Copies data from the CUDA device to the host.
Namespace for dispatching RooFit computations to various backends.