Skip to content

tenzr::PinnedBuffer

More...

#include <memory_pool.h>

Public Functions

Name
PinnedBuffer(size_t size_bytes, bool page_locked =true)
~PinnedBuffer()
Release the buffer, invoking the external deleter when one is set.
PinnedBuffer(const PinnedBuffer & ) =delete
PinnedBuffer & operator=(const PinnedBuffer & ) =delete
PinnedBuffer(PinnedBuffer && other)
PinnedBuffer & operator=(PinnedBuffer && other)
void * Data()
Raw pointer to the buffer, or nullptr when empty.
const void * Data() const
size_t SizeBytes() const
Buffer capacity in bytes.
bool IsPageLocked() const
Whether the memory is page-locked.
template <typename T >
T *
As()
Reinterpret the buffer as an array of T.
template <typename T >
const T *
As() const
std::shared_ptr< PinnedBuffer > Wrap(void * data, size_t size_bytes, std::function< void()> deleter)

Detailed Description

class tenzr::PinnedBuffer;

Owned, optionally page-locked host buffer used for array storage and device transfers.

Public Functions Documentation

function PinnedBuffer

explicit PinnedBuffer(
    size_t size_bytes,
    bool page_locked =true
)

Parameters:

  • size_bytes Requested capacity in bytes.
  • page_locked When true, attempt to mlock the allocation.

Allocate a page-aligned host buffer, optionally locking it into RAM.

function ~PinnedBuffer

~PinnedBuffer()

Release the buffer, invoking the external deleter when one is set.

function PinnedBuffer

PinnedBuffer(
    const PinnedBuffer & 
) =delete

function operator=

PinnedBuffer & operator=(
    const PinnedBuffer & 
) =delete

function PinnedBuffer

PinnedBuffer(
    PinnedBuffer && other
)

Parameters:

  • other Buffer to move from.

Move-construct a buffer, leaving other empty.

function operator=

PinnedBuffer & operator=(
    PinnedBuffer && other
)

function Data

inline void * Data()

Raw pointer to the buffer, or nullptr when empty.

function Data

inline const void * Data() const

function SizeBytes

inline size_t SizeBytes() const

Buffer capacity in bytes.

function IsPageLocked

inline bool IsPageLocked() const

Whether the memory is page-locked.

function As

template <typename T >
inline T * As()

Reinterpret the buffer as an array of T.

function As

template <typename T >
inline const T * As() const

function Wrap

static std::shared_ptr< PinnedBuffer > Wrap(
    void * data,
    size_t size_bytes,
    std::function< void()> deleter
)

Parameters:

  • data Pointer to the external memory.
  • size_bytes Size of the memory region.
  • deleter Callback invoked on release.

Return: Owning shared pointer around the wrapped region.

Wrap externally-owned memory (e.g. a DLPack buffer) without copying. The deleter runs exactly once when the last reference to the buffer is released.

Wrap externally owned memory in a PinnedBuffer without taking over allocation.