API
 
Loading...
Searching...
No Matches
GenericBuffer< AllocFunc, FreeFunc > Class Template Reference

The GenericBuffer class is a templated class for buffers. More...

#include <buffers.hpp>

Collaboration diagram for GenericBuffer< AllocFunc, FreeFunc >:
Collaboration graph

Public Member Functions

 GenericBuffer (nvinfer1::DataType type=nvinfer1::DataType::kFLOAT)
 Construct an empty buffer.
 
 GenericBuffer (size_t size, nvinfer1::DataType type)
 Construct a buffer with the specified allocation size in bytes.
 
 GenericBuffer (GenericBuffer &&buf)
 
GenericBufferoperator= (GenericBuffer &&buf)
 
void * data ()
 Returns pointer to underlying array.
 
const void * data () const
 Returns pointer to underlying array.
 
size_t size () const
 Returns the size (in number of elements) of the buffer.
 
size_t nbBytes () const
 Returns the size (in bytes) of the buffer.
 
void resize (size_t newSize)
 Resizes the buffer. This is a no-op if the new size is smaller than or equal to the current capacity.
 
void resize (const nvinfer1::Dims &dims)
 Overload of resize that accepts Dims.
 
 ~GenericBuffer ()
 

Private Attributes

size_t mSize {0}
 
size_t mCapacity {0}
 
nvinfer1::DataType mType
 
void * mBuffer
 
AllocFunc allocFn
 
FreeFunc freeFn
 

Detailed Description

template<typename AllocFunc, typename FreeFunc>
class GenericBuffer< AllocFunc, FreeFunc >

The GenericBuffer class is a templated class for buffers.

This templated RAII (Resource Acquisition Is Initialization) class handles the allocation, deallocation, querying of buffers on both the device and the host. It can handle data of arbitrary types because it stores byte buffers. The template parameters AllocFunc and FreeFunc are used for the allocation and deallocation of the buffer. AllocFunc must be a functor that takes in (void** ptr, size_t size) and returns bool. ptr is a pointer to where the allocated buffer address should be stored. size is the amount of memory in bytes to allocate. The boolean indicates whether or not the memory allocation was successful. FreeFunc must be a functor that takes in (void* ptr) and returns void. ptr is the allocated buffer address. It must work with nullptr input.

Definition at line 103 of file buffers.hpp.

Constructor & Destructor Documentation

◆ GenericBuffer() [1/3]

template<typename AllocFunc , typename FreeFunc >
GenericBuffer< AllocFunc, FreeFunc >::GenericBuffer ( nvinfer1::DataType  type = nvinfer1::DataType::kFLOAT)
inline

Construct an empty buffer.

Definition at line 109 of file buffers.hpp.

◆ GenericBuffer() [2/3]

template<typename AllocFunc , typename FreeFunc >
GenericBuffer< AllocFunc, FreeFunc >::GenericBuffer ( size_t  size,
nvinfer1::DataType  type 
)
inline

Construct a buffer with the specified allocation size in bytes.

Definition at line 120 of file buffers.hpp.

◆ GenericBuffer() [3/3]

template<typename AllocFunc , typename FreeFunc >
GenericBuffer< AllocFunc, FreeFunc >::GenericBuffer ( GenericBuffer< AllocFunc, FreeFunc > &&  buf)
inline

Definition at line 131 of file buffers.hpp.

◆ ~GenericBuffer()

template<typename AllocFunc , typename FreeFunc >
GenericBuffer< AllocFunc, FreeFunc >::~GenericBuffer ( )
inline

Definition at line 217 of file buffers.hpp.

Member Function Documentation

◆ data() [1/2]

◆ data() [2/2]

◆ nbBytes()

template<typename AllocFunc , typename FreeFunc >
size_t GenericBuffer< AllocFunc, FreeFunc >::nbBytes ( ) const
inline

Returns the size (in bytes) of the buffer.

Definition at line 187 of file buffers.hpp.

Referenced by GenericBuffer< AllocFunc, FreeFunc >::GenericBuffer(), and GenericBuffer< AllocFunc, FreeFunc >::resize().

◆ operator=()

template<typename AllocFunc , typename FreeFunc >
GenericBuffer & GenericBuffer< AllocFunc, FreeFunc >::operator= ( GenericBuffer< AllocFunc, FreeFunc > &&  buf)
inline

Definition at line 143 of file buffers.hpp.

◆ resize() [1/2]

template<typename AllocFunc , typename FreeFunc >
void GenericBuffer< AllocFunc, FreeFunc >::resize ( const nvinfer1::Dims &  dims)
inline

Overload of resize that accepts Dims.

Definition at line 212 of file buffers.hpp.

◆ resize() [2/2]

template<typename AllocFunc , typename FreeFunc >
void GenericBuffer< AllocFunc, FreeFunc >::resize ( size_t  newSize)
inline

Resizes the buffer. This is a no-op if the new size is smaller than or equal to the current capacity.

Definition at line 195 of file buffers.hpp.

Referenced by GenericBuffer< AllocFunc, FreeFunc >::resize().

◆ size()

template<typename AllocFunc , typename FreeFunc >
size_t GenericBuffer< AllocFunc, FreeFunc >::size ( ) const
inline

Returns the size (in number of elements) of the buffer.

Definition at line 179 of file buffers.hpp.

Referenced by GenericBuffer< AllocFunc, FreeFunc >::nbBytes().

Member Data Documentation

◆ allocFn

template<typename AllocFunc , typename FreeFunc >
AllocFunc GenericBuffer< AllocFunc, FreeFunc >::allocFn
private

◆ freeFn

template<typename AllocFunc , typename FreeFunc >
FreeFunc GenericBuffer< AllocFunc, FreeFunc >::freeFn
private

◆ mBuffer

◆ mCapacity

template<typename AllocFunc , typename FreeFunc >
size_t GenericBuffer< AllocFunc, FreeFunc >::mCapacity {0}
private

◆ mSize

template<typename AllocFunc , typename FreeFunc >
size_t GenericBuffer< AllocFunc, FreeFunc >::mSize {0}
private

◆ mType

template<typename AllocFunc , typename FreeFunc >
nvinfer1::DataType GenericBuffer< AllocFunc, FreeFunc >::mType
private

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