|
PSCF v1.5.0
|
Template for dynamic array stored in host CPU memory. More...
#include <HostSendArray.h>
Public Types | |
| using | ValueType = Data |
| Data type of each element. | |
| using | BackendIdClass = CUT |
| Backend identifier class type. | |
Public Member Functions | |
| HostSendArray (int capacity) | |
| Allocating constructor. | |
| void | associate (BackendArray< Data, CUT > &deviceArray) |
| Allocate if not allocated previously. | |
| HostSendArray< Data, CUT > & | operator= (BackendArray< Data, CUT > const &other) |
| Assignment operator, assign from a BackendArray<Data,CUT>. | |
| void | copySlice (BackendArray< Data, CUT > const &other, int beginId) |
| Copy a slice of the data from a larger BackendArray into this array. | |
| void | dissociate () |
| Release host array. | |
| Public Member Functions inherited from Util::DArray< Data > | |
| DArray () | |
| Default constructor. | |
| DArray (int capacity) | |
| Allocating constructor. | |
| DArray (DArray< Data > const &other) | |
| Copy constructor. | |
| virtual | ~DArray () |
| Destructor. | |
| DArray< Data > & | operator= (DArray< Data > const &other) |
| Assignment from a DArray<Data> container. | |
| DArray< Data > & | operator= (Array< Data > const &other) |
| Assignment from an Array<Data> container. | |
| void | allocate (int capacity) |
| Allocate the underlying C array. | |
| void | deallocate () |
| Deallocate the underlying C array. | |
| void | reallocate (int capacity) |
| Reallocate the underlying C array and copy to new location. | |
| template<class Archive> | |
| void | serialize (Archive &ar, const unsigned int version) |
| Serialize a DArray to/from an Archive. | |
| Public Member Functions inherited from Util::Array< Data > | |
| Data & | operator[] (int i) |
| Get an element by non-const reference. | |
| Data const & | operator[] (int i) const |
| Get an element by const reference. | |
| void | begin (ArrayIterator< Data > &iterator) |
| Set an iterator to begin this Array. | |
| void | begin (ConstArrayIterator< Data > &iterator) const |
| Set a const iterator to begin this array. | |
| Data * | cArray () |
| Return a pointer to the underlying C array (non-const data). | |
| Data const * | cArray () const |
| Return pointer to the underlying C array (const data). | |
| bool | isAllocated () const |
| Does this array have associated data? | |
| int | size () const |
| Return logical size of array. | |
| int | capacity () const |
| Return allocated size. | |
Additional Inherited Members | |
| Protected Member Functions inherited from Util::Array< Data > | |
| Array () | |
| Constructor (protected to prevent direct instantiation). | |
| ~Array () | |
| Destructor (protected to prevent direct destruction). | |
| Protected Attributes inherited from Util::Array< Data > | |
| Data * | data_ |
| Pointer to an array of Data elements. | |
| int | capacity_ |
| Allocated size of the data_ array. | |
Template for dynamic array stored in host CPU memory.
This class template should be used in device-independent template code in which an array is copied from host to device. The BackendArray<Data,CPT> template defines an assignment operator that assigns from a host array to a backend array.
The "associate" member function allocates the array if not allocated previously, or does nothing if the array is already allocated with the correct capacity.
The assignment (=) operator that copies a host array (RHS) to a backend array (LHS) performs a deep copy from host to device memory. This function is a member function of the backend array, defined by the BackendArray<Data,CUT> class template.
Usage :
Typical usage for backend-independent template code is shown below for host-to-device transfer to a long lived instance of BackendArray<Data,CPT> named dArray from a shorter lived instance of HostSendArray<Data,CPT> named hArray. Here, the alias Data denotes the type of each array element.
Comments:
Definition at line 93 of file cuda/HostSendArray.h.
| using Pscf::HostSendArray< Data, CUT >::ValueType = Data |
Data type of each element.
Definition at line 101 of file cuda/HostSendArray.h.
| using Pscf::HostSendArray< Data, CUT >::BackendIdClass = CUT |
Backend identifier class type.
Definition at line 106 of file cuda/HostSendArray.h.
| Pscf::HostSendArray< Data, CUT >::HostSendArray | ( | int | capacity | ) |
Allocating constructor.
| capacity | number of elements to allocate |
Definition at line 214 of file cuda/HostSendArray.h.
References Util::Array< Data >::capacity(), and Util::DArray< Data >::DArray().
| void Pscf::HostSendArray< Data, CUT >::associate | ( | BackendArray< Data, CUT > & | deviceArray | ) |
Allocate if not allocated previously.
GPU specialization allocates host array with same dimensions as the backend array, unless this is already the case.
| deviceArray | backend array (must be allocated on entry) |
Definition at line 274 of file cuda/HostSendArray.h.
References Util::DArray< Data >::allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::isAllocated(), and UTIL_CHECK.
| HostSendArray< Data, CUT > & Pscf::HostSendArray< Data, CUT >::operator= | ( | BackendArray< Data, CUT > const & | other | ) |
Assignment operator, assign from a BackendArray<Data,CUT>.
Performs a deep copy from a RHS BackendArray<Data,CUT> to this LHS HostSendArray<D>, by copying the underlying data from device memory to host memory.
Preconditions: The RHS BackendArray<Data,CUT> object must be allocated. If this LHS HostSendArray<D> is not allocated, the required memory will be allocated before values are copied. Otherwise, if this LHS array is allocated on entry, capacites for LHS and RHS objects must be equal.
| 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 223 of file cuda/HostSendArray.h.
References Util::DArray< Data >::allocate(), Util::Array< Data >::capacity(), Util::Array< Data >::data_, Util::Array< Data >::isAllocated(), and UTIL_CHECK.
| void Pscf::HostSendArray< Data, CUT >::copySlice | ( | BackendArray< Data, CUT > const & | other, |
| int | beginId ) |
Copy a slice of the data from a larger BackendArray into this array.
This method will populate this HostSendArray with data from a slice of a BackendArray. The size of the slice is the capacity of this HostSendArray (i.e., this entire array will be populated), and the position of the slice within the BackendArray is indicated by the 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 HostSendArray.
| other | BackendArray<Data,CUT> object from which to copy slice |
| beginId | index of other array at which slice begins |
Definition at line 252 of file cuda/HostSendArray.h.
References Util::Array< Data >::capacity(), Util::Array< Data >::data_, Util::Array< Data >::isAllocated(), and UTIL_CHECK.
|
inline |
Release host array.
GPU specialization (T=CUT) does nothing. The CPU specialization (T=CPT) removes an association between the host array and some other array.
Definition at line 184 of file cuda/HostSendArray.h.