|
PSCF v1.5.0
|
Host array to receive host-to-device data transfers. More...
#include <HostRecvArray.h>
Public Types | |
| using | ValueType = Data |
| Alias for data type of each array element. | |
| using | BackendIdClass = CUT |
| Alias for backend identifier class. | |
Public Member Functions | |
| HostRecvArray ()=default | |
| Default constructor. | |
| HostRecvArray (int capacity) | |
| Allocating constructor. | |
| HostRecvArray (BackendArray< Data, CUT > const &other) | |
| Conversion constructor (copies from device to host). | |
| virtual | ~HostRecvArray () |
| Destructor. | |
| HostRecvArray< Data, CUT > & | operator= (Array< Data > const &other) |
| Assignment from an Array<Data> container. | |
| HostRecvArray< Data, CUT > & | operator= (BackendArray< Data, CUT > const &other) |
| Assignment from a BackendArray<Data,CUT>. | |
| void | copySlice (BackendArray< Data, CUT > const &other, int beginId) |
| Copy a slice of data from a larger BackendArray into this array. | |
| void | allocate (int capacity) |
| Allocate the underlying C array. | |
| void | deallocate () |
| Deallocate the underlying C array. | |
| void | dissociate () |
| Release this array after finishing all reading. | |
| template<class Archive> | |
| void | serialize (Archive &ar, const unsigned int version) |
| Serialize a HostRecvArray to/from an Archive. | |
| Public Member Functions inherited from Util::ConstArray< Data > | |
| Data const & | operator[] (int i) const |
| Get an element by const reference. | |
| void | begin (ConstArrayIterator< Data > &iterator) const |
| Set a const iterator to begin this ConstArray. | |
| Data const * | cArray () const |
| Return a pointer to the underlying C array (pointer to const data). | |
| bool | isAllocated () const |
| Does this array have associated data? | |
| int | size () const |
| Return logical size of this array. | |
| int | capacity () const |
| Return allocated size of this array. | |
Additional Inherited Members | |
| Protected Member Functions inherited from Util::ConstArray< Data > | |
| ConstArray () | |
| Constructor (protected to prevent direct instantiation). | |
| ~ConstArray () | |
| Destructor (protected to prevent direct destruction). | |
| Protected Attributes inherited from Util::ConstArray< Data > | |
| Data * | data_ |
| Pointer to an array of Data elements. | |
| int | capacity_ |
| Allocated size of the data_ array. | |
Host array to receive host-to-device data transfers.
This class template should be used in backend-independent template code in which data is copied from a GPU backend array to a CPU host array. This template is derived from ConstArray<Data>, and thus provides read-only access to the data.
Conversion construction or assignment (operator =) from an instance of BackendArray<Data,CUT> to a HostRecvArray<Data,CUT> allocates the array if it is not allocated and then copies all elements of the array from global GPU device memory to host memory. Conversion construction from a backend array is equivalent to default construction followed by assignment.
Usage:
Typical usage is shown below for backend-indepent template code for device-to-host transfer from a longer lived instance of BackendArray<Data,CUT> named deviceArray to a local object that is an instance of HostRecvArray<Data,CUT> named hostArray. The type type of each array element is denoted by Data.
If the hostArray is a local object that is defined with the function in which it is used, the default constructor and assignment operations may instead be combined into a single call of the conversion constructor, giving the shorter version
In this case, the call of the dissociate function may also be omitted, since an equivalent operation will be performed by the destructor when the function ends and the hostArray goes out of scope.
Comments:
Definition at line 95 of file cuda/HostRecvArray.h.
| using Pscf::HostRecvArray< Data, CUT >::ValueType = Data |
Alias for data type of each array element.
Definition at line 105 of file cuda/HostRecvArray.h.
| using Pscf::HostRecvArray< Data, CUT >::BackendIdClass = CUT |
Alias for backend identifier class.
Definition at line 110 of file cuda/HostRecvArray.h.
|
default |
Default constructor.
References allocate(), Util::ConstArray< Data >::capacity(), copySlice(), deallocate(), and HostRecvArray().
Referenced by allocate(), copySlice(), deallocate(), HostRecvArray(), HostRecvArray(), HostRecvArray(), operator=(), operator=(), serialize(), and ~HostRecvArray().
| Pscf::HostRecvArray< Data, CUT >::HostRecvArray | ( | int | capacity | ) |
Allocating constructor.
| capacity | number of elements to allocate |
Definition at line 291 of file cuda/HostRecvArray.h.
References allocate(), Util::ConstArray< Data >::capacity(), and HostRecvArray().
| Pscf::HostRecvArray< Data, CUT >::HostRecvArray | ( | BackendArray< Data, CUT > const & | other | ) |
Conversion constructor (copies from device to host).
Conversion construction is equivalent to default construction followed by assignment. This function first allocates this array with a capacity equal to that of the other backend array, and then performs a deep copy of the underlying array from GPU device memory to CPU host memory.
| Exception | if the RHS array is not allocated on entry |
| other | BackendArray<Data,CUT> to be copied (input) |
Definition at line 301 of file cuda/HostRecvArray.h.
References HostRecvArray().
|
virtual |
Destructor.
Deletes underlying C array, if allocated previously.
Definition at line 310 of file cuda/HostRecvArray.h.
References Util::ConstArray< Data >::capacity_, Util::ConstArray< Data >::data_, Util::Memory::deallocate(), HostRecvArray(), and Util::ConstArray< Data >::isAllocated().
| HostRecvArray< Data, CUT > & Pscf::HostRecvArray< Data, CUT >::operator= | ( | Array< Data > const & | other | ) |
Assignment from an Array<Data> container.
Performs a deep copy, by copying values of all elements of an Array<Data> container. If this (LHS) array is already allocated on entry, it must have the same capacity as the other (RHS) array. If this LHS array is not allocated on entry, required memory is allocated before copying values.
| Exception | if other array is not allocated |
| Exception | if arrays are allocated with unequal capacities |
| other | array container on RHS of assigment (input) |
Definition at line 328 of file cuda/HostRecvArray.h.
References allocate(), Util::Array< Data >::capacity(), Util::ConstArray< Data >::capacity_, Util::ConstArray< Data >::data_, HostRecvArray(), Util::Array< Data >::isAllocated(), Util::ConstArray< Data >::isAllocated(), and UTIL_CHECK.
| HostRecvArray< Data, CUT > & Pscf::HostRecvArray< Data, CUT >::operator= | ( | BackendArray< Data, CUT > const & | other | ) |
Assignment from a BackendArray<Data,CUT>.
Performs a deep copy from a RHS BackendArray<Data,CUT> to this LHS HostRecvArray<D>, by first allocating if necessary, and then copying the underlying data from device memory to host memory.
| Exception | if the RHS array is not allocated on entry |
| Exception | if LHS and RHS have unequal nonzero capacities |
| other | BackendArray<Data,CUT> on RHS of assignment (input) |
Definition at line 360 of file cuda/HostRecvArray.h.
References allocate(), Util::ConstArray< Data >::capacity(), Util::ConstArray< Data >::data_, HostRecvArray(), Util::ConstArray< Data >::isAllocated(), and UTIL_CHECK.
| void Pscf::HostRecvArray< Data, CUT >::copySlice | ( | BackendArray< Data, CUT > const & | other, |
| int | beginId ) |
Copy a slice of data from a larger BackendArray into this array.
This function populate this HostRecvArray with data from a slice of a BackendArray. The size of the slice is equal to the capacity of this LHS HostRecvArray, so that this entire array will be fully populated. The position of the beginning of the slice within the RHS BackendArray is indicated by input parameter beginId. The capacity of the RHS BackendArray must thus be greater than or equal to the sum of beginId and the capacity of this LHS HostRecvArray.
| Exception | if RHS array is not allocated |
| Exception | if LHS array is not allocated |
| Exception | if beginId is negative |
| Exception | if the slice extends beyond the end of the RHS |
| other | BackendArray<Data,CUT> object from which to copy slice |
| beginId | index of other array at which slice begins |
Definition at line 391 of file cuda/HostRecvArray.h.
References Util::ConstArray< Data >::capacity(), Util::ConstArray< Data >::data_, HostRecvArray(), Util::ConstArray< Data >::isAllocated(), and UTIL_CHECK.
Referenced by HostRecvArray().
| void Pscf::HostRecvArray< Data, CUT >::allocate | ( | int | capacity | ) |
Allocate the underlying C array.
| Exception | if the HostRecvArray is already allocated |
| capacity | number of elements to allocate |
Definition at line 415 of file cuda/HostRecvArray.h.
References Util::Memory::allocate(), Util::ConstArray< Data >::capacity(), Util::ConstArray< Data >::capacity_, Util::ConstArray< Data >::data_, HostRecvArray(), Util::ConstArray< Data >::isAllocated(), and UTIL_THROW.
Referenced by HostRecvArray(), HostRecvArray(), operator=(), operator=(), and serialize().
| void Pscf::HostRecvArray< Data, CUT >::deallocate | ( | ) |
Deallocate the underlying C array.
| Exception | if the HostRecvArray is not allocated |
Definition at line 431 of file cuda/HostRecvArray.h.
References Util::ConstArray< Data >::capacity_, Util::ConstArray< Data >::data_, Util::Memory::deallocate(), HostRecvArray(), Util::ConstArray< Data >::isAllocated(), and UTIL_THROW.
Referenced by HostRecvArray().
|
inline |
Release this array after finishing all reading.
In template code that must work with either CPU or GPU, this should be called after all code that requires read access to this array. In this GPU specialization (T=CUT), this function does nothing.
Definition at line 245 of file cuda/HostRecvArray.h.
| void Pscf::HostRecvArray< Data, CUT >::serialize | ( | Archive & | ar, |
| const unsigned int | version ) |
Serialize a HostRecvArray to/from an Archive.
| ar | archive |
| version | archive version id |
Definition at line 465 of file cuda/HostRecvArray.h.
References allocate(), Util::ConstArray< Data >::capacity(), Util::ConstArray< Data >::capacity_, Util::ConstArray< Data >::data_, HostRecvArray(), Util::ConstArray< Data >::isAllocated(), and UTIL_THROW.