Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Acts::Cuda::MemoryManager Class Reference

#include <acts/blob/sPHENIX/Plugins/Cuda/include/Acts/Plugins/Cuda/Utilities/MemoryManager.hpp>

+ Collaboration diagram for Acts::Cuda::MemoryManager:

Classes

struct  DeviceMemory
 

Public Member Functions

 ~MemoryManager ()
 Destructor, freeing up all allocated memory.
 
Declarations preventing any copies of the singleton object
 MemoryManager (const MemoryManager &)=delete
 Disallow copy construction.
 
 MemoryManager (MemoryManager &&)=delete
 Disallow move construction.
 
MemoryManageroperator= (const MemoryManager &)=delete
 Disallow copy assignment.
 
MemoryManageroperator= (MemoryManager &&)=delete
 Disallow move assignment.
 
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.
 

Private Member Functions

 MemoryManager ()
 Hide the constructor of the class.
 

Private Attributes

std::vector< DeviceMemorym_memory
 Object holding information about memory allocations on all devices.
 

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 MemoryManagerinstance ()
 Singleton object accessor.
 

Detailed Description

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.

Definition at line 36 of file MemoryManager.hpp.

View newest version in sPHENIX GitHub at line 36 of file MemoryManager.hpp

Constructor & Destructor Documentation

Acts::Cuda::MemoryManager::~MemoryManager ( )

Destructor, freeing up all allocated memory.

Acts::Cuda::MemoryManager::MemoryManager ( const MemoryManager )
delete

Disallow copy construction.

Acts::Cuda::MemoryManager::MemoryManager ( MemoryManager &&  )
delete

Disallow move construction.

Acts::Cuda::MemoryManager::MemoryManager ( )
private

Hide the constructor of the class.

Member Function Documentation

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

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

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

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

static MemoryManager& Acts::Cuda::MemoryManager::instance ( )
static

Singleton object accessor.

Referenced by Acts::Cuda::SeedFinder< external_spacepoint_t >::createSeedsForGroup(), and main().

+ Here is the caller graph for this function:

MemoryManager& Acts::Cuda::MemoryManager::operator= ( const MemoryManager )
delete

Disallow copy assignment.

MemoryManager& Acts::Cuda::MemoryManager::operator= ( MemoryManager &&  )
delete

Disallow move assignment.

void Acts::Cuda::MemoryManager::reset ( int  device = -1)

Reset all allocations.

Referenced by Acts::Cuda::SeedFinder< external_spacepoint_t >::createSeedsForGroup().

+ Here is the caller graph for this function:

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

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

Referenced by main().

+ Here is the caller graph for this function:

Member Data Documentation

std::vector<DeviceMemory> Acts::Cuda::MemoryManager::m_memory
private

Object holding information about memory allocations on all devices.

Definition at line 99 of file MemoryManager.hpp.

View newest version in sPHENIX GitHub at line 99 of file MemoryManager.hpp


The documentation for this class was generated from the following file: