|
PSCF v1.4.0
|
Block of bare memory allocated on the GPU device. More...
#include <DeviceMemory.h>
Public Member Functions | |
| DeviceMemory () | |
| Default constructor. | |
| DeviceMemory (int capacity) | |
| Allocating constructor. | |
| virtual | ~DeviceMemory () |
| Destructor. | |
| void | allocate (int capacity) |
| Allocate the underlying C array on the device. | |
| void | deallocate () |
| Dellocate the underlying C array, if any. | |
| void | resize (int capacity) |
| Re-allocate if necessary to increase capacity. | |
| void | addReference (CountedReference &reference) |
| Associate a reference with the reference counter. | |
| void * | cArray () const |
| Return pointer to underlying C array. | |
| int | capacity () const |
| Return allocated capacity. | |
| bool | isAllocated () const |
| Return true if the array has been allocated, false otherwise. | |
Block of bare memory allocated on the GPU device.
This class wraps a void* C array that is allocated in GPU device global memory, and also contains the number of bytes allocated.
Definition at line 28 of file DeviceMemory.h.
| Pscf::DeviceMemory::DeviceMemory | ( | ) |
Default constructor.
Definition at line 21 of file DeviceMemory.cu.
| Pscf::DeviceMemory::DeviceMemory | ( | int | capacity | ) |
Allocating constructor.
This function calls allocate(capacity) internally.
| capacity | size in bytes to allocate |
Definition at line 30 of file DeviceMemory.cu.
References allocate(), and capacity().
|
virtual |
Destructor.
Deletes underlying C array, if allocated previously.
Definition at line 39 of file DeviceMemory.cu.
References isAllocated().
| void Pscf::DeviceMemory::allocate | ( | int | capacity | ) |
Allocate the underlying C array on the device.
| capacity | number of byes to allocate. |
Definition at line 54 of file DeviceMemory.cu.
References capacity(), isAllocated(), and UTIL_THROW.
Referenced by DeviceMemory(), and resize().
| void Pscf::DeviceMemory::deallocate | ( | ) |
Dellocate the underlying C array, if any.
If no memory is allocated, do nothing.
Definition at line 69 of file DeviceMemory.cu.
References isAllocated(), and UTIL_CHECK.
Referenced by resize().
| void Pscf::DeviceMemory::resize | ( | int | capacity | ) |
Re-allocate if necessary to increase capacity.
If the capacity parameter is greater than current capacity, allocate or re-allocate to obtain a block of desired capacity. Otherwise, do nothing.
When a previously allocated array is resized to increase capacity, the old array is deallocated and all data is lost.
| Exception | if capacity is not positve |
| capacity | number of byes requird |
Definition at line 82 of file DeviceMemory.cu.
References allocate(), capacity(), deallocate(), and UTIL_THROW.
| void Pscf::DeviceMemory::addReference | ( | CountedReference & | reference | ) |
Associate a reference with the reference counter.
This should only be called within an associate function of a container that creates an association with this object in which this object acts as the data owner. The CountedReference should that is passed as a parameter should be owned by the data user. On return, the ReferenceCounter that is owned by this DeviceMemory is incremented by one, and the CountedReference contains a pointer to that ReferenceCounter.
| reference | reference to be included by reference counter |
Definition at line 96 of file DeviceMemory.cu.
References Util::CountedReference::associate().
Referenced by Pscf::DeviceArray< Data >::associate().
| void * Pscf::DeviceMemory::cArray | ( | ) | const |
Return pointer to underlying C array.
Definition at line 102 of file DeviceMemory.cu.
References UTIL_CHECK.
Referenced by Pscf::DeviceArray< Data >::associate().
|
inline |
Return allocated capacity.
Definition at line 143 of file DeviceMemory.h.
Referenced by allocate(), Pscf::DeviceArray< Data >::associate(), DeviceMemory(), and resize().
|
inline |
Return true if the array has been allocated, false otherwise.
Definition at line 136 of file DeviceMemory.h.
Referenced by allocate(), Pscf::DeviceArray< Data >::associate(), deallocate(), and ~DeviceMemory().