OpenNN
Open-source neural networks library
Loading...
Searching...
No Matches
opennn::Buffer Struct Reference

Owning raw byte buffer that lives on CPU or CUDA memory, with aligned (re)allocation. More...

#include <tensor_utilities.h>

Public Member Functions

template<typename T>
T * as ()
 Reinterprets the buffer as a typed pointer (no bounds checking).
 
template<typename T>
const T * as () const
 Reinterprets the buffer as a typed const pointer.
 
Index size_in_floats () const
 Capacity expressed in float elements.
 
bool empty () const
 Returns true if no storage is allocated.
 
void resize_bytes (Index new_bytes, Device new_device_type)
 Resizes the buffer to new_bytes on new_device_type, freeing prior storage.
 
void grow_to (Index new_bytes)
 Grows the buffer to at least new_bytes; no-op if already large enough.
 
template<typename T>
T * ensure (Index n_elements)
 Ensures the buffer holds at least n_elements of T and returns a typed pointer.
 
void setZero ()
 Zeros all bytes in the buffer (cudaMemset on device, memset on host).
 
 Buffer (Device new_device_type=Device::CPU) noexcept
 Constructs an empty buffer targeting the given device type.
 
 Buffer (const Buffer &)=delete
 
Bufferoperator= (const Buffer &)=delete
 
 Buffer (Buffer &&other) noexcept
 
Bufferoperator= (Buffer &&other) noexcept
 
 ~Buffer ()
 
void swap (Buffer &other) noexcept
 Swaps storage with another buffer.
 

Public Attributes

void * data = nullptr
 
Index bytes = 0
 
Device device_type = Device::CPU
 

Detailed Description

Owning raw byte buffer that lives on CPU or CUDA memory, with aligned (re)allocation.

Constructor & Destructor Documentation

◆ Buffer() [1/3]

opennn::Buffer::Buffer ( Device new_device_type = Device::CPU)
inlineexplicitnoexcept

Constructs an empty buffer targeting the given device type.

◆ Buffer() [2/3]

opennn::Buffer::Buffer ( const Buffer & )
delete

◆ Buffer() [3/3]

opennn::Buffer::Buffer ( Buffer && other)
inlinenoexcept

◆ ~Buffer()

opennn::Buffer::~Buffer ( )
inline

Member Function Documentation

◆ as() [1/2]

template<typename T>
T * opennn::Buffer::as ( )
inlinenodiscard

Reinterprets the buffer as a typed pointer (no bounds checking).

◆ as() [2/2]

template<typename T>
const T * opennn::Buffer::as ( ) const
inlinenodiscard

Reinterprets the buffer as a typed const pointer.

◆ empty()

bool opennn::Buffer::empty ( ) const
inlinenodiscard

Returns true if no storage is allocated.

◆ ensure()

template<typename T>
T * opennn::Buffer::ensure ( Index n_elements)
inline

Ensures the buffer holds at least n_elements of T and returns a typed pointer.

◆ grow_to()

void opennn::Buffer::grow_to ( Index new_bytes)
inline

Grows the buffer to at least new_bytes; no-op if already large enough.

◆ operator=() [1/2]

Buffer & opennn::Buffer::operator= ( Buffer && other)
inlinenoexcept

◆ operator=() [2/2]

Buffer & opennn::Buffer::operator= ( const Buffer & )
delete

◆ resize_bytes()

void opennn::Buffer::resize_bytes ( Index new_bytes,
Device new_device_type )
inline

Resizes the buffer to new_bytes on new_device_type, freeing prior storage.

◆ setZero()

void opennn::Buffer::setZero ( )
inline

Zeros all bytes in the buffer (cudaMemset on device, memset on host).

◆ size_in_floats()

Index opennn::Buffer::size_in_floats ( ) const
inlinenodiscard

Capacity expressed in float elements.

◆ swap()

void opennn::Buffer::swap ( Buffer & other)
inlinenoexcept

Swaps storage with another buffer.

Member Data Documentation

◆ bytes

Index opennn::Buffer::bytes = 0

◆ data

void* opennn::Buffer::data = nullptr

◆ device_type

Device opennn::Buffer::device_type = Device::CPU