legate::ScopedAllocator#

class ScopedAllocator#

A simple allocator backed by Buffer objects.

For each allocation request, this allocator creates a 1D Buffer of std::int8_t and returns the raw pointer to it. By default, all allocations are deallocated when the allocator is destroyed, and can optionally be made alive until the task finishes by making the allocator unscoped.

Public Functions

explicit ScopedAllocator(
Memory::Kind kind,
bool scoped = true,
std::size_t alignment = DEFAULT_ALIGNMENT
)#

Create a ScopedAllocator for a specific memory kind.

Parameters:
  • kindMemory::Kind of the memory on which the Buffer should be created

  • scoped – If true, the allocator is scoped; i.e., lifetimes of allocations are tied to the allocator’s lifetime. Otherwise, the allocations are alive until the task finishes (and unless explicitly deallocated).

  • alignment – Alignment for the allocations

Throws:

std::domain_error – If alignment is 0, or not a power of 2.

void *allocate(std::size_t bytes)#

Allocates a contiguous buffer of the given Memory::Kind

When the allocator runs out of memory, the runtime will fail with an error message. Otherwise, the function returns a valid pointer. If bytes is 0, returns nullptr.

See also

deallocate

Parameters:

bytes – Size of the allocation in bytes

Returns:

A raw pointer to the allocation

void deallocate(void *ptr)#

Deallocates an allocation.

The input pointer must be one that was previously returned by an allocate() call. If ptr is nullptr, this call does nothing.

See also

allocate

Parameters:

ptr – Pointer to the allocation to deallocate

Throws:

std::invalid_argument – If ptr was not allocated by this allocator.

class Impl#