NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
NetworkTypes.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 #ifndef NVNEURAL_NETWORKTYPES_H
26 #define NVNEURAL_NETWORKTYPES_H
27 
28 #include <nvneural/CoreTypes.h>
29 
30 namespace nvneural {
31 
33 #define NVNEURAL_INETWORK_OBJECTCLASS "com.nvidia.network"
34 
35  class ILayer; // forward declaration
36 
51  {
52  public:
54  static const IRefObject::TypeId typeID = 0x44b2d2279e4abca9ul;
55 
59  virtual NeuralResult beginPass(ILayer** ppInferenceLayers, size_t layerCount) noexcept = 0;
60 
66  virtual NeuralResult beginNetwork(INetworkRuntime* pNetworkRuntime, ILayer* pModelLayer, ILayerList* pExternLayerList) noexcept = 0;
67 
70  virtual NeuralResult beginLayer(ILayer* pLayer) noexcept = 0;
71 
74  virtual NeuralResult skipLayer(ILayer* pLayer) noexcept = 0;
75 
78  virtual NeuralResult endLayer(ILayer* pLayer) noexcept = 0;
79 
85  virtual NeuralResult endNetwork(INetworkRuntime* pNetworkRuntime, ILayer* pModelLayer, ILayerList* pExternLayerList) noexcept = 0;
86 
88  virtual NeuralResult endPass() noexcept = 0;
89  };
90 
97  {
98  public:
100  static const IRefObject::TypeId typeID = 0x6e2cb6b746e5f2dul;
101 
106  virtual NeuralResult beginReshapeLayer(ILayer* pLayer) noexcept = 0;
107 
114  virtual NeuralResult endReshapeLayer(ILayer* pLayer, NeuralResult reshapeStatus) noexcept = 0;
115  };
116 
118  class INetwork : public INetworkRuntime
119  {
120  public:
122  static const IRefObject::TypeId typeID = 0x9ce8f71bf65288e9ul;
123 
127  virtual NeuralResult attachNetworkDebugger(INetworkDebugger* pDebugger) noexcept = 0;
128 
130  virtual NeuralResult detachNetworkDebugger(const INetworkDebugger* pDebugger) noexcept = 0;
131 
133  virtual NeuralResult detachAllNetworkDebuggers() noexcept = 0;
134 
138  virtual NeuralResult getNetworkDebuggers(INetworkDebuggerList** ppListOut) const noexcept = 0;
139 
143  virtual NeuralResult attachReshapeDebugger(INetworkReshapeDebugger* pDebugger) noexcept = 0;
144 
146  virtual NeuralResult detachReshapeDebugger(const INetworkReshapeDebugger* pDebugger) noexcept = 0;
147 
149  virtual NeuralResult detachAllReshapeDebuggers() noexcept = 0;
150 
153  virtual NeuralResult unload() noexcept = 0;
154 
156  virtual NeuralResult clearLayers() noexcept = 0;
157 
160 
166  virtual NeuralResult attachBackend(INetworkBackend* pBackend) noexcept = 0;
167 
171  virtual NeuralResult setDefaultBackendId(NetworkBackendId backendId) noexcept = 0;
172 
174  virtual NeuralResult setDefaultTensorFormat(const TensorFormat& tensorFormat) noexcept = 0;
175 
181  virtual NeuralResult setNetworkName(const char* pName) noexcept = 0;
182 
184  virtual NeuralResult setOptimizationFlag(NetworkBackendId backendId, INetworkBackend::OptimizationCapability capability, bool enabled) noexcept = 0;
185 
187  virtual bool isOptimizationFlagEnabled(NetworkBackendId backendId, INetworkBackend::OptimizationCapability capability) const noexcept = 0;
188 
192  virtual NeuralResult setWeightsLoader(IWeightsLoader* pWeightsLoader) noexcept = 0;
193 
197  virtual NeuralResult pushLayer(ILayer* pLayer) noexcept = 0;
198 
202  virtual NeuralResult pushLayerAlias(const char* pAliasName, ILayer* pLayer) noexcept = 0;
203 
205 
207  virtual NeuralResult synchronize() noexcept = 0;
208 
218  virtual NeuralResult bindCurrentThread() noexcept = 0;
219 
224  virtual NeuralResult clearLoadedWeights() noexcept = 0;
225 
228 
230  virtual NeuralResult reshapeAll() noexcept = 0;
231 
237  virtual NeuralResult reshape(ILayerList* pMarkedLayers) noexcept = 0;
238 
240 
243 
248  virtual NeuralResult inferenceSubgraph(ILayerList* pInputs, ILayerList* pOutputs) noexcept = 0;
249 
254  virtual NeuralResult inference() noexcept = 0;
255 
257 
259  virtual NeuralResult copyTensor(const ILayer* pSourceLayer, ILayer* pDestinationLayer) noexcept = 0;
260 
266  virtual NeuralResult setClassRegistry(const IClassRegistry* pRegistry) noexcept = 0;
267 
269  virtual const IClassRegistry* getClassRegistry() const noexcept = 0;
270 
277  virtual NeuralResult getWeightsNamesForLayer(IStringList** ppListOut, const ILayer* pLayer) const noexcept = 0;
278 
284  virtual IActivationFunction* defaultForwardActivationFunction(const ILayer* pLayer) const noexcept = 0;
285 
290  virtual NeuralResult getProcessedLayerInputList(const ILayer* pLayer, ILayerList** ppProcessedInputLayerList) const noexcept = 0;
291  };
292 
294  class INetwork2 : public INetwork
295  {
296  public:
298  static const IRefObject::TypeId typeID = 0x18ab6a1edda6c965ul;
299 
300  using INetwork::pushLayer;
301 
308  virtual NeuralResult pushLayer(ILayer* pLayer, const char* pTemplateParentName) noexcept = 0;
309  };
310 
312  class INetwork3 : public INetwork2
313  {
314  public:
316  static const IRefObject::TypeId typeID = 0xe1edc460da161c87ul;
317 
322  virtual void setBuildMode(bool enable) noexcept = 0;
323 
326  virtual bool buildModeRestrictionViolated() const noexcept = 0;
327 
332  virtual const char* getLastBuildModeViolationMessage() const noexcept = 0;
333  };
334 }
335 #endif // NVNEURAL_NETWORKTYPES_H
Fundamental NvNeural data types are declared here.
NetworkBackendId
Enumeration describing common network backends.
Definition: CoreTypes.h:239
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:275
IActivationFunction represents a functor that can perform a specific activation function.
Definition: CoreTypes.h:2015
Common class registry for instantiating objects and collecting plugin-provided descriptors.
Definition: CoreTypes.h:1801
ILayer is the base class for neural network layers.
Definition: LayerTypes.h:59
ILayerList represents an immutable collection of ILayer pointers.
Definition: CoreTypes.h:1060
INetwork2 is the public interface for the revision 2 of the Network interface.
Definition: NetworkTypes.h:295
virtual NeuralResult pushLayer(ILayer *pLayer, const char *pTemplateParentName) noexcept=0
Adds a layer to the network.
INetwork3 is the public interface for the revision 3 of the Network interface.
Definition: NetworkTypes.h:313
virtual bool buildModeRestrictionViolated() const noexcept=0
Returns true if a restricted method was called while in build mode.
virtual void setBuildMode(bool enable) noexcept=0
Enable/disable build mode for the network While in build mode, certains methods from the network are ...
INetworkBackend is a runtime-specific interface for CUDA, DirectX, or other system- specific operatio...
Definition: CoreTypes.h:643
INetworkDebugger defines a callback interface for network inference.
Definition: NetworkTypes.h:51
virtual NeuralResult endLayer(ILayer *pLayer) noexcept=0
Indicates that layer inference has completed.
virtual NeuralResult endPass() noexcept=0
Indicates the end of an inference pass.
virtual NeuralResult endNetwork(INetworkRuntime *pNetworkRuntime, ILayer *pModelLayer, ILayerList *pExternLayerList) noexcept=0
Indicates the end of subnetwork inference within a pass.
virtual NeuralResult beginPass(ILayer **ppInferenceLayers, size_t layerCount) noexcept=0
Indicates the beginning of an inference pass.
virtual NeuralResult beginLayer(ILayer *pLayer) noexcept=0
Indicates that layer inference is beginning.
static const IRefObject::TypeId typeID
Interface TypeId for InterfaceOf purposes.
Definition: NetworkTypes.h:54
virtual NeuralResult skipLayer(ILayer *pLayer) noexcept=0
Indicates that a layer was optimized out during inference and will be skipped.
virtual NeuralResult beginNetwork(INetworkRuntime *pNetworkRuntime, ILayer *pModelLayer, ILayerList *pExternLayerList) noexcept=0
Indicates the beginning of subnetwork inference within a pass.
INetworkDebuggerList represents an immutable collection of INetworkDebugger pointers.
Definition: CoreTypes.h:1111
INetwork is the public interface to Network.
Definition: NetworkTypes.h:119
virtual NeuralResult detachAllNetworkDebuggers() noexcept=0
Detaches all debuggers from the network.
virtual NeuralResult pushLayer(ILayer *pLayer) noexcept=0
Adds a layer to the network.
virtual NeuralResult detachNetworkDebugger(const INetworkDebugger *pDebugger) noexcept=0
Detaches a debugger object from the network.
virtual NeuralResult attachNetworkDebugger(INetworkDebugger *pDebugger) noexcept=0
Attaches a debugger object to the network.
INetworkReshapeDebugger defines a callback interface for reshape operations.
Definition: NetworkTypes.h:97
virtual NeuralResult beginReshapeLayer(ILayer *pLayer) noexcept=0
Callback emitted when a layer is about to reshape.
virtual NeuralResult endReshapeLayer(ILayer *pLayer, NeuralResult reshapeStatus) noexcept=0
Callback emitted when a layer is finished reshaping.
INetworkRuntime is a subset of the basic network interface that is accessible from layer classes duri...
Definition: CoreTypes.h:1129
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
IStringList represents an immutable collection of strings.
Definition: CoreTypes.h:1079
IWeightsLoader is an interface that provides weights to layers.
Definition: CoreTypes.h:525
TensorFormat describes a specific tensor shape (element type and layout).
Definition: CoreTypes.h:88