|
PSCF v1.5.0
|
Pseudo "device" array for use with C++ backend. More...
#include <BackendArray.h>
Public Types | |
| using | BackendIdClass = CPT |
| Backend identifier class typename aliase. | |
| Public Types inherited from Pscf::FftwDRArray< Data > | |
| using | ValueType = Data |
| Data type of each array element. | |
Public Member Functions | |
| BackendArray (int capacity) | |
| Allocating constructor. | |
| BackendArray< Data, CPT > & | operator= (HostSendArray< Data, CPT > const &other) |
| Pseudo-assignment from a host array. | |
| Public Member Functions inherited from Pscf::FftwDRArray< Data > | |
| FftwDRArray () | |
| Default constructor. | |
| FftwDRArray (int capacity) | |
| Allocating constructor. | |
| FftwDRArray (FftwDRArray< Data > const &other) | |
| Copy constructor. | |
| virtual | ~FftwDRArray () |
| Destructor. | |
| FftwDRArray< Data > & | operator= (FftwDRArray< Data > const &other) |
| Assignment from another FftwDRArray<Data> container. | |
| FftwDRArray< Data > & | operator= (Array< Data > const &other) |
| Assignment from an Array<Data> container. | |
| void | allocate (int capacity) |
| Allocate an underlying C array, which this container then owns. | |
| virtual void | deallocate () |
| Dellocate an underlying C array that is owned by this container. | |
| void | associate (FftwDRArray< Data > &other, int beginId, int capacity) |
| Associate this object with a slice of a different FftwDRArray. | |
| void | associate (FftwDRArray< Data > &other) |
| Associate this object with all of a different FftwDRArray. | |
| void | dissociate () |
| Dissociate this object from an externally owned array slice. | |
| template<class Archive> | |
| void | serialize (Archive &ar, const unsigned int version) |
| Serialize an FftwDRArray to/from an Archive. | |
| bool | isOwner () const |
| Does this container own a dynamically allocated C array? | |
| bool | isAssociated () const |
| Is this container associated with a C array it does not own? | |
| 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. | |
| Public Member Functions inherited from Util::ReferenceCounter | |
| ReferenceCounter () | |
| Constructor. | |
| int | nRef () const |
| Get the number of references to a shareable resource. | |
| bool | hasRefs () const |
| Does this counter have references (is nRef > 0)? | |
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. | |
Pseudo "device" array for use with C++ backend.
Derived from FftwDRArray, and largely equivalent.
The main difference from the base class is the addition of assignment (operator = ) from a HostSendArray<Data,CTP> to a BackendArray<Data,CTP>. This operator checks for the existence of an association between the backend array (LHS) and host array (RHS) in which both point to the same memory, throws an Exception if such an association does not already exist, or does nothing if it does. Reason for this usage is discussed below.
Host to device data transfer:
Usage for transfer of data from an instance of HostSendArray<Data,CPT> to an instance of BackendArray<Data,CPT> is discussed in the class documentation for the HostSendArray class template. The most explicit version of this pattern involves the following steps:
Comments:
Definition at line 82 of file cpp/BackendArray.h.
| using Pscf::BackendArray< Data, CPT >::BackendIdClass = CPT |
Backend identifier class typename aliase.
Definition at line 92 of file cpp/BackendArray.h.
| Pscf::BackendArray< Data, CPT >::BackendArray | ( | int | capacity | ) |
Allocating constructor.
| capacity | number of elements to allocate |
Definition at line 152 of file cpp/BackendArray.h.
References Util::Array< Data >::capacity(), and Pscf::FftwDRArray< Data >::FftwDRArray().
| BackendArray< Data, CPT > & Pscf::BackendArray< Data, CPT >::operator= | ( | HostSendArray< Data, CPT > const & | other | ) |
Pseudo-assignment from a host array.
This function performs a sanity test and does nothing if the test passes. It checks that both LHS and RHS are allocated and both refer to the to the same underlying C array.
Rationale: Since the host array acts as a shallow copy of this backend array, the association must have been created before data was initialized on the host array, which must occurs before the pseudo host-to-device transfer is finalized by this operator.
| Exception | if this is not allocated |
| Exception | if other array is not allocated |
| Exception | if this and other do not point to the same memory |
| other | array container on RHS of assigment (input) |
Definition at line 161 of file cpp/BackendArray.h.
References Util::Array< Data >::capacity(), Util::Array< Data >::cArray(), Util::Array< Data >::isAllocated(), and UTIL_CHECK.