PSCF v1.4.0
Pscf::DeviceMemory Class Reference

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ DeviceMemory() [1/2]

Pscf::DeviceMemory::DeviceMemory ( )

Default constructor.

Definition at line 21 of file DeviceMemory.cu.

◆ DeviceMemory() [2/2]

Pscf::DeviceMemory::DeviceMemory ( int capacity)

Allocating constructor.

This function calls allocate(capacity) internally.

Parameters
capacitysize in bytes to allocate

Definition at line 30 of file DeviceMemory.cu.

References allocate(), and capacity().

◆ ~DeviceMemory()

Pscf::DeviceMemory::~DeviceMemory ( )
virtual

Destructor.

Deletes underlying C array, if allocated previously.

Definition at line 39 of file DeviceMemory.cu.

References isAllocated().

Member Function Documentation

◆ allocate()

void Pscf::DeviceMemory::allocate ( int capacity)

Allocate the underlying C array on the device.

Exceptions
Exceptionif capacity parameter not positve
Exceptionif the array is already allocated.
Parameters
capacitynumber of byes to allocate.

Definition at line 54 of file DeviceMemory.cu.

References capacity(), isAllocated(), and UTIL_THROW.

Referenced by DeviceMemory(), and resize().

◆ deallocate()

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().

◆ 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.

Exceptions
Exceptionif capacity is not positve
Parameters
capacitynumber of byes requird

Definition at line 82 of file DeviceMemory.cu.

References allocate(), capacity(), deallocate(), and UTIL_THROW.

◆ addReference()

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.

Parameters
referencereference to be included by reference counter

Definition at line 96 of file DeviceMemory.cu.

References Util::CountedReference::associate().

Referenced by Pscf::DeviceArray< Data >::associate().

◆ cArray()

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().

◆ capacity()

int Pscf::DeviceMemory::capacity ( ) const
inline

Return allocated capacity.

Returns
Number of elements allocated in array

Definition at line 143 of file DeviceMemory.h.

Referenced by allocate(), Pscf::DeviceArray< Data >::associate(), DeviceMemory(), and resize().

◆ isAllocated()

bool Pscf::DeviceMemory::isAllocated ( ) const
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().


The documentation for this class was generated from the following files: