8#include "DeviceMemory.h"
9#include "cudaErrorCheck.h"
10#include <util/misc/CountedReference.h>
12#include <cuda_runtime.h>
42 if (refCounter_.hasRefs()) {
43 std::cout <<
"Error - destruction of DeviceMemory with"
44 <<
"external references" << std::endl;
57 UTIL_THROW(
"Attempt to allocate with capacity <= 0");
60 UTIL_THROW(
"Attempt to re-allocate a DeviceMemory");
62 cudaErrorCheck( cudaMalloc( &dataPtr_,
capacity ) );
73 cudaErrorCheck( cudaFree(dataPtr_) );
85 UTIL_THROW(
"Attempt to resize DeviceMemory with capacity <= 0");
virtual ~DeviceMemory()
Destructor.
void deallocate()
Dellocate the underlying C array, if any.
void addReference(CountedReference &reference)
Associate a reference with the reference counter.
bool isAllocated() const
Return true if the array has been allocated, false otherwise.
DeviceMemory()
Default constructor.
void * cArray() const
Return pointer to underlying C array.
void allocate(int capacity)
Allocate the underlying C array on the device.
int capacity() const
Return allocated capacity.
void resize(int capacity)
Re-allocate if necessary to increase capacity.
Reference to a shared resource.
void associate(ReferenceCounter &counter)
Create an association with a ReferenceCounter.
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.