NVIDIA NvNeural SDK  2021.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
nvneural::ICppCodeGenerationLayerHost Class Referenceabstract

Tool-supplied interface for C++ code generation. More...

#include <nvneural/CodeGenTypes.h>

Inheritance diagram for nvneural::ICppCodeGenerationLayerHost:
nvneural::IRefObject

Public Member Functions

Information Provided by the Host
virtual bool deploymentMode () const noexcept=0
 Returns true if the generator is in "deployment mode." When generating for deployment mode, the layer should precompile kernels where possible and optimize for speed rather than ease of development.
 
virtual const IStringListtargetGpuArchitectures () const noexcept=0
 Returns a pointer to an existing IStringList listing target GPU architectures. More...
 
virtual const char * networkVariableName () const noexcept=0
 Returns the C++ name of the INetwork variable being constructed. More...
 
virtual const char * layerVariableName () const noexcept=0
 Returns the C++ name of this ILayer object. More...
 
virtual const char * resourceDictionaryVariableName () const noexcept=0
 Returns the C++ name of the IResourceDictionary object. More...
 
virtual const char * inputArgumentExpression () const noexcept=0
 Returns the C++ expression corresponding to the command-line "input" parameter for this layer. More...
 
Information Provided by the Layer
virtual NeuralResult setObjectClass (const char *pObjectClass) noexcept=0
 Sets the object class that should be used to construct this layer. More...
 
virtual NeuralResult addInclude (const char *pInclude) noexcept=0
 Adds an include definition to the generated C++. More...
 
virtual NeuralResult addSourceFragment (const char *pCppCode) noexcept=0
 Adds a code fragment to the generated C++.
 
virtual NeuralResult addHeaderFragment (const char *pCppCode) noexcept=0
 Adds a code fragment to the generated header.
 
virtual NeuralResult setInitializationFragment (const char *pCppCode) noexcept=0
 Sets the initialization fragment, replacing ILayer::loadFromParameters. More...
 
virtual NeuralResult addResource (IResourceDictionary::ResourceId *pResourceIdOut, const void *pBuffer, std::uint32_t bufferBytes) noexcept=0
 Adds a binary resource to the generated C++. More...
 
virtual NeuralResult setInputFragment (const char *pCppCode) noexcept=0
 Marks a layer as a configurable input, setting its argument-parsing fragment. More...
 
- Public Member Functions inherited from nvneural::IRefObject
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 IRefObject::TypeId typeID = 0x1025680db910cfebul
 Interface TypeId for InterfaceOf purposes.
 
- Static Public Attributes inherited from nvneural::IRefObject
static const TypeId typeID = 0x14ecc3f9de638e1dul
 Interface TypeId for InterfaceOf purposes.
 

Additional Inherited Members

- Public Types inherited from nvneural::IRefObject
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.
 
- Protected Member Functions inherited from nvneural::IRefObject
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

Tool-supplied interface for C++ code generation.

Host applications like ConverenceNG provide an instance of this interface to the ICppCodeGenerationLayer::generateLayerCpp method. Layers may call zero or more of the output methods to customize the standard code templates.

The SourceWriter class in CodeGenHelpers.h is provided for convenience when generating large swathes of C++ code. It exposes a non-ABI-stable interface based around iostreams with the added benefit of supporting automatic indentation.

Outputs:

  • includes: List of "<nvneural/Thing.h>" strings; the layer must provide <> or "" as appropriate to the header being included. Each header should be idempotent and able to be included in arbitrary order, as the tool will generally try to remove duplicates. Default is "no includes."
  • fragments: Code fragments to be copied verbatim into the generated network C++ file. Fragments are copied in the order received by the generator tool. Header fragments are also available, and are copied into the generated network H file.
  • objectClass: Name of the object to generate if different from that used to generate the ICppCodeGenerationLayer. By convention, all layers should be created using a ClassRegistry factory even if the resulting objects are not paired with LayerDesc structures. This maximizes flexibility when layers are split between plugins and inline definitions in application C++.
  • initialization: Code fragment for initializing the created layer object. This should be semantically equivalent to ILayer::loadFromParameters. The tool takes care of assigning layer inputs, the activation function, any activation coefficients, and attaching the layer to the INetwork object.
  • resources: Layers needing to precompile kernels or other binary data can store them in the tool and reload them at runtime from an IResourceDictionary. The tool will collapse duplicates and assign non-conflicting resource IDs, so use generic names for common code.

Member Function Documentation

◆ addInclude()

virtual NeuralResult nvneural::ICppCodeGenerationLayerHost::addInclude ( const char *  pInclude)
pure virtualnoexcept

Adds an include definition to the generated C++.

Remember to add <> or "" as appropriate.

◆ addResource()

virtual NeuralResult nvneural::ICppCodeGenerationLayerHost::addResource ( IResourceDictionary::ResourceId pResourceIdOut,
const void *  pBuffer,
std::uint32_t  bufferBytes 
)
pure virtualnoexcept

Adds a binary resource to the generated C++.

Parameters
pResourceIdOutReturned resource ID
pBufferResource buffer to store
bufferBytesSize of the pBuffer resource in bytes

◆ inputArgumentExpression()

virtual const char* nvneural::ICppCodeGenerationLayerHost::inputArgumentExpression ( ) const
pure virtualnoexcept

Returns the C++ expression corresponding to the command-line "input" parameter for this layer.

Its type is std::string, and defaults to the empty string if the user did not specify a value.

Warning
This string is not compilable unless the layer also calls setInputFragment.

◆ layerVariableName()

virtual const char* nvneural::ICppCodeGenerationLayerHost::layerVariableName ( ) const
pure virtualnoexcept

Returns the C++ name of this ILayer object.

Its type is nvneural::RefPtr<nvneural::ILayer>.

◆ networkVariableName()

virtual const char* nvneural::ICppCodeGenerationLayerHost::networkVariableName ( ) const
pure virtualnoexcept

Returns the C++ name of the INetwork variable being constructed.

Its type is nvneural::RefPtr<nvneural::INetwork>.

◆ resourceDictionaryVariableName()

virtual const char* nvneural::ICppCodeGenerationLayerHost::resourceDictionaryVariableName ( ) const
pure virtualnoexcept

Returns the C++ name of the IResourceDictionary object.

Its type is nvneural::RefPtr<nvneural::IResourceDictionary>.

◆ setInitializationFragment()

virtual NeuralResult nvneural::ICppCodeGenerationLayerHost::setInitializationFragment ( const char *  pCppCode)
pure virtualnoexcept

Sets the initialization fragment, replacing ILayer::loadFromParameters.

Multiple calls to this method replace previous fragments instead of concatenating.

◆ setInputFragment()

virtual NeuralResult nvneural::ICppCodeGenerationLayerHost::setInputFragment ( const char *  pCppCode)
pure virtualnoexcept

Marks a layer as a configurable input, setting its argument-parsing fragment.

Multiple calls to this method replace previous fragments instead of concatenating.

Inside this fragment, the layer should retrieve the string named by the expression inputArgumentExpression and use it to load an input tensor.

The fragment should "return 1" (or some other nonzero exit code) and emit an error message to the default logger if something goes wrong at runtime.

◆ setObjectClass()

virtual NeuralResult nvneural::ICppCodeGenerationLayerHost::setObjectClass ( const char *  pObjectClass)
pure virtualnoexcept

Sets the object class that should be used to construct this layer.

Its type should be compatible with IPlugin::createObject. Multiple calls to this method replace previous object classes.

◆ targetGpuArchitectures()

virtual const IStringList* nvneural::ICppCodeGenerationLayerHost::targetGpuArchitectures ( ) const
pure virtualnoexcept

Returns a pointer to an existing IStringList listing target GPU architectures.

Architectures are in nvcc/nvrtc format (e.g., "sm_86") and can be passed directly to ICudaRuntimeCompiler::setTargetArchitecture.


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