TensorRT  7.2.1.6
NVIDIA TensorRT
Looking for a C++ dev who knows TensorRT?
I'm looking for work. Hire me!
samplesCommon::GenericBuffer< AllocFunc, FreeFunc > Class Template Reference

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

Inheritance diagram for samplesCommon::GenericBuffer< AllocFunc, FreeFunc >:
Collaboration diagram for samplesCommon::GenericBuffer< AllocFunc, FreeFunc >:

Public Member Functions

 GenericBuffer (nvinfer1::DataType type=nvinfer1::DataType::kFLOAT)
 Construct an empty buffer. More...
 
 GenericBuffer (size_t size, nvinfer1::DataType type)
 Construct a buffer with the specified allocation size in bytes. More...
 
 GenericBuffer (GenericBuffer &&buf)
 
GenericBufferoperator= (GenericBuffer &&buf)
 
void * data ()
 Returns pointer to underlying array. More...
 
const void * data () const
 Returns pointer to underlying array. More...
 
size_t size () const
 Returns the size (in number of elements) of the buffer. More...
 
size_t nbBytes () const
 Returns the size (in bytes) of the buffer. More...
 
void resize (size_t newSize)
 Resizes the buffer. More...
 
void resize (const nvinfer1::Dims &dims)
 Overload of resize that accepts Dims. More...
 
 ~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 samplesCommon::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.

Constructor & Destructor Documentation

◆ GenericBuffer() [1/3]

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

Construct an empty buffer.

◆ GenericBuffer() [2/3]

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

Construct a buffer with the specified allocation size in bytes.

◆ GenericBuffer() [3/3]

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

◆ ~GenericBuffer()

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

Member Function Documentation

◆ operator=()

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

◆ data() [1/2]

template<typename AllocFunc , typename FreeFunc >
void* samplesCommon::GenericBuffer< AllocFunc, FreeFunc >::data ( )
inline

Returns pointer to underlying array.

Here is the caller graph for this function:

◆ data() [2/2]

template<typename AllocFunc , typename FreeFunc >
const void* samplesCommon::GenericBuffer< AllocFunc, FreeFunc >::data ( ) const
inline

Returns pointer to underlying array.

◆ size()

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

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

Here is the caller graph for this function:

◆ nbBytes()

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

Returns the size (in bytes) of the buffer.

Here is the caller graph for this function:

◆ resize() [1/2]

template<typename AllocFunc , typename FreeFunc >
void samplesCommon::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.

Here is the caller graph for this function:

◆ resize() [2/2]

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

Overload of resize that accepts Dims.

Here is the caller graph for this function:

Member Data Documentation

◆ mSize

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

◆ mCapacity

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

◆ mType

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

◆ mBuffer

template<typename AllocFunc , typename FreeFunc >
void* samplesCommon::GenericBuffer< AllocFunc, FreeFunc >::mBuffer
private

◆ allocFn

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

◆ freeFn

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

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