Classes | Public Member Functions | Static Public Member Functions | List of all members
kvikio::BounceBufferPool< Allocator > Class Template Reference

Thread-safe singleton pool for reusable bounce buffers. More...

#include <bounce_buffer.hpp>

Classes

class  Buffer
 RAII wrapper for a host bounce buffer allocation. More...
 

Public Member Functions

Buffer get ()
 Acquire a bounce buffer from the pool. More...
 
void put (void *buffer, std::size_t size)
 Return a buffer to the pool for reuse. More...
 
std::size_t clear ()
 Free all retained allocations in the pool. More...
 
 BounceBufferPool (BounceBufferPool const &)=delete
 
BounceBufferPooloperator= (BounceBufferPool const &)=delete
 
 BounceBufferPool (BounceBufferPool &&o)=delete
 
BounceBufferPooloperator= (BounceBufferPool &&o)=delete
 

Static Public Member Functions

static KVIKIO_EXPORT BounceBufferPoolinstance ()
 Get the singleton instance of the pool. More...
 

Detailed Description

template<typename Allocator = CudaPinnedAllocator>
class kvikio::BounceBufferPool< Allocator >

Thread-safe singleton pool for reusable bounce buffers.

Manages a pool of host memory buffers used for staging data during I/O operations. Buffers are retained and reused across calls to minimize allocation overhead. The pool uses a LIFO (stack) allocation strategy optimized for cache locality.

All buffers in the pool have the same size, controlled by defaults::bounce_buffer_size(). If the buffer size changes, all cached buffers are cleared and reallocated at the new size.

Call BounceBufferPool::get to get an allocation that will be retained when it goes out of scope (RAII). The size of all retained allocations are the same.

Template Parameters
AllocatorThe allocator policy that determines buffer properties:
Note
The destructor intentionally leaks allocations to avoid CUDA cleanup issues when static destructors run after CUDA context destruction

Definition at line 118 of file bounce_buffer.hpp.

Member Function Documentation

◆ clear()

template<typename Allocator = CudaPinnedAllocator>
std::size_t kvikio::BounceBufferPool< Allocator >::clear ( )

Free all retained allocations in the pool.

Clears the pool and deallocates all cached buffers. Useful for reclaiming memory when bounce buffers are no longer needed.

Returns
The number of bytes cleared

◆ get()

template<typename Allocator = CudaPinnedAllocator>
Buffer kvikio::BounceBufferPool< Allocator >::get ( )

Acquire a bounce buffer from the pool.

Returns a cached buffer if available, otherwise allocates a new one. The returned Buffer object will automatically return the buffer to the pool when it goes out of scope.

Returns
RAII Buffer object wrapping the allocated memory
Exceptions
CudaErrorif allocation fails (e.g., invalid CUDA context for pinned allocators)

◆ instance()

template<typename Allocator = CudaPinnedAllocator>
static KVIKIO_EXPORT BounceBufferPool& kvikio::BounceBufferPool< Allocator >::instance ( )
static

Get the singleton instance of the pool.

Each template instantiation (different Allocator) has its own singleton instance.

Returns
Reference to the singleton pool instance

◆ put()

template<typename Allocator = CudaPinnedAllocator>
void kvikio::BounceBufferPool< Allocator >::put ( void *  buffer,
std::size_t  size 
)

Return a buffer to the pool for reuse.

Typically called automatically by Buffer's destructor. Only adds the buffer to the pool if its size matches the current pool buffer size; otherwise the buffer is deallocated immediately.

Parameters
bufferPointer to memory to return
sizeSize of the buffer in bytes

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