28 template <
class R,
class T>
29 concept HostRange = std::ranges::contiguous_range<R> && std::ranges::sized_range<R> &&
30 std::is_same_v<T, std::ranges::range_value_t<R>>;
43 template <TriviallyCopyable T>
54 template <HostRange<T> R>
64 template <HostRange<T> R>
99 template <TriviallyCopyable T>
101 :
m_ptr( static_cast<T*>(
Detail::allocateWithStream( len * sizeof( T ), stream ) ) )
103 ,
m_size( len * sizeof( T ) )
105 stream.registerDependency();
108 template <TriviallyCopyable T>
110 :
m_ptr( static_cast<T*>(
111 Detail::allocateNoStream( len * sizeof( T ), globalTag.hasAsyncParent ? globalTag.asyncPtr : nullptr ) ) )
113 ,
m_size( len * sizeof( T ) )
116 template <TriviallyCopyable T>
126 template <TriviallyCopyable T>
127 template <HostRange<T> R>
130 if ( std::ranges::size( src ) !=
m_len ) {
132 m_stream->parent()->error() <<
"Host to device copy with mismatched sizes: " << std::ranges::size( src )
133 <<
" on host and " <<
m_len <<
" on device" <<
endmsg;
134 throw GaudiException(
"Host to device copy with mismatched sizes",
"CUDADeviceArrayException",
137 throw GaudiException(
"Host to device copy with mismatched sizes",
"CUDADeviceArrayException",
148 template <TriviallyCopyable T>
150 if (
this == &rhs ) {
return *
this; }
153 <<
"Device to device copies between DeviceArrays on different streams are not allowed!" <<
endmsg;
154 throw GaudiException(
"Device to device copy with mismatched streams",
"CUDADeviceArrayException",
159 m_stream->parent()->error() <<
"Device to device copy with mismatched sizes: " << rhs.
m_len <<
" and " <<
m_len
161 throw GaudiException(
"Device to device copy with mismatched sizes",
"CUDADeviceArrayException",
167 throw GaudiException(
"Device to device copy with mismatched sizes",
"CUDADeviceArrayException",
171 throw GaudiException(
"Device to device copy with mismatched sizes",
"CUDADeviceArrayException",
178 }
else if ( rhs.
m_stream !=
nullptr ) {
186 template <TriviallyCopyable T>
187 template <HostRange<T> R>
190 if ( std::ranges::size( dest ) !=
m_len ) {
192 m_stream->parent()->error() <<
"Device to host copy with mismatched sizes: " <<
m_len <<
" on device and "
193 << std::ranges::size( dest ) <<
" on host" <<
endmsg;
194 throw GaudiException(
"Device to host copy with mismatched sizes",
"CUDADeviceArrayException",
197 throw GaudiException(
"Device to host copy with mismatched sizes",
"CUDADeviceArrayException",
207 template <TriviallyCopyable T>
209 std::span<T, 1> dest_span( &dest, 1 );
210 this->
toHost( dest_span );
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Base class from which all concrete algorithm classes should be derived.
Base class for asynchronous algorithms.
DeviceArray & operator=(const T &src)
Copy from a host value (for size 1)
~DeviceArray()
Destructor.
void toHost(R &dest)
Copy to a HostRange.
T * devPtr()
Return raw device pointer.
DeviceArray & operator=(const R &src)
Copy from a HostRange.
T * operator->()
Allow access to struct members.
DeviceArray(Stream &stream, std::size_t len)
Construct DeviceArray local to a Stream (i.e. Algorithm). May not be stored in whiteboard.
T * operator&()
Alias for devPtr.
const Gaudi::AsynchronousAlgorithm * parent()
Access the parent algorithm.
Define general base for Gaudi exception.
constexpr static const auto FAILURE
Constrain ranges that can represent host memory compatible with this array.
Ensure type is trivially copyable (conceptization of std::is_trivially_copyable)
void copyDeviceToDeviceNoStream(void *destDevPtr, const void *srcDevPtr, std::size_t size)
void * allocateNoStream(std::size_t size, Gaudi::AsynchronousAlgorithm *parent)
void copyDeviceToHostWithStream(void *hstPtr, const void *devPtr, std::size_t size, Stream &stream)
void copyHostToDeviceNoStream(void *devPtr, const void *hstPtr, std::size_t size)
void * allocateWithStream(std::size_t size, Stream &stream)
void copyDeviceToHostNoStream(void *hstPtr, const void *devPtr, std::size_t size)
void copyDeviceToDeviceWithStream(void *destDevPtr, const void *srcDevPtr, std::size_t size, Stream &stream)
void freeNoStream(void *ptr)
void copyHostToDeviceWithStream(void *devPtr, const void *hstPtr, std::size_t size, Stream &stream)
void freeWithStream(void *ptr, Stream &stream)
DeviceArrayGlobalTag_t(Gaudi::Algorithm *parent)
const bool hasAsyncParent
Gaudi::AsynchronousAlgorithm *const asyncPtr
Gaudi::Algorithm *const syncPtr
DeviceArrayGlobalTag_t(Gaudi::AsynchronousAlgorithm *parent)