NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
LayerTypes.h
Go to the documentation of this file.
1 /*
2 * SPDX-FileCopyrightText: Copyright (c) 2020-2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: MIT
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23 
25 
26 #ifndef NVNEURAL_LAYERTYPES_H
27 #define NVNEURAL_LAYERTYPES_H
28 
29 #include <nvneural/CoreTypes.h>
30 
31 namespace nvneural {
32 
33 
38  enum class WeightsQuery : std::uint32_t
39  {
47  Required = 1,
48 
54  Aligned = 2,
55  };
56 
58  class ILayer : public IRefObject
59  {
60  public:
62  static const IRefObject::TypeId typeID = 0xcd07ffbfd74d9b11ul;
63 
67  virtual NeuralResult setName(const char* pName) noexcept = 0;
68 
72  virtual const char* name() const noexcept = 0;
73 
77  virtual const char* serializedType() const noexcept = 0;
78 
85  virtual NeuralResult setNetworkRuntime(INetworkRuntime* pNetworkRuntime) noexcept = 0;
86 
90  virtual NetworkBackendId backendId() const noexcept = 0;
91 
95  virtual TensorFormat tensorFormat() const noexcept = 0;
96 
100  virtual TensorDimension stepping() const noexcept = 0;
101 
105  virtual TensorDimension dimensions() const noexcept = 0;
106 
111  virtual TensorDimension internalDimensions() const noexcept = 0;
112 
117  virtual std::size_t tensorBufferSize() const noexcept = 0;
118 
124  virtual std::size_t tensorInternalBufferSize() const noexcept = 0;
125 
131  virtual NeuralResult loadFromParameters(const IParameterNode* pParameters) noexcept = 0;
132 
152 
158 
161  virtual ActivationFunctionId activationFunction() const noexcept = 0;
162 
167  virtual NeuralResult setActivationCoefficient(std::size_t coefficientIndex, float value) noexcept = 0;
168 
174  virtual float activationCoefficient(std::size_t coefficientIndex) const noexcept = 0;
175 
177 
181 
187  virtual NeuralResult setPermanent(bool permanent) noexcept = 0;
188 
192  virtual bool isPermanent() const noexcept = 0;
193 
203  virtual NeuralResult setAffected(bool affected) noexcept = 0;
204 
208  virtual bool isAffected() const noexcept = 0;
209 
211 
220  virtual NeuralResult getInputLayers(ILayerList** ppInputLayers) const noexcept = 0;
221 
230  virtual NeuralResult setInputLayer(std::size_t index, ILayer* pLayer) noexcept = 0;
231 
235  virtual NeuralResult reshape() noexcept = 0;
236 
241  virtual NeuralResult evaluateForward() noexcept = 0;
242 
247  virtual const char* weightsName() const noexcept = 0;
248 
252  virtual NeuralResult setWeightsName(const char* pWeightsName) noexcept = 0;
253 
258  virtual TensorDimension weightsDimensions(const char* pWeightsName, WeightsQuery queryType) const noexcept = 0;
259 
262 
264  virtual NeuralResult getData(void** ppOut, TensorFormat format, const ILayer* pRequestingLayer) noexcept = 0;
265 
267  virtual NeuralResult getConstData(const void** ppOut, TensorFormat format, const ILayer* pRequestingLayer) const noexcept = 0;
268 
283  virtual NeuralResult getCpuConstData(void* pOutBuffer, size_t bufferByteCount, size_t* pBytesCopied, TensorFormat format) const noexcept = 0;
284 
286 
287  };
288 
300  {
301  public:
303  static const IRefObject::TypeId typeID = 0xff90b9f223475f88ul;
304 
309 
312  virtual ActivationFunctionId innerActivationFunction() const noexcept = 0;
313 
318  virtual NeuralResult setInnerActivationCoefficient(std::size_t coefficientIndex, float value) noexcept = 0;
319 
325  virtual float innerActivationCoefficient(std::size_t coefficientIndex) const noexcept = 0;
326  };
327 
331  class IInputLayer : public IRefObject
332  {
333  public:
335  static const IRefObject::TypeId typeID = 0xf1a084394b18dceeul;
336  };
337 
343  {
344  public:
346  static const IRefObject::TypeId typeID = 0xe4924aa3178a6e9ful;
347 
357  virtual bool inputSupportsElision(size_t inputIndex, std::size_t* pElisionOffsetOut) const noexcept = 0;
358  };
359 
372  {
373  public:
375  static const IRefObject::TypeId typeID = 0x715eaa65a023d7bcul;
376 
379  virtual bool allInputsSupportDirectTensorWrites() const noexcept = 0;
380 
391  virtual NeuralResult getTensorWriteOffset(const ILayer* pInput, std::size_t* pOffsetOut) const noexcept = 0;
392  };
393 
404  class IBypassLayer : public IRefObject
405  {
406  public:
408  static const IRefObject::TypeId typeID = 0xeb843bc48914779eul;
409 
413  virtual const ILayer* getAliasedInput() const noexcept = 0;
414  };
415 
420  {
421  public:
423  static const IRefObject::TypeId typeID = 0x945791d0e3af06fcul;
424 
429  virtual std::size_t nextStatusMessageSize() const noexcept = 0;
430 
438  virtual NeuralResult copyStatusMessage(char* pBuffer, std::size_t bufferSize) noexcept = 0;
439  };
440 
453  namespace runtimeoptionstype
454  {
455  const char* const stringlist = "stringList";
456  const char* const numfloat = "numFloat";
457  const char* const numint = "numInt";
458  const char* const booltf = "boolTF";
459  const char* const textlabel = "textLabel";
460  const char* const textedit = "textEdit";
461  const char* const trigger = "trigger";
462  }
463 
467  namespace runtimeoptionsattributes
468  {
469  const char* const list = "list";
470  const char* const min = "min";
471  const char* const max = "max";
472  const char* const step = "step";
473  }
474 
498  {
499  public:
501  static const IRefObject::TypeId typeID = 0x3d7156c756e977aeul;
502 
521 
524  virtual std::size_t runtimeOptionCount() const noexcept = 0;
525 
530  virtual const char* runtimeOptionByIndex(size_t index) const noexcept = 0;
531 
533 
538  virtual NeuralResult setRuntimeOptionsHost(IRuntimeOptionsHost* pRuntimeOptionsHost) noexcept = 0;
539 
546 
553  virtual NeuralResult setRuntimeOptionValue(const char* pName, const char* pValue) noexcept = 0;
554 
558  virtual const char* getRuntimeOptionValue(const char* pName) const noexcept = 0;
559 
561  };
562 
563 
564 } // namespace nvneural
565 
566 #endif // NVNEURAL_LAYERTYPES_H
Fundamental NvNeural data types are declared here.
NetworkBackendId
Enumeration describing common network backends.
Definition: CoreTypes.h:239
ActivationFunctionId
Enumeration describing common activation functions.
Definition: CoreTypes.h:259
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:275
WeightsQuery
WeightsQuery describes the different types of queries for weights data.
Definition: LayerTypes.h:39
@ Aligned
Represents the "actual" dimensions expected from compatible weights.
@ Required
Represents the "official" dimensions expected from compatible weights.
IBypassLayer is an optional interface that marks a layer as one that can potentially forward its inpu...
Definition: LayerTypes.h:405
virtual const ILayer * getAliasedInput() const noexcept=0
Returns the input layer that should be aliased from this layer or nullptr if this layer cannot be byp...
IConcatenationLayer2 is an optional interface implemented by layers that marks them as concatenation ...
Definition: LayerTypes.h:372
virtual bool allInputsSupportDirectTensorWrites() const noexcept=0
Tests whether all inputs to this layer can be replaced with direct writes.
IConcatenationLayer is an optional interface implemented by layers that marks them as concatenation l...
Definition: LayerTypes.h:343
virtual bool inputSupportsElision(size_t inputIndex, std::size_t *pElisionOffsetOut) const noexcept=0
If this layer supports elision, it calculates the appropriate offset for a given input.
IInnerActivationLayer is an optional interface implemented by layers that fuse pairs of operations.
Definition: LayerTypes.h:300
virtual ActivationFunctionId innerActivationFunction() const noexcept=0
Retrieves the activation function attached to this layer.
virtual NeuralResult setInnerActivationFunction(ActivationFunctionId activationFunction) noexcept=0
Sets the inner activation function.
IInputLayer is an optional interface implemented by layers that marks them as input layers.
Definition: LayerTypes.h:332
ILayer is the base class for neural network layers.
Definition: LayerTypes.h:59
virtual bool isAffected() const noexcept=0
Returns the current status of the "affected" flag.
virtual std::size_t tensorInternalBufferSize() const noexcept=0
Retrieves the dimensions of the layer's output tensor as allocated internally.
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.
virtual bool isPermanent() const noexcept=0
Returns the current status of the "permanent" flag.
virtual NeuralResult setActivationCoefficient(std::size_t coefficientIndex, float value) noexcept=0
Sets an activation coefficient.
virtual NeuralResult setAffected(bool affected) noexcept=0
Sets or clears the "affected" flag on a layer's output tensor.
virtual NeuralResult evaluateForward() noexcept=0
Performs forward evaluation for this layer.
virtual std::size_t tensorBufferSize() const noexcept=0
Retrieve the size of the layer's output tensor buffer in bytes.
virtual ActivationFunctionId activationFunction() const noexcept=0
Retrieves the activation function attached to this layer.
virtual const char * weightsName() const noexcept=0
Retrieves the name used to identify this layer's weights.
virtual TensorDimension dimensions() const noexcept=0
Retrieves the dimensions of the layer's output tensor.
virtual NeuralResult setWeightsName(const char *pWeightsName) noexcept=0
Sets the name used to identify this layer's weights.
virtual NetworkBackendId backendId() const noexcept=0
Returns the backend ID associated with this layer implementation.
virtual NeuralResult setInputLayer(std::size_t index, ILayer *pLayer) noexcept=0
Sets an input layer by index.
virtual NeuralResult setNetworkRuntime(INetworkRuntime *pNetworkRuntime) noexcept=0
Informs the layer it has been attached to a new network.
virtual TensorDimension weightsDimensions(const char *pWeightsName, WeightsQuery queryType) const noexcept=0
Retrieves the tensor dimension of a layer's named weight input.
virtual float activationCoefficient(std::size_t coefficientIndex) const noexcept=0
Retrieves the activation coefficient for the specified index.
virtual const char * serializedType() const noexcept=0
Retrieves the layer type.
virtual NeuralResult loadFromParameters(const IParameterNode *pParameters) noexcept=0
Loads layer parameters from a serialized key-value representation.
virtual const char * name() const noexcept=0
Retrieves the layer name.
virtual NeuralResult setName(const char *pName) noexcept=0
Sets the layer name.
virtual NeuralResult setPermanent(bool permanent) noexcept=0
Sets or clears the "permanent" flag on a layer's output tensor.
virtual TensorDimension stepping() const noexcept=0
Returns the internal storage stride consumed by this layer implementation.
virtual TensorFormat tensorFormat() const noexcept=0
Returns the tensor format consumed by this layer implementation.
virtual NeuralResult getInputLayers(ILayerList **ppInputLayers) const noexcept=0
Retrieves the inputs for this layer.
static const IRefObject::TypeId typeID
Interface TypeId for InterfaceOf purposes.
Definition: LayerTypes.h:62
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 reshape() noexcept=0
Initializes (or reinitializes) the layer implementation with the current set of parameters.
virtual TensorDimension internalDimensions() const noexcept=0
Retrieves the dimensions of the layer's output tensor as allocated internally.
virtual NeuralResult setActivationFunction(ActivationFunctionId activationFunction) noexcept=0
Sets the activation function attached to the layer.
ILayerList represents an immutable collection of ILayer pointers.
Definition: CoreTypes.h:1060
INetworkRuntime is a subset of the basic network interface that is accessible from layer classes duri...
Definition: CoreTypes.h:1129
Represents a serialized parameter block in a model definition.
Definition: CoreTypes.h:1889
Base class for all objects, similar to COM's IUnknown.
Definition: CoreTypes.h:343
std::uint64_t TypeId
Every interface must define a unique TypeId. This should be randomized.
Definition: CoreTypes.h:349
IRuntimeOptionsHost is an interface that provides runtime option communication from the layer to the ...
Definition: CoreTypes.h:544
IRuntimeOptionsLayer is an optional interface that marks a layer as one that uses runtime options.
Definition: LayerTypes.h:498
virtual std::size_t runtimeOptionCount() const noexcept=0
Returns the number of available runtime options.
IStatusMessageLayer is an optional interface intended for ILayer to provide status messages.
Definition: LayerTypes.h:420
virtual std::size_t nextStatusMessageSize() const noexcept=0
Returns the size of the next status message including trailing null.
const char *const max
Defines a max value, ex. "max":"1" or "max":"1.0".
Definition: LayerTypes.h:471
const char *const list
Defines a list of string, ex. "list":["option_1", "option_2"].
Definition: LayerTypes.h:469
const char *const step
Defines a step value, ex. "step":"1" or "step":"0.5".
Definition: LayerTypes.h:472
const char *const min
Defines a min value, ex. "min":"0" or "min":"0.5".
Definition: LayerTypes.h:470
const char *const numfloat
Requires nothing, sent float.
Definition: LayerTypes.h:456
const char *const trigger
Requires nothing, sent empty string.
Definition: LayerTypes.h:461
const char *const booltf
Requires nothing, sent "true" or "false".
Definition: LayerTypes.h:458
const char *const numint
Requires nothing, sent int.
Definition: LayerTypes.h:457
const char *const textlabel
Requires nothing, sent nothing, send string.
Definition: LayerTypes.h:459
const char *const stringlist
Requires runtimeoptionsattributes::list, sent ordinal.
Definition: LayerTypes.h:455
const char *const textedit
Requires nothing, sent string.
Definition: LayerTypes.h:460
TensorDimension describes the dimensions of a four-dimensional image tensor.
Definition: CoreTypes.h:136
TensorFormat describes a specific tensor shape (element type and layout).
Definition: CoreTypes.h:88