TensorRT  8.0.0
nvinfer1::IGpuAllocator Class Referenceabstract

Application-implemented class for controlling allocation on the GPU. More...

#include <NvInferRuntimeCommon.h>

Public Member Functions

virtual void * allocate (uint64_t size, uint64_t alignment, AllocatorFlags flags) noexcept=0
 
virtual void free (void *memory) noexcept=0
 
virtual ~IGpuAllocator ()=default
 
virtual void * reallocate (void *baseAddr, uint64_t alignment, uint64_t newSize) noexcept
 

Protected Member Functions

 IGpuAllocator (IGpuAllocator const &)=default
 
 IGpuAllocator (IGpuAllocator &&)=default
 
IGpuAllocatoroperator= (IGpuAllocator const &) &=default
 
IGpuAllocatoroperator= (IGpuAllocator &&) &=default
 

Detailed Description

Application-implemented class for controlling allocation on the GPU.

Constructor & Destructor Documentation

◆ ~IGpuAllocator()

virtual nvinfer1::IGpuAllocator::~IGpuAllocator ( )
virtualdefault

Destructor declared virtual as general good practice for a class with virtual methods. TensorRT never calls the destructor for an IGpuAllocator defined by the application.

Member Function Documentation

◆ allocate()

virtual void* nvinfer1::IGpuAllocator::allocate ( uint64_t  size,
uint64_t  alignment,
AllocatorFlags  flags 
)
pure virtualnoexcept

A callback implemented by the application to handle acquisition of GPU memory.

Parameters
sizeThe size of the memory required.
alignmentThe required alignment of memory. Alignment will be zero or a power of 2 not exceeding the alignment guaranteed by cudaMalloc. Thus this allocator can be safely implemented with cudaMalloc/cudaFree. An alignment value of zero indicates any alignment is acceptable.
flagsReserved for future use. In the current release, 0 will be passed.

If an allocation request of size 0 is made, nullptr should be returned.

If an allocation request cannot be satisfied, nullptr should be returned.

◆ free()

virtual void nvinfer1::IGpuAllocator::free ( void *  memory)
pure virtualnoexcept

A callback implemented by the application to handle release of GPU memory.

TensorRT may pass a nullptr to this function if it was previously returned by allocate().

Parameters
memoryThe acquired memory.

◆ reallocate()

virtual void* nvinfer1::IGpuAllocator::reallocate ( void *  baseAddr,
uint64_t  alignment,
uint64_t  newSize 
)
inlinevirtualnoexcept

A callback implemented by the application to resize an existing allocation.

Only allocations which were allocated with AllocatorFlag::kRESIZABLE will be resized.

Options are one of:

  • resize in place leaving min(oldSize, newSize) bytes unchanged and return the original address
  • move min(oldSize, newSize) bytes to a new location of sufficient size and return its address
  • return nullptr, to indicate that the request could not be fulfilled.

If nullptr is returned, TensorRT will assume that resize() is not implemented, and that the allocation at baseAddr is still valid.

This method is made available for use cases where delegating the resize strategy to the application provides an opportunity to improve memory management. One possible implementation is to allocate a large virtual device buffer and progressively commit physical memory with cuMemMap. CU_MEM_ALLOC_GRANULARITY_RECOMMENDED is suggested in this case.

TensorRT may call realloc to increase the buffer by relatively small amounts.

Parameters
baseAddrthe address of the original allocation.
alignmentThe alignment used by the original allocation.
newSizeThe new memory size required.
Returns
the address of the reallocated memory

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