cuda::experimental::stf::cached_block_allocator_fifo#

class cached_block_allocator_fifo : public cuda::experimental::stf::block_allocator_interface#

A block allocator with FIFO caching strategy.

This allocator wraps a root allocator and implements a caching mechanism to efficiently reuse previously allocated memory blocks.

When a memory block is requested, it first attempts to find a suitable block in the internal cache (free_cache). If no suitable block is found, a larger buffer is allocated from the root allocator, split into smaller blocks, and stored in the cache for future reuse.

The caching policy is FIFO (First-In-First-Out): freed blocks are appended to a queue and reused in the order they were deallocated.

At deinitialization (deinit()), all cached blocks and their associated large allocations are properly released by delegating to the root allocator.

Note

The allocator is thread-safe and uses a mutex to protect access to its internal cache.

Note

Deallocation does not immediately release memory back to the root allocator. Instead, deallocated blocks are stored in the cache for future reuse.

Public Functions

inline cached_block_allocator_fifo(
block_allocator_untyped root_allocator_,
)#

This constructor takes a root allocator which performs allocations when there is a cache miss.

inline virtual void *allocate(
backend_ctx_untyped &ctx,
const data_place &memory_node,
::std::ptrdiff_t &s,
event_list &prereqs,
) override#

Allocates a memory block.

Attempts to allocate a memory block from the internal cache if available.

Parameters:
  • ctx – The backend context (unused in this implementation).

  • memory_node – Memory location where the allocation should happen.

  • s – Pointer to the size of memory required.

  • prereqs – List of events that this allocation depends on.

Returns:

void* A pointer to the allocated memory block or nullptr if allocation fails.

inline virtual void deallocate(
backend_ctx_untyped&,
const data_place &memory_node,
event_list &prereqs,
void *ptr,
size_t sz,
) override#

Deallocates a memory block.

Puts the deallocated block back into the internal cache for future reuse.

Parameters:
  • ctx – The backend context (unused in this implementation).

  • memory_node – Memory location where the deallocation should happen.

  • prereqs – List of events that this deallocation depends on.

  • ptr – Pointer to the memory block to be deallocated.

  • sz – Size of the memory block.

inline virtual event_list deinit(backend_ctx_untyped &ctx) override#

De-initializes the allocator.

inline virtual ::std::string to_string() const override#

Returns a string representation of the allocator.

Returns:

std::string The string “cached_block_allocator”.

inline virtual void print_info() const override#

Prints additional information about the allocator.

This function currently prints no additional information.