|
PSCF v1.5.0
|
Array for pseudo device-to-host array transfer with C++ backend. More...
#include <HostRecvArray.h>
Public Types | |
| using | BackendIdClass = CPT |
| Backend identifier class typename alias. | |
Public Member Functions | |
| ~HostRecvArray () | |
| Destructor. | |
| HostRecvArray (BackendArray< Data, CPT > const &other) | |
| Conversion construction from a BackendArray. | |
| HostRecvArray< Data, CPT > & | operator= (BackendArray< Data, CPT > const &other) |
| Create a read-only association with a BackendArray. | |
| void | dissociate () |
| Release association with a backend array. | |
| 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. | |
Array for pseudo device-to-host array transfer with C++ backend.
This template specialization should be used in backend-independent template code as the host array in contexts in which the specialization for the CUDA backend (T=Pscf:CUT) would copy an array from the GPU device to the CPU host. This specialization for the C++ backend (T=Pscf::CPT) instead makes the host array a shallow copy of the backend array, thus avoiding the cost of an actual deep copy. This specialization supports random read-only access to array elements via a subscript ([]) operator that returns a const reference, or via a ConstArrayIterator.
Conversion construction and assignment (operator =) from an instance of BackendArray<Data,CPT> to a HostRecvArray<Data,CPT> each create a shallow read-only copy of a C array that is owned by the associated backend array, via a private pointer to this shared array. These two functions each take a const reference to BackendArray<Data,CPT> as a parameter, and so can be used in contexts in which the backend array must be passed as a const reference. Conversion construction is equivalent to default construction followed by assignment.
An association with a backend array can be released by calling the dissociate member function, or will be released upon destruction of this host array. Such an association must be released by one of these two methods before the backend array that owns the associated data is de-allocated or destroyed. A reference counting system is used to detect and report dangerous de-allocation of a backend array that is still referred to by one or more other containers, which would create a dangling reference.
Usage:
Typical usage is shown below for a pseudo device-to-host transfer from a longer lived instance of BackendArray<Data,CPT> named deviceArray to a shorter lived instance of HostRecvArray<Data,CPT> named hostArray. The alias Data denotes the data type of each array element.
The default constructor and assignment operations may be combined into a single call of the conversion constructor, giving the shorter version:
Comments:
Definition at line 114 of file cpp/HostRecvArray.h.
| using Pscf::HostRecvArray< Data, CPT >::BackendIdClass = CPT |
Backend identifier class typename alias.
Definition at line 122 of file cpp/HostRecvArray.h.
| Pscf::HostRecvArray< Data, CPT >::~HostRecvArray | ( | ) |
| Pscf::HostRecvArray< Data, CPT >::HostRecvArray | ( | BackendArray< Data, CPT > const & | other | ) |
Conversion construction from a BackendArray.
Create a read-only association with the backend array, thus creating a shallow copy that points to the memory owned by the backend array.
| other | array container |
Definition at line 228 of file cpp/HostRecvArray.h.
| HostRecvArray< Data, CPT > & Pscf::HostRecvArray< Data, CPT >::operator= | ( | BackendArray< Data, CPT > const & | other | ) |
Create a read-only association with a BackendArray.
Create an association with the other backend array, thus creating a shallow copy that points to the memory owned by the backend array. This array may not be allocated on entry.
| Exception | if other array is not allocated |
| Exception | if this is already associated with an array |
| other | array container on RHS of assigment (input) |
Definition at line 240 of file cpp/HostRecvArray.h.
| void Pscf::HostRecvArray< Data, CPT >::dissociate | ( | ) |
Release association with a backend array.
| Exception | if no such association exists. |
Definition at line 250 of file cpp/HostRecvArray.h.
References Util::ConstArray< Data >::capacity_, Util::ConstArray< Data >::data_, and UTIL_CHECK.