NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
nvneural::ScopedMemoryAllocation Class Reference

ScopedMemoryAllocation is a helper function for allocating memory blocks from the backend while adding the security and ease of use of the RAII idiom. More...

#include <ScopedMemoryAllocation.h>

Public Member Functions

void * asPointer ()
 Returns the pointer to the allocated memory block. More...
 
MemoryHandle handle () const
 Returns the memory handle of the allocated memory block. More...
 
 operator bool () const
 Returns true if the memory allocation is valid (non-null handle).
 
ScopedMemoryAllocationoperator= (const ScopedMemoryAllocation &copyFrom)=delete
 
ScopedMemoryAllocationoperator= (ScopedMemoryAllocation &&moveFrom)
 Takes ownership of an allocation from another ScopedMemoryAllocation. More...
 
 ScopedMemoryAllocation (const ScopedMemoryAllocation &copyFrom)=delete
 
 ScopedMemoryAllocation (INetworkBackend *pBackend, size_t bufferSize)
 Creates a temporary memory allocation using a network backend. More...
 
 ScopedMemoryAllocation (INetworkBackend *pBackend, size_t bufferSize, const char *pTrackingKey)
 Creates a temporary memory allocation, using a network backend, of the requested size and allows tracking of the memory block using a user-defined key. More...
 
 ScopedMemoryAllocation (ScopedMemoryAllocation &&moveFrom)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
 ~ScopedMemoryAllocation ()
 Frees the allocation.
 

Detailed Description

ScopedMemoryAllocation is a helper function for allocating memory blocks from the backend while adding the security and ease of use of the RAII idiom.

Usage notes: This is meant to be used only temporarily within a particular block of code. The class doesn't take a reference to the network backend. Check handle() for nullptr, which is the failure of allocation. Memory is freed automatically once out of scope.

Constructor & Destructor Documentation

◆ ScopedMemoryAllocation() [1/2]

nvneural::ScopedMemoryAllocation::ScopedMemoryAllocation ( INetworkBackend pBackend,
size_t  bufferSize 
)
inline

Creates a temporary memory allocation using a network backend.

The memory allocated is in the backend's address space (cuDevicePtr for CUDA).

Parameters
pBackendBackend performing the allocation
bufferSizeSize of buffer to request, in bytes

◆ ScopedMemoryAllocation() [2/2]

nvneural::ScopedMemoryAllocation::ScopedMemoryAllocation ( INetworkBackend pBackend,
size_t  bufferSize,
const char *  pTrackingKey 
)
inline

Creates a temporary memory allocation, using a network backend, of the requested size and allows tracking of the memory block using a user-defined key.

It is best practice to use the layer's name at this key. The memory allocated is in the backend's address space (cuDevicePtr for CUDA).

Parameters
pBackendBackend performing the allocation
bufferSizeSize of buffer to request, in bytes
pTrackingKeyA string key, usually the layer's name, which allows tracking of this allocation's information, nullptr to disable

Member Function Documentation

◆ asPointer()

void* nvneural::ScopedMemoryAllocation::asPointer ( )
inline

Returns the pointer to the allocated memory block.

Returns
A void pointer to the memory block.

◆ handle()

MemoryHandle nvneural::ScopedMemoryAllocation::handle ( ) const
inline

Returns the memory handle of the allocated memory block.

Returns
The memory handle, nullptr indicates a failed allocation.

◆ operator=()

ScopedMemoryAllocation& nvneural::ScopedMemoryAllocation::operator= ( ScopedMemoryAllocation &&  moveFrom)
inline

Takes ownership of an allocation from another ScopedMemoryAllocation.

Parameters
moveFromrvalue reference to the source allocation object

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