Class Acts::Cuda::MemoryManager

class Acts::Cuda::MemoryManager

Singleton class used for allocating memory on CUDA device(s)

In order to avoid calling cudaMalloc(…) and cudaFree(…) too many times in the code (which can turn out to be pretty slow), device memory is allocated using this singleton memory manager for the Acts::Cuda::device_array arrays.

It is implemented in a very simple way. It allocates a big blob of memory, and then hands out pointers from this blob to anyone that asks for device memory.

The class doesn’t handle memory returns in any sophisticated way. It assumes that any calculation will need all allocated memory until the end of that calculation. At which point all of that memory gets re-purpused in one call.

The code is not thread safe currently in any shape or form. But there should be ways of making it at least “thread friendly” later on.

Declarations preventing any copies of the singleton object

MemoryManager(const MemoryManager&) = delete

Disallow copy construction.

MemoryManager(MemoryManager&&) = delete

Disallow move construction.

MemoryManager &operator=(const MemoryManager&) = delete

Disallow copy assignment.

MemoryManager &operator=(MemoryManager&&) = delete

Disallow move assignment.

Functions that the users of Acts may be interacting with

void setMemorySize(std::size_t sizeInBytes, int device = -1)

Set the amount of memory to use on a particular device.

static MemoryManager &instance()

Singleton object accessor.

Functions used internally by the Acts code

std::size_t availableMemory(int device = -1) const

Get the amount of memory still available on a specific device.

void *allocate(std::size_t sizeInBytes, int device = -1)

Get a pointer to an available memory block on the device.

void reset(int device = -1)

Reset all allocations.

Public Functions

~MemoryManager()

Destructor, freeing up all allocated memory.