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

ClassRegistry is the default implementation for IClassRegistry. More...

#include <ClassRegistry.h>

Inheritance diagram for nvneural::ClassRegistry:
nvneural::refobj::RefObjectBase< refobj::Implements< IClassRegistry > >

Public Types

using CreationFunction = IRefObject *(*)()
 Typedef for factory functions that take no arguments and return a new IRefObject.
 

Public Member Functions

 ClassRegistry ()
 Creates a new ClassRegistry containing statically-registered descriptors and object classes.
 
NeuralResult createObject (IRefObject **ppOut, const char *pObjectClass) const noexcept final
 Creates the designated object using its manifest-specified class name. More...
 
const ActivationDescexportedActivationByIndex (std::size_t index) const noexcept final
 Returns a registered activation function descriptor for a given index. More...
 
std::size_t exportedActivationsCount () const noexcept final
 Returns the count of registered activation functions. More...
 
const FusingRuleexportedFusingRuleByIndex (std::size_t index) const noexcept final
 Returns a registered fusing rule for a given index. More...
 
std::size_t exportedFusingRulesCount () const noexcept final
 Returns the count of registered fusing rules. More...
 
const LayerDescexportedLayerByIndex (std::size_t index) const noexcept final
 Returns a registered layer descriptor for a given index. More...
 
std::size_t exportedLayersCount () const noexcept final
 Returns the count of registered layers. More...
 
const PrototypeDescexportedPrototypeByIndex (std::size_t index) const noexcept final
 Returns a registered prototype layer descriptor for a given index. More...
 
PrototypeRuntimeValidatorFunction exportedPrototypeRuntimeValidatorByIndex (std::size_t index) const noexcept final
 Returns the runtime validator of a registered prototype layer for a given index. More...
 
std::size_t exportedPrototypesCount () const noexcept final
 Returns the count of registered prototype layers. More...
 
NeuralResult importPlugin (IPlugin *pPlugin) final
 Imports everything (layer, activation, fusing rules, and prototypes) registered with a single plugin. More...
 
NeuralResult importPluginLoader (IPluginLoader *pPluginLoader) final
 Imports all plugins loaded by a plugin loader. More...
 
bool isPrototypeRuntimeCompatible (const char *pPrototypeObjectClass, const INetwork *pNetwork) const final
 Checks if the given prototype object class is compatible with any of the registered prototypes. More...
 
 ~ClassRegistry ()
 Destroys the ClassRegistry.
 
- Public Member Functions inherited from nvneural::refobj::RefObjectBase< refobj::Implements< IClassRegistry > >
IRefObject::RefCount addRef () const noexcept
 Increment the object's reference count. More...
 
const void * queryInterface (IRefObject::TypeId interfaceId) const noexcept
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void * queryInterface (IRefObject::TypeId interfaceId) noexcept
 Retrieves a new object interface pointer. More...
 
 RefObjectBase ()
 Default constructor. Logs object creation.
 
IRefObject::RefCount release () const noexcept
 Decrements the object's reference count and destroys the object if the reference count reaches zero. More...
 

Static Public Member Functions

template<typename TObject >
static OpaqueClassRegistrationHandle registerActivation (const ActivationDesc &activationDesc)
 Registers a C++ object and ActivationDesc structure for discovery and creation. More...
 
static OpaqueClassRegistrationHandle registerActivationDesc (const ActivationDesc *pActivationDesc)
 Registers an ActivationDesc structure for discovery. More...
 
static OpaqueClassRegistrationHandle registerFusingRule (std::uint32_t syntaxVersion, const char *pFusingRule)
 Register a fusing rule for export. More...
 
template<typename TObject >
static OpaqueClassRegistrationHandle registerLayer (const LayerDesc &layerDesc)
 Registers a C++ object and LayerDesc structure for discovery and creation. More...
 
static OpaqueClassRegistrationHandle registerLayerDesc (const LayerDesc *pLayerDesc)
 Registers a LayerDesc structure for discovery. More...
 
template<typename TObject >
static OpaqueClassRegistrationHandle registerObjectClass (const char *pObjectClass)
 Registers a C++ object as a factory-creatable object class. More...
 
static OpaqueClassRegistrationHandle registerObjectClassInternal (const char *pObjectClass, CreationFunction classFactory)
 Registers an object class and associated creation function. More...
 
template<typename TObject >
static OpaqueClassRegistrationHandle registerPrototype (const PrototypeDesc &prototypeDesc, PrototypeRuntimeValidatorFunction runtimeValidator)
 Registers a C++ object as a prototype layer for discovery and creation. More...
 
static OpaqueClassRegistrationHandle registerPrototypeDesc (const PrototypeDesc *pPrototypeDesc, PrototypeRuntimeValidatorFunction runtimeValidator)
 Registers a PrototypeDesc structure and validator for discovery. More...
 

Detailed Description

ClassRegistry is the default implementation for IClassRegistry.

In addition to the operations already described in IClassRegistry, ClassRegistry supports direct integration with ExportPlugin, the standard IPlugin implementation. All statically defined exports (using registerLayer, registerActivation, and so on) are automaticallly hooked up to the type-specific plugin interfaces for discovery by tools and applications.

There are two major caveats to static registration:

  1. ClassRegistry does not make deep copies of registered descriptor structures. They must remain valid at all times while the plugin is loaded. In practice, this means module- level const variables are required. Do not use rvalues!
  2. Module-level variables initialize under the DLL loader lock in Windows. Do not perform significant operations as part of constructing your export variables. In addition to the "C++ static initialization order fiasco" (see this site for details: https://en.cppreference.com/w/cpp/language/siof) you should refrain from allocating large amounts of memory (prefer fixed std::arrays instead) and avoid any threading operations.

Member Function Documentation

◆ createObject()

NeuralResult ClassRegistry::createObject ( IRefObject **  ppOut,
const char *  pObjectClass 
) const
finalnoexcept

Creates the designated object using its manifest-specified class name.

Parameters
ppOutReceives a pointer to a newly created object, or nullptr if the name is unknown or creation fails.
pObjectClassObject class name.
Note
For implementers: the newly created object should have a ref count of 1.

◆ exportedActivationByIndex()

const ActivationDesc * ClassRegistry::exportedActivationByIndex ( std::size_t  index) const
finalnoexcept

Returns a registered activation function descriptor for a given index.

Parameters
index0-based index to an activation function
Returns
A pointer to ActivationDesc that will remain valid through the lifespan of this object, or nullptr if index is out of bounds.

◆ exportedActivationsCount()

std::size_t ClassRegistry::exportedActivationsCount ( ) const
finalnoexcept

Returns the count of registered activation functions.

◆ exportedFusingRuleByIndex()

const FusingRule * ClassRegistry::exportedFusingRuleByIndex ( std::size_t  index) const
finalnoexcept

Returns a registered fusing rule for a given index.

Parameters
index0-based index to a fusing ruler
Returns
A pointer to FusingRule that will remain valid through the lifespan of this object, or nullptr if index is out of bounds.

◆ exportedFusingRulesCount()

std::size_t ClassRegistry::exportedFusingRulesCount ( ) const
finalnoexcept

Returns the count of registered fusing rules.

◆ exportedLayerByIndex()

const LayerDesc * ClassRegistry::exportedLayerByIndex ( std::size_t  index) const
finalnoexcept

Returns a registered layer descriptor for a given index.

Parameters
index0-based index to a layer
Returns
A pointer to LayerDesc that will remain valid through the lifespan of this object, or nullptr if index is out of bounds.

◆ exportedLayersCount()

std::size_t ClassRegistry::exportedLayersCount ( ) const
finalnoexcept

Returns the count of registered layers.

◆ exportedPrototypeByIndex()

const PrototypeDesc * ClassRegistry::exportedPrototypeByIndex ( std::size_t  index) const
finalnoexcept

Returns a registered prototype layer descriptor for a given index.

Parameters
index0-based index to a prototype layer
Returns
A pointer to PrototypeDesc that will remain valid through the lifespan of this object, or nullptr if index is out of bounds.

◆ exportedPrototypeRuntimeValidatorByIndex()

PrototypeRuntimeValidatorFunction ClassRegistry::exportedPrototypeRuntimeValidatorByIndex ( std::size_t  index) const
finalnoexcept

Returns the runtime validator of a registered prototype layer for a given index.

Parameters
index0-based index to a prototype layer
Returns
A function of PrototypeRuntimeValidatorFunction that will remain valid through the lifespan of this object, or nullptr if index is out of bounds.

◆ exportedPrototypesCount()

std::size_t ClassRegistry::exportedPrototypesCount ( ) const
finalnoexcept

Returns the count of registered prototype layers.

◆ importPlugin()

NeuralResult ClassRegistry::importPlugin ( IPlugin pPlugin)
final

Imports everything (layer, activation, fusing rules, and prototypes) registered with a single plugin.

Parameters
pPluginA plugin enumerated by a plugin loader
Returns
Always success as this function does not expect any failure

◆ importPluginLoader()

NeuralResult ClassRegistry::importPluginLoader ( IPluginLoader pPluginLoader)
final

Imports all plugins loaded by a plugin loader.

Equivalent to looping through the IPluginLoader calling importPlugin on each object.

Parameters
pPluginLoaderIPluginLoader with loaded plugins
Returns
Success if plugin loader is empty or all plugins loaded successfully, Failure if one or more had errors

◆ isPrototypeRuntimeCompatible()

bool ClassRegistry::isPrototypeRuntimeCompatible ( const char *  pPrototypeObjectClass,
const INetwork pNetwork 
) const
final

Checks if the given prototype object class is compatible with any of the registered prototypes.

Parameters
pPrototypeObjectClassA string specifying the prototype object class to be checked
pNetworkNetwork pointer needed for a prototype's runtime validator
Returns
True if the given prototype is compatible with one of the registered prototypes; False otherwise

◆ registerActivation()

template<typename TObject >
static OpaqueClassRegistrationHandle nvneural::ClassRegistry::registerActivation ( const ActivationDesc activationDesc)
inlinestatic

Registers a C++ object and ActivationDesc structure for discovery and creation.

The object type is registered equivalent to calling registerObjectClass<TObject>(activationDesc.pObjectClass). You do not need to register the object explicitly.

Template Parameters
TObjectObject type to register; must have a zero-argument constructor defined
Parameters
activationDescActivation descriptor to export

◆ registerActivationDesc()

OpaqueClassRegistrationHandle ClassRegistry::registerActivationDesc ( const ActivationDesc pActivationDesc)
static

Registers an ActivationDesc structure for discovery.

Does not register referenced object classes for creation.

Parameters
pActivationDescActivation descriptor to export

◆ registerFusingRule()

OpaqueClassRegistrationHandle ClassRegistry::registerFusingRule ( std::uint32_t  syntaxVersion,
const char *  pFusingRule 
)
static

Register a fusing rule for export.

The fusing rule will be considered a "default fusing rule" for purposes of ConverenceNG –enable-default-fusing.

Parameters
syntaxVersionFusing rule syntax version used by pFusingRule
pFusingRuleFusing rule definition to export; syntax is version-specific and described in the FusingRule struct

◆ registerLayer()

template<typename TObject >
static OpaqueClassRegistrationHandle nvneural::ClassRegistry::registerLayer ( const LayerDesc layerDesc)
inlinestatic

Registers a C++ object and LayerDesc structure for discovery and creation.

The object type is registered equivalent to calling registerObjectClass<TObject>(layerDesc.pObjectClass). You do not need to register the object explicitly.

Template Parameters
TObjectObject type to register; must have a zero-argument constructor defined
Parameters
layerDescLayer descriptor to export

◆ registerLayerDesc()

OpaqueClassRegistrationHandle ClassRegistry::registerLayerDesc ( const LayerDesc pLayerDesc)
static

Registers a LayerDesc structure for discovery.

Does not register referenced object classes for creation.

Parameters
pLayerDescLayer descriptor to export

◆ registerObjectClass()

template<typename TObject >
static OpaqueClassRegistrationHandle nvneural::ClassRegistry::registerObjectClass ( const char *  pObjectClass)
inlinestatic

Registers a C++ object as a factory-creatable object class.

Template Parameters
TObjectObject type to register; must have a zero-argument constructor defined
Parameters
pObjectClassClass name to export the object under; should be a string literal

◆ registerObjectClassInternal()

OpaqueClassRegistrationHandle ClassRegistry::registerObjectClassInternal ( const char *  pObjectClass,
CreationFunction  classFactory 
)
static

Registers an object class and associated creation function.

Most of the other registration methods call this for you, but this interface is provided to support nonstandard use cases.

Parameters
pObjectClassObject class name to export
classFactoryCreation function to associate with the object class

◆ registerPrototype()

template<typename TObject >
static OpaqueClassRegistrationHandle nvneural::ClassRegistry::registerPrototype ( const PrototypeDesc prototypeDesc,
PrototypeRuntimeValidatorFunction  runtimeValidator 
)
inlinestatic

Registers a C++ object as a prototype layer for discovery and creation.

The object type is registered equivalent to calling registerObjectClass<TObject>(prototypeDesc.pObjectClass). You do not need to register the object explicitly.

Template Parameters
TObjectObject type to register; must have a zero-argument constructor defined
Parameters
prototypeDescPrototype descriptor to export
runtimeValidatorValidation function associated with the descriptor to export

◆ registerPrototypeDesc()

OpaqueClassRegistrationHandle ClassRegistry::registerPrototypeDesc ( const PrototypeDesc pPrototypeDesc,
PrototypeRuntimeValidatorFunction  runtimeValidator 
)
static

Registers a PrototypeDesc structure and validator for discovery.

Does not register referenced object classes for creation.

Parameters
pPrototypeDescPrototype descriptor to export
runtimeValidatorValidation function associated with the descriptor to export

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