1#ifndef PSCF_DEVICE_ARRAY_H
2#define PSCF_DEVICE_ARRAY_H
11#include "cudaErrorCheck.h"
13#include <cuda_runtime.h>
41 template <
typename Data>
209 template <
typename Data>
221 template <
typename Data>
235 template <
typename Data>
245 cudaMemcpyDeviceToDevice) );
251 template <
typename Data>
255 cudaErrorCheck( cudaFree(
dataPtr_) );
263 template <
typename Data>
267 UTIL_THROW(
"Attempt to re-allocate an array");
270 UTIL_THROW(
"Attempt to allocate array already associated with data");
273 UTIL_THROW(
"Attempt to allocate with capacity <= 0");
284 template <
typename Data>
295 UTIL_THROW(
"Attempt to associate an already-allocated array.");
310 template <
typename Data>
317 UTIL_THROW(
"Cannot deallocate, data not owned by this object.");
319 cudaErrorCheck( cudaFree(
dataPtr_) );
329 template <
typename Data>
333 UTIL_THROW(
"Cannot dissociate: this object owns the array.");
336 UTIL_THROW(
"Cannot dissociate: no associated data found.");
348 template <
typename Data>
353 if (
this == &other)
return *
this;
357 UTIL_THROW(
"Other DeviceArray<Data> must be allocated.");
367 UTIL_THROW(
"Cannot assign arrays of unequal capacity");
373 cudaMemcpyDeviceToDevice) );
381 template <
typename Data>
387 UTIL_THROW(
"RHS HostDArray<Data> must be allocated.");
397 UTIL_THROW(
"Cannot assign arrays of unequal capacity");
403 cudaMemcpyHostToDevice) );
411 template <
typename Data>
427 template <
typename Data>
443 template <
typename Data>
459 template <
typename Data>
466 template <
typename Data>
Dynamic array on the GPU device with aligned data.
DeviceArray()
Default constructor.
Data ElementType
Data type of each element.
bool isOwner() const
Does this object own the underlying data?
DeviceArray< Prdc::Cuda::cudaReal > const * ownerPtr_
void deallocate()
Dellocate the underlying C array.
DeviceArray(int capacity)
Allocating constructor.
void dissociate()
Dissociate this object from the associated array.
virtual ~DeviceArray()
Destructor.
Prdc::Cuda::cudaReal const * ownerDataPtr_
virtual DeviceArray< Data > & operator=(const DeviceArray< Data > &other)
Assignment operator, assign from another DeviceArray<Data> array.
bool isAllocated() const
Return true if the array has been allocated, false otherwise.
void associate(DeviceArray< Data > &arr, int beginId, int capacity)
Associate this object with a slice of a different DeviceArray.
Prdc::Cuda::cudaReal * dataPtr_
DeviceArray(DeviceArray< Data > const &other)
Copy constructor.
void allocate(int capacity)
Allocate the underlying C array on the device.
Data const * cArray() const
Return const pointer to underlying C array.
Data * cArray()
Return pointer to underlying C array.
Template for dynamic array stored in host CPU memory.
Data * cArray()
Return a pointer to the underlying C array.
int capacity() const
Return allocated size.
bool isAllocated() const
Return true if this DArray has been allocated, false otherwise.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
PSCF package top-level namespace.