rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
Public Member Functions | List of all members
rexlib::memory_allocator Class Referenceabstract

Abstract allocator of buffer objects on a memory_resource. More...

#include <rexlib/core/hardware/memory_allocator.hpp>

Public Member Functions

 memory_allocator (const memory_allocator &other)=delete
 
 memory_allocator (memory_allocator &&other)=delete
 
memory_allocator & operator= (const memory_allocator &other)=delete
 
memory_allocator & operator= (memory_allocator &&other)=delete
 
virtual const memory_resource & get_memory_resource () const noexcept=0
 Get the memory resource backing this allocator.
 
virtual std::size_t get_max_alignment () const noexcept=0
 Get the largest alignment this allocator can satisfy.
 
virtual std::shared_ptr< buffer > allocate (std::size_t size, std::size_t alignment, command_queue *queue_hint, command_token &pending)=0
 Allocate a new buffer on the backing memory resource.
 

Detailed Description

Abstract allocator of buffer objects on a memory_resource.

Concrete implementations are free to back themselves with anything that fits the underlying backend.

The allocator is also in charge of tracking the asynchronous use of the buffers it produces: when a buffer's shared ownership is dropped while device work referencing it is still in flight, the allocator either defers the actual release until that work has completed, or hands the memory out again together with the token of that work.

Member Function Documentation

◆ allocate()

virtual std::shared_ptr< buffer > rexlib::memory_allocator::allocate ( std::size_t  size,
std::size_t  alignment,
command_queue *  queue_hint,
command_token &  pending 
)
pure virtual

Allocate a new buffer on the backing memory resource.

The allocator may round size up to satisfy internal alignment or page granularity constraints; the resulting buffer's buffer::get_size may return a number greater than or equal to size .

Parameters
sizeRequested minimum size, in bytes.
alignmentRequested alignment, in bytes. Must be a power of two and not greater than get_max_alignment.
queue_hintOptional non-owning pointer to the queue on which the buffer is expected to be first used. The allocator may use it to hand out the memory that is cheapest to use there. The buffer can be used on any other queue as well.
pendingOutput parameter that receives the token of the commands that still use the memory handed out. The first use of the buffer has to wait for it. It is empty when nothing uses the memory.
Returns
The newly allocated buffer. Never null.
Exceptions
std::bad_alloc(or a backend-specific exception derived from std::exception) on allocation failure.
std::invalid_argumentif alignment is not a valid power of two within get_max_alignment.

◆ get_max_alignment()

virtual std::size_t rexlib::memory_allocator::get_max_alignment ( ) const
pure virtualnoexcept

Get the largest alignment this allocator can satisfy.

The returned value is the strictest alignment that may be passed to allocate. It is a power of two and is constant over the lifetime of the allocator.

Returns
Maximum supported alignment, in bytes.

◆ get_memory_resource()

virtual const memory_resource & rexlib::memory_allocator::get_memory_resource ( ) const
pure virtualnoexcept

Get the memory resource backing this allocator.

Returns
Reference to the backing memory resource.

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