Class ResourceManager

Class Documentation

class ResourceManager

Public Functions

void initialize()

Initialize the ResourceManager.

This will create all registered MemoryResource objects

std::vector<std::string> getAllocatorNames() const

Get the names of all available Allocator objects.

std::vector<int> getAllocatorIds() const

Get the ids of all available Allocator objects.

Allocator getAllocator(const std::string &name)

Get the Allocator with the given name.

Allocator getAllocator(const char *name)
Allocator getAllocator(resource::MemoryResourceType resource_type)

Get the default Allocator for the given resource_type.

Allocator getAllocator(int id)

Get the Allocator with the given ID.

Allocator getDefaultAllocator()

Get the default Allocator.

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

Return

The default Allocator.

void setDefaultAllocator(Allocator allocator)

Set the default Allocator.

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

Parameters
  • allocator: The Allocator to use as the default.

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

Construct a new Allocator.

void registerAllocator(const std::string &name, Allocator allocator)

Register an Allocator with the ResourceManager.

After registration, the Allocator can be retrieved by calling getAllocator(name).

The same Allocator can be registered under multiple names.

Parameters

Allocator getAllocator(void *ptr)

Get the Allocator used to allocate ptr.

Return

Allocator for the given ptr.

Parameters

bool isAllocator(const std::string &name)
bool hasAllocator(void *ptr)

Does the given pointer have an associated Allocator.

Return

True if the pointer has an associated Allocator.

void registerAllocation(void *ptr, util::AllocationRecord record)

register an allocation with the manager.

util::AllocationRecord deregisterAllocation(void *ptr)

de-register the address ptr with the manager.

Return

the allocation record removed from the manager.

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

Find the allocation record associated with an address ptr.

Return

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

bool isAllocatorRegistered(const std::string &name)

Check whether the named Allocator exists.

void 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_ptr: Destination pointer.

  • src_ptr: Source pointer.

  • size: Size in bytes.

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

Set the first length bytes of ptr to the value val.

Parameters
  • ptr: Pointer to data.

  • val: Value to set.

  • length: Number of bytes to set to val.

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

Reallocate current_ptr to new_size.

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).
Parameters
  • current_ptr: Source pointer to reallocate.

  • new_size: New size of pointer.

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.

Return

Reallocated pointer.

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

Reallocate current_ptr to new_size.

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

Parameters
  • current_ptr: Source pointer to reallocate.

  • new_size: New size of pointer.

  • allocator: Allocator to use if current_ptr is null.

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.

Return

Reallocated pointer.

void *move(void *src_ptr, Allocator allocator)

Move src_ptr to memory from allocator.

Return

Pointer to new location of data.

Parameters
  • src_ptr: Pointer to move.

  • allocator: Allocator to use to allocate new memory for moved data.

void deallocate(void *ptr)

Deallocate any pointer allocated by an Umpire-managed resource.

Parameters
  • ptr: Pointer to deallocate.

std::size_t getSize(void *ptr) const

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

Return

Size of allocation in bytes.

Parameters
  • ptr: Pointer to find size of.

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

Public Static Functions

static ResourceManager &getInstance()