NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
nvneural::IRefObject Class Referenceabstract

Base class for all objects, similar to COM's IUnknown. More...

#include <nvneural/CoreTypes.h>

Inheritance diagram for nvneural::IRefObject:
nvneural::IActivationFunction nvneural::IActivationPlugin nvneural::IApiVersionQuery nvneural::IBackendDeviceIdentifier nvneural::IBatchNormalizationLayer nvneural::IBufferedLogger nvneural::IBypassLayer nvneural::IClassRegistry nvneural::IConcatenationLayer nvneural::IConvolutionLayer nvneural::ICppCodeGenerationLayer nvneural::ICppCodeGenerationLayerHost nvneural::ICudaCompiledFunction nvneural::ICudaInputLayer nvneural::ICudaMemoryAllocator nvneural::ICudaRuntimeCompiler nvneural::IFileImage nvneural::IFilesystemWeightsLoader nvneural::IImage nvneural::IInnerActivationLayer nvneural::IInputLayer nvneural::ILayer nvneural::ILayerList nvneural::ILayerPlugin nvneural::ILibraryContext nvneural::ILinearBlendLayer nvneural::ILogger nvneural::INetworkBackend nvneural::INetworkBackendCuda nvneural::INetworkDebugger nvneural::INetworkDebuggerList nvneural::INetworkLayer nvneural::INetworkReshapeDebugger nvneural::INetworkRuntime nvneural::IOnnxGenerationActivation nvneural::IOnnxGenerationGraphAttribute nvneural::IOnnxGenerationGraphNode nvneural::IOnnxGenerationHost nvneural::IOnnxGenerationLayer nvneural::IParameterNode nvneural::IPlugin nvneural::IPluginLoader nvneural::IPoolingLayer nvneural::IPrototypeLayer nvneural::IPrototypePlugin nvneural::IResourceAggregator nvneural::IResourceDictionary nvneural::IRuntimeOptionsHost nvneural::IRuntimeOptionsLayer nvneural::IShuffleLayer nvneural::IStandardInputLayer nvneural::IStatusMessageLayer nvneural::IStringList nvneural::IWeightsData nvneural::IWeightsLoader

Public Types

using RefCount = std::uint32_t
 Typedef used to track the number of active references to an object.
 
using TypeId = std::uint64_t
 Every interface must define a unique TypeId. This should be randomized.
 

Public Member Functions

virtual RefCount addRef () const noexcept=0
 Increments the object's reference count. More...
 
virtual const void * queryInterface (TypeId interface) const noexcept=0
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
virtual void * queryInterface (TypeId interface) noexcept=0
 Retrieves a new object interface pointer. More...
 
virtual RefCount release () const noexcept=0
 Decrements the object's reference count and destroy the object if the reference count reaches zero. More...
 

Static Public Attributes

static const TypeId typeID = 0x14ecc3f9de638e1dul
 Interface TypeId for InterfaceOf purposes.
 

Protected Member Functions

virtual ~IRefObject ()=default
 A protected destructor prevents accidental stack-allocation of IRefObjects or use with other smart pointer classes like std::unique_ptr.
 

Detailed Description

Base class for all objects, similar to COM's IUnknown.

Remarks
This library adopts the COM pattern of reference-counted, self-deleting objects with a custom RTTI implementation in lieu of dynamic_cast<>.

Why self-deleting: The only safe place to delete memory is from the module that allocated it. Modules linking with a static C runtime (or merely a different version of Microsoft's C runtime) will not necessarily use the same heap, and freeing memory inconsistently does lead to heap corruption bugs.

Why custom RTTI: C++ type_info structures are weak symbols on Linux. Loading a shared library with RTLD_LOCAL (needed for self-contained dependencies) breaks type_info equality, making dynamic_cast unreliable across module boundaries.

Major differences from IUnknown:

  • Type IDs are uint64_ts rather than GUIDs. Done because we do not anticipate this library to be used in a scenario that requires more than 2**64 unique interface IIDs. By reducing to uint64_t, an interface ID fits in a single register and does not require nonstandard __int128 types, pass-by-struct, or a dedicated comparison function (even if it's strcmp for string IID types).
  • No attempt to standardize ABI for 32-bit platforms. We use our platforms' native calling conventions, which removes the need for __cdecl annotations.
  • Our QueryInterface equivalent returns the out value directly instead of writing into a pointer. On failure (whether E_NOINTERFACE or something more catastrophic), the return value is nullptr.

As a matter of convention (and to work with the RefPtr helper class), all interface classes should have a static const TypeId member named typeID. You should use the InterfaceOf template to retrieve the interface's TypeId instead of accessing the member directly; this allows implementers to define other TypeId values via partial specialization without necessarily declaring the entire interface class.

Member Function Documentation

◆ addRef()

virtual RefCount nvneural::IRefObject::addRef ( ) const
pure virtualnoexcept

Increments the object's reference count.

Returns
The new reference count. Should be used only for debugging.

Implemented in nvneural::BufferedLogger.

◆ queryInterface()

virtual void* nvneural::IRefObject::queryInterface ( TypeId  interface)
pure virtualnoexcept

Retrieves a new object interface pointer.

Parameters
interfaceTypeId of the interface to convert to.
Returns
A new interface pointer suitable for static_cast<> from void, or nullptr on failure or if the interface is unsupported.
Note
Calls addRef on the resulting pointer.
Remarks
The standard rules of COM IUnknown::QueryInterface apply:
  1. Do not dynamically add or remove interfaces to an object.
  2. Reflexive rule: Querying for the interface you already have must succeed and return an identical pointer.
  3. Symmetric rule: All successful queries must be bidirectional.
  4. Transitive rule: Querying through intermediary interfaces must yield the same result as querying directly for the final interface.

Implemented in nvneural::BufferedLogger.

◆ release()

virtual RefCount nvneural::IRefObject::release ( ) const
pure virtualnoexcept

Decrements the object's reference count and destroy the object if the reference count reaches zero.

Returns
The new reference count. Should be used only for debugging.

Implemented in nvneural::BufferedLogger.


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