Go to the documentation of this file.
18 #include <type_traits>
26 template <
class R,
class T>
27 concept
HostRange = std::ranges::contiguous_range<R> && std::ranges::sized_range<R> &&
28 std::is_same_v<T, std::ranges::range_value_t<R>>;
41 template <TriviallyCopyable T>
52 template <HostRange<T> R>
62 template <HostRange<T> R>
97 template <TriviallyCopyable T>
101 , m_size( len * sizeof( T ) )
103 stream.registerDependency();
106 template <TriviallyCopyable T>
108 : m_ptr( static_cast<T*>(
111 , m_size( len * sizeof( T ) )
114 template <TriviallyCopyable T>
116 if ( m_stream ==
nullptr ) {
121 m_stream->removeDependency();
124 template <TriviallyCopyable T>
125 template <HostRange<T> R>
129 if ( m_stream !=
nullptr ) {
130 m_stream->parent()->error() <<
"Host to device copy with mismatched sizes: " <<
std::ranges::size( src )
131 <<
" on host and " << m_len <<
" on device" <<
endmsg;
132 throw GaudiException(
"Host to device copy with mismatched sizes",
"CUDADeviceArrayException",
135 throw GaudiException(
"Host to device copy with mismatched sizes",
"CUDADeviceArrayException",
138 if ( m_stream ==
nullptr ) {
146 template <TriviallyCopyable T>
148 if (
this == &rhs ) {
return *
this; }
149 if ( m_stream !=
nullptr && rhs.
m_stream !=
nullptr && m_stream != rhs.
m_stream ) {
150 m_stream->parent()->error()
151 <<
"Device to device copies between DeviceArrays on different streams are not allowed!" <<
endmsg;
152 throw GaudiException(
"Device to device copy with mismatched streams",
"CUDADeviceArrayException",
155 if ( m_len != rhs.
m_len ) {
156 if ( m_stream !=
nullptr ) {
157 m_stream->parent()->error() <<
"Device to device copy with mismatched sizes: " << rhs.
m_len <<
" and " << m_len
159 throw GaudiException(
"Device to device copy with mismatched sizes",
"CUDADeviceArrayException",
163 rhs.
m_stream->
parent()->error() <<
"Device to device copy with mismatched sizes: " << rhs.
m_len <<
" and "
165 throw GaudiException(
"Device to device copy with mismatched sizes",
"CUDADeviceArrayException",
169 throw GaudiException(
"Device to device copy with mismatched sizes",
"CUDADeviceArrayException",
174 if ( m_stream !=
nullptr ) {
176 }
else if ( rhs.
m_stream !=
nullptr ) {
184 template <TriviallyCopyable T>
185 template <HostRange<T> R>
189 if ( m_stream !=
nullptr ) {
190 m_stream->parent()->error() <<
"Device to host copy with mismatched sizes: " << m_len <<
" on device and "
192 throw GaudiException(
"Device to host copy with mismatched sizes",
"CUDADeviceArrayException",
195 throw GaudiException(
"Device to host copy with mismatched sizes",
"CUDADeviceArrayException",
198 if ( m_stream ==
nullptr ) {
205 template <TriviallyCopyable T>
207 std::span<T, 1> dest_span( &
dest, 1 );
208 this->toHost( dest_span );
DeviceArray & operator=(const T &src)
Copy from a host value (for size 1)
void toHost(R &dest)
Copy to a HostRange.
concept HostRange
Constrain ranges that can represent host memory compatible with this array.
Gaudi::Algorithm *const syncPtr
T * operator->()
Allow access to struct members.
T * operator&()
Alias for devPtr.
constexpr auto size(const T &, Args &&...) noexcept
const bool hasAsyncParent
void copyDeviceToDeviceNoStream(void *destDevPtr, const void *srcDevPtr, std::size_t size)
DeviceArrayGlobalTag_t(Gaudi::Algorithm *parent)
void copyDeviceToDeviceWithStream(void *destDevPtr, const void *srcDevPtr, std::size_t size, Stream &stream)
const Gaudi::AsynchronousAlgorithm * parent()
Access the parent algorithm.
DeviceArrayGlobalTag_t(Gaudi::AsynchronousAlgorithm *parent)
void copyHostToDeviceNoStream(void *devPtr, const void *hstPtr, std::size_t size)
void freeWithStream(void *ptr, Stream &stream)
void * allocateNoStream(std::size_t size, Gaudi::AsynchronousAlgorithm *parent)
T * devPtr()
Return raw device pointer.
void * allocateWithStream(std::size_t size, Stream &stream)
~DeviceArray()
Destructor.
Base class from which all concrete algorithm classes should be derived.
Base class for asynchronous algorithms.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
void copyDeviceToHostWithStream(void *hstPtr, const void *devPtr, std::size_t size, Stream &stream)
concept TriviallyCopyable
Ensure type is trivially copyable (conceptization of std::is_trivially_copyable)
void freeNoStream(void *ptr)
DeviceArray & operator=(const R &src)
Copy from a HostRange.
DeviceArray(Stream &stream, std::size_t len)
Construct DeviceArray local to a Stream (i.e. Algorithm). May not be stored in whiteboard.
void copyHostToDeviceWithStream(void *devPtr, const void *hstPtr, std::size_t size, Stream &stream)
constexpr static const auto FAILURE
void copyDeviceToHostNoStream(void *hstPtr, const void *devPtr, std::size_t size)
Gaudi::AsynchronousAlgorithm *const asyncPtr