UMPIRE
Umpire: resource management and provision
umpire::ResourceManager Class Reference

#include </home/docs/checkouts/readthedocs.org/user_builds/umpire/checkouts/develop/src/umpire/ResourceManager.hpp>

Public Member Functions

void initialize ()
 Initialize the ResourceManager. More...
 
std::vector< std::string > getAllocatorNames () const noexcept
 Get the names of all available Allocator objects. More...
 
std::vector< int > getAllocatorIds () const noexcept
 Get the ids of all available Allocator objects. More...
 
Allocator getAllocator (const std::string &name)
 Get the Allocator with the given name. More...
 
Allocator getAllocator (const char *name)
 
Allocator getAllocator (resource::MemoryResourceType resource_type)
 Get the default Allocator for the given resource_type. More...
 
Allocator getAllocator (int id)
 Get the Allocator with the given ID. More...
 
Allocator getDefaultAllocator ()
 Get the default Allocator. More...
 
std::vector< std::string > getResourceNames ()
 Get the names for existing Resources. More...
 
std::vector< std::string > getSharedAllocatorNames ()
 Get the names for existing SHARED Allocator names, if any. More...
 
void setDefaultAllocator (Allocator allocator) noexcept
 Set the default Allocator. More...
 
template<typename Strategy , bool introspection = true, typename... Args>
Allocator makeAllocator (const std::string &name, Args &&... args)
 Construct a new Allocator. More...
 
template<typename Strategy , typename... Args>
Allocator makeAllocator (const std::string &name, Tracking tracked, Args &&... args)
 
Allocator makeResource (const std::string &name)
 
Allocator makeResource (const std::string &name, MemoryResourceTraits traits)
 
void addAlias (const std::string &name, Allocator allocator)
 Add an Allocator alias. More...
 
void removeAlias (const std::string &name, Allocator allocator)
 Remove an Allocator alias. More...
 
void destroyAllocator (const std::string &name, bool free_allocations=false)
 Destroy an allocator by name. More...
 
void destroyAllocator (int id, bool free_allocations=false)
 Destroy an allocator by ID. More...
 
Allocator getAllocator (void *ptr)
 Get the Allocator used to allocate ptr. More...
 
bool isAllocator (const std::string &name) noexcept
 
bool isAllocator (int id) noexcept
 
bool hasAllocator (void *ptr)
 Does the given pointer have an associated Allocator. More...
 
void registerAllocation (void *ptr, util::AllocationRecord record)
 register an allocation with the manager. More...
 
util::AllocationRecord deregisterAllocation (void *ptr)
 de-register the address ptr with the manager. More...
 
const util::AllocationRecordfindAllocationRecord (void *ptr) const
 Find the allocation record associated with an address ptr. More...
 
void copy (void *dst_ptr, void *src_ptr, std::size_t size=0)
 Copy size bytes of data from src_ptr to dst_ptr. More...
 
camp::resources::EventProxy< camp::resources::Resourcecopy (void *dst_ptr, void *src_ptr, camp::resources::Resource &ctx, std::size_t size=0)
 
void memset (void *ptr, int val, std::size_t length=0)
 Set the first length bytes of ptr to the value val. More...
 
camp::resources::EventProxy< camp::resources::Resourcememset (void *ptr, int val, camp::resources::Resource &ctx, std::size_t length=0)
 
void * reallocate (void *current_ptr, std::size_t new_size)
 Reallocate current_ptr to new_size. More...
 
void * reallocate (void *current_ptr, std::size_t new_size, camp::resources::Resource &ctx)
 
void * reallocate (void *current_ptr, std::size_t new_size, Allocator allocator)
 Reallocate current_ptr to new_size. More...
 
void * reallocate (void *current_ptr, std::size_t new_size, Allocator allocator, camp::resources::Resource &ctx)
 
void * move (void *src_ptr, Allocator allocator)
 Move src_ptr to memory from allocator. More...
 
void deallocate (void *ptr)
 Deallocate any pointer allocated by an Umpire-managed resource. More...
 
camp::resources::EventProxy< camp::resources::Resourceprefetch (void *ptr, int device, camp::resources::Resource &ctx)
 Asynchronously prefetch memory ptr to device. More...
 
std::size_t getSize (void *ptr) const
 Get the size in bytes of the allocation for the given pointer. More...
 
std::size_t getInternalMemoryUsage () const
 
std::shared_ptr< op::MemoryOperationgetOperation (const std::string &operation_name, Allocator src_allocator, Allocator dst_allocator)
 
int getNumDevices () const
 
 ~ResourceManager ()
 
 ResourceManager (const ResourceManager &)=delete
 
ResourceManageroperator= (const ResourceManager &)=delete
 

Static Public Member Functions

static ResourceManagergetInstance ()
 

Friends

void print_allocator_records (Allocator, std::ostream &)
 Print the allocations from a specific allocator in a human-readable format. More...
 
std::vector< util::AllocationRecordget_allocator_records (Allocator)
 Returns vector of AllocationRecords created by the allocator. More...
 

Constructor & Destructor Documentation

◆ ~ResourceManager()

umpire::ResourceManager::~ResourceManager ( )

◆ ResourceManager()

umpire::ResourceManager::ResourceManager ( const ResourceManager )
delete

Member Function Documentation

◆ getInstance()

◆ initialize()

◆ getAllocatorNames()

std::vector< std::string > umpire::ResourceManager::getAllocatorNames ( ) const
noexcept

Get the names of all available Allocator objects.

References umpire::util::message::Debug, and UMPIRE_LOG.

◆ getAllocatorIds()

std::vector< int > umpire::ResourceManager::getAllocatorIds ( ) const
noexcept

Get the ids of all available Allocator objects.

◆ getAllocator() [1/5]

◆ getAllocator() [2/5]

Allocator umpire::ResourceManager::getAllocator ( const char *  name)

References getAllocator().

◆ getAllocator() [3/5]

Allocator umpire::ResourceManager::getAllocator ( resource::MemoryResourceType  resource_type)

Get the default Allocator for the given resource_type.

References umpire::util::message::Debug, getAllocator(), umpire::resource::resource_to_string(), and UMPIRE_LOG.

◆ getAllocator() [4/5]

Allocator umpire::ResourceManager::getAllocator ( int  id)

Get the Allocator with the given ID.

References umpire::util::message::Debug, UMPIRE_ERROR, and UMPIRE_LOG.

◆ getDefaultAllocator()

Allocator umpire::ResourceManager::getDefaultAllocator ( )

Get the default Allocator.

The default Allocator is used whenever an Allocator is required and one is not provided, or cannot be inferred.

Returns
The default Allocator.

References umpire::util::message::Debug, umpire::Allocator::getAllocationStrategy(), getAllocator(), and UMPIRE_LOG.

Referenced by umpire::malloc(), and reallocate().

◆ getResourceNames()

std::vector< std::string > umpire::ResourceManager::getResourceNames ( )

Get the names for existing Resources.

The Memory Resource Registry dynamically populates available memory resource types based on what's available. This function returns those names so they can be used to determine allocator accessibility.

Returns
The available resource names.

References umpire::resource::MemoryResourceRegistry::getInstance(), and umpire::resource::MemoryResourceRegistry::getResourceNames().

◆ getSharedAllocatorNames()

std::vector< std::string > umpire::ResourceManager::getSharedAllocatorNames ( )

Get the names for existing SHARED Allocator names, if any.

The SHARED memory resource only indicates whether or not these SHARED allocators exist. Since SHARED allocators are made at runtime, this function will actually find the specific name of each SHARED allocator and return it.

Returns
A vector of strings with the available SHARED allocator names.

References umpire::util::message::Debug, and UMPIRE_LOG.

◆ setDefaultAllocator()

void umpire::ResourceManager::setDefaultAllocator ( Allocator  allocator)
noexcept

Set the default Allocator.

The default Allocator is used whenever an Allocator is required and one is not provided, or cannot be inferred.

Parameters
allocatorThe Allocator to use as the default.

References umpire::util::message::Debug, umpire::event::operation, umpire::event::record(), and UMPIRE_LOG.

◆ makeAllocator() [1/2]

template<typename Strategy , bool introspection, typename... Args>
Allocator umpire::ResourceManager::makeAllocator ( const std::string &  name,
Args &&...  args 
)

Construct a new Allocator.

References umpire::Tracked, and umpire::Untracked.

Referenced by umpire_resourcemanager_make_allocator_advisor(), umpire_resourcemanager_make_allocator_aligned_allocator(), umpire_resourcemanager_make_allocator_bufferify_advisor(), umpire_resourcemanager_make_allocator_bufferify_aligned_allocator(), umpire_resourcemanager_make_allocator_bufferify_fixed_pool(), umpire_resourcemanager_make_allocator_bufferify_list_pool(), umpire_resourcemanager_make_allocator_bufferify_mixed_pool(), umpire_resourcemanager_make_allocator_bufferify_monotonic(), umpire_resourcemanager_make_allocator_bufferify_named(), umpire_resourcemanager_make_allocator_bufferify_naming_shim(), umpire_resourcemanager_make_allocator_bufferify_prefetcher(), umpire_resourcemanager_make_allocator_bufferify_quick_pool(), umpire_resourcemanager_make_allocator_bufferify_resource_aware_pool(), umpire_resourcemanager_make_allocator_bufferify_size_limiter(), umpire_resourcemanager_make_allocator_bufferify_slot_pool(), umpire_resourcemanager_make_allocator_bufferify_thread_safe(), umpire_resourcemanager_make_allocator_fixed_pool(), umpire_resourcemanager_make_allocator_fixed_pool_untracked(), umpire_resourcemanager_make_allocator_fixed_pool_untracked_bufferify(), umpire_resourcemanager_make_allocator_list_pool(), umpire_resourcemanager_make_allocator_list_pool_untracked(), umpire_resourcemanager_make_allocator_list_pool_untracked_bufferify(), umpire_resourcemanager_make_allocator_mixed_pool(), umpire_resourcemanager_make_allocator_mixed_pool_untracked(), umpire_resourcemanager_make_allocator_mixed_pool_untracked_bufferify(), umpire_resourcemanager_make_allocator_monotonic(), umpire_resourcemanager_make_allocator_monotonic_untracked(), umpire_resourcemanager_make_allocator_monotonic_untracked_bufferify(), umpire_resourcemanager_make_allocator_named(), umpire_resourcemanager_make_allocator_naming_shim(), umpire_resourcemanager_make_allocator_prefetcher(), umpire_resourcemanager_make_allocator_quick_pool(), umpire_resourcemanager_make_allocator_quick_pool_untracked(), umpire_resourcemanager_make_allocator_quick_pool_untracked_bufferify(), umpire_resourcemanager_make_allocator_resource_aware_pool(), umpire_resourcemanager_make_allocator_resource_aware_pool_untracked(), umpire_resourcemanager_make_allocator_resource_aware_pool_untracked_bufferify(), umpire_resourcemanager_make_allocator_size_limiter(), umpire_resourcemanager_make_allocator_slot_pool(), umpire_resourcemanager_make_allocator_slot_pool_untracked(), umpire_resourcemanager_make_allocator_slot_pool_untracked_bufferify(), and umpire_resourcemanager_make_allocator_thread_safe().

◆ makeAllocator() [2/2]

template<typename Strategy , typename... Args>
Allocator umpire::ResourceManager::makeAllocator ( const std::string &  name,
Tracking  tracked,
Args &&...  args 
)

◆ makeResource() [1/2]

Allocator umpire::ResourceManager::makeResource ( const std::string &  name)

◆ makeResource() [2/2]

◆ addAlias()

void umpire::ResourceManager::addAlias ( const std::string &  name,
Allocator  allocator 
)

Add an Allocator alias.

After this call, allocator can be retrieved by calling getAllocator(name).

The same Allocator can have multiple aliases.

Parameters
nameName to alias Allocator with.
allocatorAllocator to register.

References umpire::Allocator::getAllocationStrategy(), getAllocator(), isAllocator(), and UMPIRE_ERROR.

Referenced by umpire_resourcemanager_add_alias(), and umpire_resourcemanager_add_alias_bufferify().

◆ removeAlias()

void umpire::ResourceManager::removeAlias ( const std::string &  name,
Allocator  allocator 
)

Remove an Allocator alias.

After calling, allocator can no longer be accessed by calling getAllocator(name). If allocator is not registered under name, an error will be thrown.

If one of the default resource names (e.g. HOST) is used, an error will be thrown.

Parameters
nameName to deregister Allocator with.
allocatorAllocator to deregister.

References umpire::Allocator::getId(), umpire::Allocator::getName(), isAllocator(), and UMPIRE_ERROR.

Referenced by umpire_resourcemanager_remove_alias(), and umpire_resourcemanager_remove_alias_bufferify().

◆ destroyAllocator() [1/2]

void umpire::ResourceManager::destroyAllocator ( const std::string &  name,
bool  free_allocations = false 
)

Destroy an allocator by name.

Removes the allocator from the ResourceManager and frees associated resources. Core resource allocators (HOST, DEVICE, etc.) cannot be destroyed.

Behavior is controlled by the UMPIRE_STRICT_DESTRUCTION environment variable:

If UMPIRE_STRICT_DESTRUCTION is set (to any value):

  • Throws error if allocator has active allocations and free_allocations=false
  • Throws error if allocator is a parent of other allocators

If UMPIRE_STRICT_DESTRUCTION is not set (default):

  • Logs warning but proceeds if allocator has active allocations
  • Logs warning but proceeds if allocator is a parent

Example: export UMPIRE_STRICT_DESTRUCTION=1 // Enable strict mode unset UMPIRE_STRICT_DESTRUCTION // Disable strict mode (default)

Parameters
nameName of the allocator to destroy
free_allocationsIf true, deallocates all active allocations before destroying. Defaults to false.
Exceptions
runtime_errorif allocator is a core resource or not found

References umpire::util::message::Debug, deregisterAllocation(), umpire::get_allocator_records(), umpire::strategy::AllocationStrategy::getId(), umpire::strategy::AllocationStrategy::getName(), umpire::strategy::AllocationStrategy::getParent(), umpire::event::operation, umpire::event::record(), UMPIRE_ERROR, UMPIRE_LOG, and umpire::util::message::Warning.

Referenced by destroyAllocator(), umpire_resourcemanager_destroy_allocator_by_id(), umpire_resourcemanager_destroy_allocator_by_id_with_free(), umpire_resourcemanager_destroy_allocator_by_name(), umpire_resourcemanager_destroy_allocator_by_name_bufferify(), umpire_resourcemanager_destroy_allocator_by_name_with_free(), and umpire_resourcemanager_destroy_allocator_by_name_with_free_bufferify().

◆ destroyAllocator() [2/2]

void umpire::ResourceManager::destroyAllocator ( int  id,
bool  free_allocations = false 
)

Destroy an allocator by ID.

See destroyAllocator(const std::string&, bool) for detailed behavior.

Parameters
idID of the allocator to destroy
free_allocationsIf true, deallocates all active allocations before destroying. Defaults to false.
Exceptions
runtime_errorif allocator is a core resource or not found

References umpire::util::message::Debug, destroyAllocator(), UMPIRE_ERROR, and UMPIRE_LOG.

◆ getAllocator() [5/5]

Allocator umpire::ResourceManager::getAllocator ( void *  ptr)

Get the Allocator used to allocate ptr.

Parameters
ptrPointer to find the Allocator for.
Returns
Allocator for the given ptr.

References umpire::util::message::Debug, and UMPIRE_LOG.

◆ isAllocator() [1/2]

◆ isAllocator() [2/2]

bool umpire::ResourceManager::isAllocator ( int  id)
noexcept

◆ hasAllocator()

bool umpire::ResourceManager::hasAllocator ( void *  ptr)

Does the given pointer have an associated Allocator.

Returns
True if the pointer has an associated Allocator.

References umpire::util::AllocationMap::contains(), umpire::util::message::Debug, and UMPIRE_LOG.

Referenced by umpire_resourcemanager_has_allocator().

◆ registerAllocation()

◆ deregisterAllocation()

util::AllocationRecord umpire::ResourceManager::deregisterAllocation ( void *  ptr)

◆ findAllocationRecord()

const util::AllocationRecord * umpire::ResourceManager::findAllocationRecord ( void *  ptr) const

Find the allocation record associated with an address ptr.

Returns
the record if found, or throws an exception if not found.

References umpire::util::message::Debug, umpire::util::AllocationMap::find(), UMPIRE_ERROR, and UMPIRE_LOG.

◆ copy() [1/2]

void umpire::ResourceManager::copy ( void *  dst_ptr,
void *  src_ptr,
std::size_t  size = 0 
)

Copy size bytes of data from src_ptr to dst_ptr.

Both the src_ptr and dst_ptr addresses must be allocated by Umpire. They can be offset from any Umpire-managed base address.

The dst_ptr must be large enough to accommodate size bytes of data.

Parameters
dst_ptrDestination pointer.
src_ptrSource pointer.
sizeSize in bytes.

References umpire::util::message::Debug, umpire::util::AllocationMap::find(), umpire::op::MemoryOperationRegistry::getInstance(), umpire::event::operation, umpire::event::record(), umpire::util::AllocationRecord::size, UMPIRE_ERROR, and UMPIRE_LOG.

Referenced by move(), umpire::op::GenericReallocateOperation::transform(), umpire::op::HostReallocateOperation::transform(), umpire::op::GenericReallocateOperation::transform_async(), umpire_resourcemanager_copy_all(), and umpire_resourcemanager_copy_with_size().

◆ copy() [2/2]

◆ memset() [1/2]

void umpire::ResourceManager::memset ( void *  ptr,
int  val,
std::size_t  length = 0 
)

◆ memset() [2/2]

◆ reallocate() [1/4]

void * umpire::ResourceManager::reallocate ( void *  current_ptr,
std::size_t  new_size 
)

Reallocate current_ptr to new_size.

Parameters
current_ptrSource pointer to reallocate.
new_sizeNew size of pointer.

If current_ptr is nullptr, then the default allocator will be used to allocate data. The default allocator may be set with a call to setDefaultAllocator(Allocator allocator).

NOTE 1: This is not thread safe NOTE 2: If the allocator for which current_ptr is intended is different from the default allocator, then all subsequent reallocate calls will result in allocations from the default allocator which may not be the intended behavior.

If new_size is 0, then the current_ptr will be deallocated if it is not a nullptr, and a zero-byte allocation will be returned.

Returns
Reallocated pointer.

References umpire::util::AllocationMap::find(), umpire::Allocator::getAllocationStrategy(), getDefaultAllocator(), umpire::event::operation, and umpire::event::record().

Referenced by umpire_resourcemanager_reallocate_default(), and umpire_resourcemanager_reallocate_with_allocator().

◆ reallocate() [2/4]

void * umpire::ResourceManager::reallocate ( void *  current_ptr,
std::size_t  new_size,
camp::resources::Resource ctx 
)

◆ reallocate() [3/4]

void * umpire::ResourceManager::reallocate ( void *  current_ptr,
std::size_t  new_size,
Allocator  allocator 
)

Reallocate current_ptr to new_size.

Parameters
current_ptrSource pointer to reallocate.
new_sizeNew size of pointer.
allocatorAllocator to use if current_ptr is null.

If current_ptr is null, then allocator will be used to allocate the data.

If new_size is 0, then the current_ptr will be deallocated if it is not a nullptr, and a zero-byte allocation will be returned.

Returns
Reallocated pointer.

References umpire::Allocator::getAllocationStrategy(), umpire::Allocator::getName(), umpire::event::operation, and umpire::event::record().

◆ reallocate() [4/4]

void * umpire::ResourceManager::reallocate ( void *  current_ptr,
std::size_t  new_size,
Allocator  allocator,
camp::resources::Resource ctx 
)

◆ move()

void * umpire::ResourceManager::move ( void *  src_ptr,
Allocator  allocator 
)

◆ deallocate()

void umpire::ResourceManager::deallocate ( void *  ptr)

Deallocate any pointer allocated by an Umpire-managed resource.

Parameters
ptrPointer to deallocate.

References umpire::util::message::Debug, and UMPIRE_LOG.

Referenced by umpire::free(), move(), and umpire_resourcemanager_deallocate().

◆ prefetch()

camp::resources::EventProxy< camp::resources::Resource > umpire::ResourceManager::prefetch ( void *  ptr,
int  device,
camp::resources::Resource ctx 
)

Asynchronously prefetch memory ptr to device.

Parameters
ptrPointer to prefech
deviceDevice to prefetch data to
ctxResource to use for asynchronous operation

References umpire::util::message::Debug, umpire::util::AllocationMap::find(), umpire::op::MemoryOperationRegistry::getInstance(), umpire::MemoryResourceTraits::um, UMPIRE_ERROR, and UMPIRE_LOG.

◆ getSize()

std::size_t umpire::ResourceManager::getSize ( void *  ptr) const

Get the size in bytes of the allocation for the given pointer.

Parameters
ptrPointer to find size of.
Returns
Size of allocation in bytes.

References umpire::util::message::Debug, umpire::util::AllocationMap::find(), umpire::event::record(), and UMPIRE_LOG.

Referenced by umpire::Allocator::getSize(), and umpire_resourcemanager_get_size().

◆ getInternalMemoryUsage()

std::size_t umpire::ResourceManager::getInternalMemoryUsage ( ) const

◆ getOperation()

std::shared_ptr< op::MemoryOperation > umpire::ResourceManager::getOperation ( const std::string &  operation_name,
Allocator  src_allocator,
Allocator  dst_allocator 
)

◆ getNumDevices()

int umpire::ResourceManager::getNumDevices ( ) const

References UMPIRE_ERROR.

◆ operator=()

ResourceManager& umpire::ResourceManager::operator= ( const ResourceManager )
delete

Friends And Related Function Documentation

◆ print_allocator_records

void print_allocator_records ( Allocator  ,
std::ostream &   
)
friend

Print the allocations from a specific allocator in a human-readable format.

Parameters
allocatorsource Allocator.
osoutput stream

◆ get_allocator_records

std::vector<util::AllocationRecord> get_allocator_records ( Allocator  )
friend

Returns vector of AllocationRecords created by the allocator.

Parameters
allocatorsource Allocator.