12#include <pspg/math/GpuResources.h>
13#include <cuda_runtime.h>
26 template <
typename Data>
35 template <
typename Data>
51 template <
typename Data>
58 UTIL_THROW(
"Attempt to allocate with capacity <= 0");
60 gpuErrchk(cudaMalloc((
void**) &data_, capacity *
sizeof(Data)));
69 template <
typename Data>
86 template <
typename Data>
94 cudaMemcpy(data_, other.
cDField(),
95 capacity_ *
sizeof(Data), cudaMemcpyDeviceToDevice);
109 template <
typename Data>
113 if (
this == &other)
return *
this;
120 if (!isAllocated()) {
122 }
else if (capacity_ != other.
capacity_) {
123 UTIL_THROW(
"Cannot assign Fields of unequal capacity");
127 cudaMemcpy(data_, other.
cDField(),
128 capacity_ *
sizeof(Data), cudaMemcpyDeviceToDevice);
Dynamic array on the GPU with alligned data.
virtual DField< Data > & operator=(const DField< Data > &other)
Assignment operator.
Data * cDField()
Return pointer to underlying C array.
void allocate(int capacity)
Allocate the underlying C array on the device.
int capacity_
Allocated size of the data_ array.
void deallocate()
Dellocate the underlying C array.
virtual ~DField()
Destructor.
DField()
Default constructor.
int capacity() const
Return allocated size.
bool isAllocated() const
Return true if the Field has been allocated, false otherwise.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
C++ namespace for polymer self-consistent field theory (PSCF).
Utility classes for scientific computation.