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.

ScopedAllocator is copyable (primarily so types derived from ScopedAllocator can satisfy the Allocator named requirement <>_), but all copies share a reference to the same ScopedAllocator::Impl, so scoped deallocation will not occur until all copies go out of scope.

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 from allocate() (use allocate_aligned() to specify a different alignment)

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

See also

allocate_aligned

Parameters:

bytes – Size of the allocation in bytes

Returns:

A raw pointer to the allocation

void *allocate_aligned(std::size_t bytes, std::size_t alignment)#

Allocates a contiguous buffer of the given Memory::Kind with a specified alignment.

See also

deallocate

See also

allocate_aligned

Parameters:
  • bytes – Size of the allocation in bytes.

  • alignment – Alignment in bytes of this allocation.

Throws:

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

Returns:

A raw pointer to the allocation

template<typename T>
T *allocate_type(std::size_t num_items)#

Allocates a contiguous buffer of uninitialized Ts with the given Memory::Kind.

See also

deallocate

Parameters:

num_items – The number of items to allocate

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#

Detail-hiding implementation class for ScopedAllocator.

See also

ScopedAllocator