NVArena

class zhetapi::NVArena

An allocator class for Nvidia GPUs. Has additional features like warnings for memory leaks and copy bound errors. Overall is a more convenient interface to GPU memory than standard CUDA operations like cudaMalloc and cudaMemcpy.

Public Functions

template<class T>
T *alloc(size_t = 1)

Allocates a block of items of a specific type.

Template Parameters

t – the specific type of item to allocate.

Parameters

items – the number of items to allocate.

Returns

the allocated block.

template<class T>
void free(T*)

Frees a block of items of a specific type.

Template Parameters

T – the specific type of item to free.

Parameters

ptr – the block of memory to be freed.

template<class T>
void write(T*, T*, size_t = 1)

Copies a block of memory from host memory to GPU memory, using cudaMemcpy.

Template Parameters

T – the type of each element in the blocks of memory.

Parameters
  • dst – the pointer to the destination in GPU memory.

  • src – the pointer to the block in host memory.

  • n – the number of items to copy (note that this copies n * sizeof(T) bytes in total).

template<class T>
void read(T*, T*, size_t = 1)

Copies a block of memory from GPU memory to host memory, using cudaMemcpy.

Template Parameters

T – the type of each element in the blocks of memory.

Parameters
  • dst – the pointer to the destination in host memory.

  • src – the pointer to the block in GPU memory.

  • n – the number of items to copy (note that this copies n * sizeof(T) bytes in total).

class double_free : public runtime_error

This exceptoin is thrown if the user frees a piece of memory more than once. The allocator keeps track of all allocated blocks for this.

class segfault : public runtime_error

This exception is thrown if the user tries to free a piece of memory that was never allocated.