Skip to main content

IGpuAllocator

Struct IGpuAllocator 

Source
pub struct IGpuAllocator { /* private fields */ }

Implementations§

Source§

impl IGpuAllocator

Source

pub fn allocate( self: Pin<&mut IGpuAllocator>, size: u64, alignment: u64, flags: u32, ) -> *mut c_void

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

  • size The size of the memory block required (in bytes).
  • alignment The 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.
  • flags Reserved for future use. In the current release, 0 will be passed.

If the allocation was successful, the start address of a device memory block of the requested size. If an allocation request of size 0 is made, nullptr must be returned. If an allocation request cannot be satisfied, nullptr must be returned. If a non-null address is returned, it is guaranteed to have the specified alignment.

The implementation must guarantee thread safety for concurrent allocate/reallocate/deallocate requests.

  • Allowed context for the API call
  • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads.

Deprecated in TensorRT 10.0. Superseded by allocateAsync

Source

pub unsafe fn reallocate( self: Pin<&mut IGpuAllocator>, arg1: *mut c_void, arg2: u64, arg3: u64, ) -> *mut c_void

A thread-safe 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.

  • baseAddr the address of the original allocation, which will have been returned by previously calling allocate() or reallocate() on the same object.
  • alignment The alignment used by the original allocation. This will be the same value that was previously passed to the allocate() or reallocate() call that returned baseAddr.
  • newSize The new memory size required (in bytes).

The address of the reallocated memory, or nullptr. If a non-null address is returned, it is guaranteed to have the specified alignment.

The implementation must guarantee thread safety for concurrent allocate/reallocate/deallocate requests.

  • Allowed context for the API call
  • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads.
Source

pub unsafe fn deallocate( self: Pin<&mut IGpuAllocator>, memory: *mut c_void, ) -> bool

A thread-safe 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().

  • memory A memory address that was previously returned by an allocate() or reallocate() call of the same allocator object.

True if the acquired memory is released successfully.

The implementation must guarantee thread safety for concurrent allocate/reallocate/deallocate requests.

  • Allowed context for the API call
  • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads. Deprecated in TensorRT 10.0. Superseded by deallocateAsync
Source

pub unsafe fn allocateAsync( self: Pin<&mut IGpuAllocator>, size: u64, alignment: u64, flags: u32, arg1: *mut CUstream_st, ) -> *mut c_void

A thread-safe callback implemented by the application to handle stream-ordered acquisition of GPU memory.

The default behavior is to call method allocate(), which is synchronous and thus loses any performance benefits of asynchronous allocation. If you want the benefits of asynchronous allocation, see discussion of IGpuAsyncAllocator vs. IGpuAllocator in the documentation for nvinfer1::IGpuAllocator.

  • size The size of the memory block required (in bytes).
  • alignment The 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.
  • flags Reserved for future use. In the current release, 0 will be passed.
  • stream specifies the cudaStream for asynchronous usage.

If the allocation was successful, the start address of a device memory block of the requested size. If an allocation request of size 0 is made, nullptr must be returned. If an allocation request cannot be satisfied, nullptr must be returned. If a non-null address is returned, it is guaranteed to have the specified alignment.

The implementation must guarantee thread safety for concurrent allocate/reallocate/deallocate requests.

  • Allowed context for the API call
  • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads.
Source

pub unsafe fn deallocateAsync( self: Pin<&mut IGpuAllocator>, memory: *mut c_void, arg1: *mut CUstream_st, ) -> bool

A thread-safe callback implemented by the application to handle stream-ordered release of GPU memory.

The default behavior is to call method deallocate(), which is synchronous and thus loses any performance benefits of asynchronous deallocation. If you want the benefits of asynchronous deallocation, see discussion of IGpuAsyncAllocator vs. IGpuAllocator in the documentation for nvinfer1::IGpuAllocator.

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

  • memory A memory address that was previously returned by an allocate() or reallocate() call of the same allocator object.
  • stream specifies the cudaStream for asynchronous usage.

True if the acquired memory is released successfully.

The implementation must guarantee thread safety for concurrent allocate/reallocate/deallocate requests.

The implementation is not required to be asynchronous. It is permitted to synchronize, albeit doing so will lose the performance advantage of asynchronous deallocation. Either way, it is critical that it not actually free the memory until the current stream position is reached.

  • Allowed context for the API call
  • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads.
Source

pub fn getInterfaceInfo<'a>( self: &'a IGpuAllocator, ) -> impl New<Output = InterfaceInfo> + 'a

Return version information associated with this interface. Applications must not override this method.

Trait Implementations§

Source§

impl AsRef<IVersionedInterface> for IGpuAllocator

Source§

fn as_ref(self: &IGpuAllocator) -> &IVersionedInterface

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Drop for IGpuAllocator

Source§

fn drop(self: &mut IGpuAllocator)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl ExternType for IGpuAllocator

Source§

type Kind = Opaque

Source§

type Id

A type-level representation of the type’s C++ namespace and type name. Read more
Source§

impl MakeCppStorage for IGpuAllocator

Source§

unsafe fn allocate_uninitialized_cpp_storage() -> *mut IGpuAllocator

Allocates heap space for this type in C++ and return a pointer to that space, but do not initialize that space (i.e. do not yet call a constructor). Read more
Source§

unsafe fn free_uninitialized_cpp_storage(arg0: *mut IGpuAllocator)

Frees a C++ allocation which has not yet had a constructor called. Read more
Source§

impl SharedPtrTarget for IGpuAllocator

Source§

impl UniquePtrTarget for IGpuAllocator

Source§

impl WeakPtrTarget for IGpuAllocator

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.