NVIDIA NvNeural SDK  2021.1
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 
354  virtual bool inputSupportsElision(size_t inputIndex, std::size_t* pElisionOffsetOut) const noexcept = 0;
355  };
356 
365  class IBypassLayer : public IRefObject
366  {
367  public:
369  static const IRefObject::TypeId typeID = 0xeb843bc48914779eul;
370 
374  virtual const ILayer* getAliasedInput() const noexcept = 0;
375  };
376 
381  {
382  public:
384  static const IRefObject::TypeId typeID = 0x945791d0e3af06fcul;
385 
390  virtual std::size_t nextStatusMessageSize() const noexcept = 0;
391 
399  virtual NeuralResult copyStatusMessage(char* pBuffer, std::size_t bufferSize) noexcept = 0;
400  };
401 
414  namespace runtimeoptionstype
415  {
416  const char* const stringlist = "stringList";
417  const char* const numfloat = "numFloat";
418  const char* const numint = "numInt";
419  const char* const booltf = "boolTF";
420  const char* const textlabel = "textLabel";
421  const char* const textedit = "textEdit";
422  const char* const trigger = "trigger";
423  }
424 
428  namespace runtimeoptionsattributes
429  {
430  const char* const list = "list";
431  const char* const min = "min";
432  const char* const max = "max";
433  const char* const step = "step";
434  }
435 
459  {
460  public:
462  static const IRefObject::TypeId typeID = 0x3d7156c756e977aeul;
463 
482 
485  virtual std::size_t runtimeOptionCount() const noexcept = 0;
486 
491  virtual const char* runtimeOptionByIndex(size_t index) const noexcept = 0;
492 
494 
499  virtual NeuralResult setRuntimeOptionsHost(IRuntimeOptionsHost* pRuntimeOptionsHost) noexcept = 0;
500 
507 
514  virtual NeuralResult setRuntimeOptionValue(const char* pName, const char* pValue) noexcept = 0;
515 
519  virtual const char* getRuntimeOptionValue(const char* pName) const noexcept = 0;
520 
522  };
523 
524 
525 } // namespace nvneural
526 
527 #endif // NVNEURAL_LAYERTYPES_H
Fundamental NvNeural data types are declared here.
NetworkBackendId
Enumeration describing common network backends.
Definition: CoreTypes.h:237
ActivationFunctionId
Enumeration describing common activation functions.
Definition: CoreTypes.h:257
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:273
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:366
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...
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:927
INetworkRuntime is a subset of the basic network interface that is accessible from layer classes duri...
Definition: CoreTypes.h:996
Represents a serialized parameter block in a model definition.
Definition: CoreTypes.h:1697
Base class for all objects, similar to COM's IUnknown.
Definition: CoreTypes.h:341
std::uint64_t TypeId
Every interface must define a unique TypeId. This should be randomized.
Definition: CoreTypes.h:347
IRuntimeOptionsHost is an interface that provides runtime option communication from the layer to the ...
Definition: CoreTypes.h:542
IRuntimeOptionsLayer is an optional interface that marks a layer as one that uses runtime options.
Definition: LayerTypes.h:459
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:381
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:432
const char *const list
Defines a list of string, ex. "list":["option_1", "option_2"].
Definition: LayerTypes.h:430
const char *const step
Defines a step value, ex. "step":"1" or "step":"0.5".
Definition: LayerTypes.h:433
const char *const min
Defines a min value, ex. "min":"0" or "min":"0.5".
Definition: LayerTypes.h:431
const char *const numfloat
Requires nothing, sent float.
Definition: LayerTypes.h:417
const char *const trigger
Requires nothing, sent empty string.
Definition: LayerTypes.h:422
const char *const booltf
Requires nothing, sent "true" or "false".
Definition: LayerTypes.h:419
const char *const numint
Requires nothing, sent int.
Definition: LayerTypes.h:418
const char *const textlabel
Requires nothing, sent nothing, send string.
Definition: LayerTypes.h:420
const char *const stringlist
Requires runtimeoptionsattributes::list, sent ordinal.
Definition: LayerTypes.h:416
const char *const textedit
Requires nothing, sent string.
Definition: LayerTypes.h:421
TensorDimension describes the dimensions of a four-dimensional image tensor.
Definition: CoreTypes.h:134
TensorFormat describes a specific tensor shape (element type and layout).
Definition: CoreTypes.h:86