NVIDIA NvNeural SDK
2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
|
ILayer is the base class for neural network layers. More...
#include <nvneural/LayerTypes.h>
Public Member Functions | |
virtual NetworkBackendId | backendId () const noexcept=0 |
Returns the backend ID associated with this layer implementation. More... | |
virtual TensorDimension | dimensions () const noexcept=0 |
Retrieves the dimensions of the layer's output tensor. More... | |
virtual NeuralResult | evaluateForward () noexcept=0 |
Performs forward evaluation for this layer. More... | |
virtual NeuralResult | getInputLayers (ILayerList **ppInputLayers) const noexcept=0 |
Retrieves the inputs for this layer. More... | |
virtual TensorDimension | internalDimensions () const noexcept=0 |
Retrieves the dimensions of the layer's output tensor as allocated internally. More... | |
virtual NeuralResult | loadFromParameters (const IParameterNode *pParameters) noexcept=0 |
Loads layer parameters from a serialized key-value representation. More... | |
virtual const char * | name () const noexcept=0 |
Retrieves the layer name. More... | |
virtual NeuralResult | reshape () noexcept=0 |
Initializes (or reinitializes) the layer implementation with the current set of parameters. More... | |
virtual const char * | serializedType () const noexcept=0 |
Retrieves the layer type. More... | |
virtual NeuralResult | setInputLayer (std::size_t index, ILayer *pLayer) noexcept=0 |
Sets an input layer by index. More... | |
virtual NeuralResult | setName (const char *pName) noexcept=0 |
Sets the layer name. More... | |
virtual NeuralResult | setNetworkRuntime (INetworkRuntime *pNetworkRuntime) noexcept=0 |
Informs the layer it has been attached to a new network. More... | |
virtual NeuralResult | setWeightsName (const char *pWeightsName) noexcept=0 |
Sets the name used to identify this layer's weights. More... | |
virtual TensorDimension | stepping () const noexcept=0 |
Returns the internal storage stride consumed by this layer implementation. More... | |
virtual std::size_t | tensorBufferSize () const noexcept=0 |
Retrieve the size of the layer's output tensor buffer in bytes. More... | |
virtual TensorFormat | tensorFormat () const noexcept=0 |
Returns the tensor format consumed by this layer implementation. More... | |
virtual std::size_t | tensorInternalBufferSize () const noexcept=0 |
Retrieves the dimensions of the layer's output tensor as allocated internally. More... | |
virtual TensorDimension | weightsDimensions (const char *pWeightsName, WeightsQuery queryType) const noexcept=0 |
Retrieves the tensor dimension of a layer's named weight input. More... | |
virtual const char * | weightsName () const noexcept=0 |
Retrieves the name used to identify this layer's weights. More... | |
Activation functions | |
Layers may have attached activations in the network design. Activation function data is stored with the layer in order to support fused operations. Where possible, layer implementations should implement their own built-in activation functions as part of their operation kernels. This is significantly more efficient than a second kernel launch and full traversal of the layer's output tensor. When fusing launches in this way, do not call the INetworkRuntime::defaultForwardActivation function during inference. Only call that function when the activation function attached to your layer instance is one not already part of the layer inference kernel. Activation coefficients not explicitly assigned with setActivationCoefficient should be assumed to have default values of zero. Layers should allow arbitrary coefficient indices for composability with arbitrary activations, but may reject indices that would be nonsensical for their internal storage. Layers should allow at least the indices [0..3] to be stored in all cases. | |
virtual NeuralResult | setActivationFunction (ActivationFunctionId activationFunction) noexcept=0 |
Sets the activation function attached to the layer. More... | |
virtual ActivationFunctionId | activationFunction () const noexcept=0 |
Retrieves the activation function attached to this layer. More... | |
virtual NeuralResult | setActivationCoefficient (std::size_t coefficientIndex, float value) noexcept=0 |
Sets an activation coefficient. More... | |
virtual float | activationCoefficient (std::size_t coefficientIndex) const noexcept=0 |
Retrieves the activation coefficient for the specified index. More... | |
Tensor memory management flags | |
virtual NeuralResult | setPermanent (bool permanent) noexcept=0 |
Sets or clears the "permanent" flag on a layer's output tensor. More... | |
virtual bool | isPermanent () const noexcept=0 |
Returns the current status of the "permanent" flag. More... | |
virtual NeuralResult | setAffected (bool affected) noexcept=0 |
Sets or clears the "affected" flag on a layer's output tensor. More... | |
virtual bool | isAffected () const noexcept=0 |
Returns the current status of the "affected" flag. More... | |
Data retrieval | |
virtual NeuralResult | getData (void **ppOut, TensorFormat format, const ILayer *pRequestingLayer) noexcept=0 |
Retrieves device-side memory for the layer's output. | |
virtual NeuralResult | getConstData (const void **ppOut, TensorFormat format, const ILayer *pRequestingLayer) const noexcept=0 |
Retrieves read-only device-side memory for the layer's output. | |
virtual NeuralResult | getCpuConstData (void *pOutBuffer, size_t bufferByteCount, size_t *pBytesCopied, TensorFormat format) const noexcept=0 |
Retrieves read-only CPU-side memory for the layer's output. More... | |
![]() | |
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 = 0xcd07ffbfd74d9b11ul |
Interface TypeId for InterfaceOf purposes. | |
![]() | |
static const TypeId | typeID = 0x14ecc3f9de638e1dul |
Interface TypeId for InterfaceOf purposes. | |
Additional Inherited Members | |
![]() | |
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. | |
![]() | |
virtual | ~IRefObject ()=default |
A protected destructor prevents accidental stack-allocation of IRefObjects or use with other smart pointer classes like std::unique_ptr. | |
ILayer is the base class for neural network layers.
|
pure virtualnoexcept |
Retrieves the activation coefficient for the specified index.
The meaning of this value is activation-specific. If no setActivationCoefficient call was previously issued for this index, the layer should return a default value of zero.
coefficientIndex | Coefficient index |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Retrieves the activation function attached to this layer.
Should return the most recent value passed to setActivationFunction.
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Returns the backend ID associated with this layer implementation.
Networks will reshape tensors as necessary in order to match the return value.
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Retrieves the dimensions of the layer's output tensor.
Should not change except in response to a reshape event.
|
pure virtualnoexcept |
Performs forward evaluation for this layer.
If the layer does not provide a pre-fused implementation of the selected activation function, it MUST call INetworkRuntime::defaultForwardActivation(this).
|
pure virtualnoexcept |
Retrieves read-only CPU-side memory for the layer's output.
This function is intended for debugging purposes. Element count of the buffer should be dimensions().elementCount(), multiplied by the size of the desired element type.
To check buffer sizes without preallocating memory, pass nullptr in pOutBuffer and zero in bufferByteCount. pBytesCopied will then receive the optimal size for pOutBuffer. Other uses of nullptr are considered errors.
pBytesCopied is not modified if this function fails.
pOutBuffer | Memory region receiving the layer output data |
bufferByteCount | Size of pOutBuffer in bytes |
pBytesCopied | Optional output variable receiving the number of bytes copied into pOutBuffer |
format | Format for the output buffer |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Retrieves the inputs for this layer.
ppInputLayers | Pointer receiving a reference to an ILayerList object. |
Layer may create a new list or return an incremented reference to a cached object; this is an implementation detail.
In either case, caller is responsible for releasing its reference when done with *ppInputLayers.
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Retrieves the dimensions of the layer's output tensor as allocated internally.
Internal allocations may have additional padding or alignment restrictions.
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Returns the current status of the "affected" flag.
By default, layers should be "affected" after initialization.
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Returns the current status of the "permanent" flag.
By default, layers should not be "permanent."
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Loads layer parameters from a serialized key-value representation.
Tools such as ConverenceNG call this during network construction. Deployed applications may use this function themselves (often with a container class such as StringMapParameterNode) or may use layer-specific object interfaces; either approach is valid.
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Retrieves the layer name.
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Initializes (or reinitializes) the layer implementation with the current set of parameters.
It is safe to call this multiple times, and may be necessary as parameters change.
|
pure virtualnoexcept |
Retrieves the layer type.
|
pure virtualnoexcept |
Sets an activation coefficient.
The meaning of this value is activation-specific.
coefficientIndex | Coefficient index |
value | Value to store |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Sets the activation function attached to the layer.
Repeated calls to this function replace the activation rather than stacking them.
activationFunction | New activation function ID |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Sets or clears the "affected" flag on a layer's output tensor.
Layers that are "affected" have pending computation work and will be reevaluated as necessary during inference. Networks will clear the "affected" flag after successful inference.
Layers should mark themselves as "affected" in response to parameter changes that would be visible during inference. Examples of such changes include loadFromParameters and the IRuntimeOptionsLayer::setRuntimeOptionValue callback.
affected | New value for the "affected" flag |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Sets an input layer by index.
Input indices are explicitly allowed to be sparse in order to support optional inputs; usually such inputs are used to provide weights from other parts of the graph instead of going out to IWeightsLoader.
index | Index of the input to assign |
pLayer | Layer to assign as an input |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Sets the layer name.
Layer names are unique within a network.
pName | New layer name; layer must copy this data. |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Informs the layer it has been attached to a new network.
INetwork::pushLayer implementations will call this function for you; host applications do not normally need to call this function.
pNetworkRuntime | New owning network |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Sets or clears the "permanent" flag on a layer's output tensor.
Layers that are "permanent" are kept resident in memory and their tensor buffers are not reused. Setting too many layers as "permanent" will have negative effects on memory utilization.
permanent | New value for the "permanent" flag |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Sets the name used to identify this layer's weights.
pWeightsName | New layer name to use for weights instead of name() |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Returns the internal storage stride consumed by this layer implementation.
Output tensors are padded to be multiples of this value.
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Retrieve the size of the layer's output tensor buffer in bytes.
This result is defined as the number of elements in dimensions() multiplied by the size of an individual element (e.g., 4 for FP32).
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Returns the tensor format consumed by this layer implementation.
Networks will reshape tensors as necessary in order to match the return value.
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Retrieves the dimensions of the layer's output tensor as allocated internally.
Internal allocations may have additional padding or alignment restrictions. The result is defined as the number of elements in internalDimensions() multiplied by the size of an individual element (e.g., 4 for FP32).
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Retrieves the tensor dimension of a layer's named weight input.
pWeightsName | Name of a weights object being queried |
queryType | Type of dimensions being queried; see WeightsQuery for details |
Implemented in nvneural::BaseLayer.
|
pure virtualnoexcept |
Retrieves the name used to identify this layer's weights.
By default, this should be the name assigned with setName. Alternate weights names allow layer aliasing and namespacing within subnetworks.
Implemented in nvneural::BaseLayer.