NVIDIA NvNeural SDK  2021.1
GPU inference framework for NVIDIA Nsight Deep Learning Designer
CoreTypes.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_CORETYPES_H
27 #define NVNEURAL_CORETYPES_H
28 
29 #include <cstddef>
30 #include <cstdint>
31 #include <tuple>
32 #include <type_traits>
33 #include <vector>
34 #include <initializer_list>
35 
36 namespace nvneural {
37  class IImage;
38  class ILayer;
39  class INetwork;
40  class INetworkBackend;
41  class INetworkRuntime;
42  class IPlugin;
43  class IPluginLoader;
44  class IStringList;
45 
51  const std::uint32_t ApiVersion = 1338;
52 
58  enum class TensorDataType : std::uint16_t
59  {
60  Invalid = 0,
61  TestOnly = 1,
62  Float = 2,
63  Half = 3,
64  CompressedPng = 7,
65 
66  CustomBase = 0x4000u,
67  };
68 
74  enum class TensorDataLayout : std::uint16_t
75  {
76  Invalid = 0,
77  TestOnly = 1,
78  Nchw = 2,
79  Nhwc = 3,
80 
81  CustomBase = 0x4000u,
82  };
83 
85  struct TensorFormat
86  {
89 
91  inline TensorFormat()
94  {
95  }
96 
98  inline TensorFormat(TensorDataType elementType_, TensorDataLayout layout_)
99  : elementType{elementType_}
100  , layout{layout_}
101  {
102  }
103 
105  inline bool operator !=(const TensorFormat& other) const noexcept
106  {
107  return elementType != other.elementType
108  || layout != other.layout;
109  }
110 
112  inline bool operator ==(const TensorFormat& other) const noexcept
113  {
114  return !(*this != other);
115  }
116 
120  inline bool operator <(const TensorFormat& other) const noexcept
121  {
122  return std::tie(elementType, layout) < std::tie(other.elementType, other.layout);
123  }
124  };
125 
126  // The Neural plugin ABI assumes a TensorFormat can fit in a single 32-bit register
127  static_assert(sizeof(TensorFormat) == sizeof(std::uint32_t), "TensorFormat structure packing not as expected");
128 
134  {
135  size_t n = 0;
136  size_t c = 0;
137  size_t h = 0;
138  size_t w = 0;
139 
141  inline TensorDimension() = default;
142 
144  inline TensorDimension(size_t N, size_t C, size_t H, size_t W)
145  : n{N}
146  , c{C}
147  , h{H}
148  , w{W}
149  {
150  }
151 
153  ~TensorDimension() = default;
154 
156  inline TensorDimension(const TensorDimension& copyFrom)
157  : n{copyFrom.n}
158  , c{copyFrom.c}
159  , h{copyFrom.h}
160  , w{copyFrom.w}
161  {
162  }
163 
165  inline TensorDimension& operator =(const TensorDimension& copyFrom)
166  {
167  n = copyFrom.n;
168  c = copyFrom.c;
169  h = copyFrom.h;
170  w = copyFrom.w;
171  return *this;
172  }
173 
175  inline bool operator ==(const TensorDimension& other) const
176  {
177  return (n == other.n) && (c == other.c) && (h == other.h) && (w == other.w);
178  }
179 
181  inline bool operator !=(const TensorDimension& other) const
182  {
183  return !(*this == other);
184  }
185 
188  inline std::size_t elementCount() const
189  {
190  return n * c * h *w;
191  }
192  };
193 
194  // The Neural plugin ABI assumes a TensorDimension remains a POD type.
195  static_assert(std::is_standard_layout<TensorDimension>::value, "TensorDimension must be standard layout");
196 
198  class Float16
199  {
200  public:
202  std::uint16_t data = 0u;
203 
205  Float16() = default;
206 
208  Float16(const Float16& copyFrom);
209 
211  explicit Float16(float value);
212 
214  inline Float16& operator=(double value)
215  {
216  *this = Float16(static_cast<float>(value));
217  return *this;
218  }
219 
221  inline Float16& operator =(const Float16& copyFrom)
222  {
223  data = copyFrom.data;
224  return *this;
225  }
226 
228  operator float() const;
229  };
230 
236  enum class NetworkBackendId : std::uint32_t
237  {
239  Invalid = 0,
240 
241  TestOnly = 1,
242  Cpu = 2,
243  Cuda = 3,
244 
245  CustomBase = 0x4000u,
246  };
247 
256  enum class ActivationFunctionId : std::uint32_t
257  {
258  None = 0,
259  ReLU = 1,
260  LeakyReLU = 2,
261  LeakySigmoid = 3,
262  LeakyTanh = 4,
263  Tanh = 5,
264  Sigmoid = 6,
265  Softmax = 7,
266  Sine = 8,
267 
268  CustomBase = 0x4000u,
269  };
270 
272  enum class NeuralResult : std::int32_t
273  {
274  // *If* we need them, additional success codes will go here (e.g., S_FALSE = -1)
275  Success = 0,
276  Failure = 1,
277  Unsupported = 2,
278  // *If* we need them, additional failure codes will go here (e.g., E_POINTER = 3)
279  };
280 
282  inline constexpr bool succeeded(NeuralResult result) noexcept
283  {
284  return result <= NeuralResult::Success;
285  }
287  inline constexpr bool failed(NeuralResult result) noexcept
288  {
289  return result >= NeuralResult::Failure;
290  }
291 
297  enum class ImageSpace : std::uint32_t
298  {
299  Invalid = 0,
300  RgbNormalized = 1,
301  RgbCentered = 2,
302 
303  CustomBase = 0x4000u,
304  };
305 
341  {
342  public:
344  using RefCount = std::uint32_t;
345 
347  using TypeId = std::uint64_t;
348 
350  static const TypeId typeID = 0x14ecc3f9de638e1dul;
351 
355  virtual RefCount addRef() const noexcept = 0;
356 
361  virtual RefCount release() const noexcept = 0;
362 
382  virtual void* queryInterface(TypeId interface) noexcept = 0;
383 
385  virtual const void* queryInterface(TypeId interface) const noexcept = 0;
386 
387  protected:
390  virtual ~IRefObject() = default;
391  };
392 
399  template<typename TInterface>
400  struct InterfaceOf
401  {
403  static constexpr IRefObject::TypeId value = TInterface::typeID;
404  };
405 
411  class ILogger : public IRefObject
412  {
413  public:
415  static const IRefObject::TypeId typeID = 0xd74335d06aa1ba61ul;
416 
422  using VerbosityLevel = std::int32_t;
423 
431  virtual VerbosityLevel verbosity() const noexcept = 0;
432 
440  virtual NeuralResult log(VerbosityLevel verbosity, const char* format, ...) noexcept = 0;
441 
454  virtual NeuralResult logWarning(VerbosityLevel verbosity, const char* format, ...) noexcept = 0;
455 
472  virtual NeuralResult logError(VerbosityLevel verbosity, const char* format, ...) noexcept = 0;
473  };
474 
481  {
482  public:
484  static const IRefObject::TypeId typeID = 0x310ca743db44232dul;
485 
487  virtual std::uint32_t apiVersion() const noexcept = 0;
488  };
489 
491  class IWeightsData : public IRefObject
492  {
493  public:
495  static const IRefObject::TypeId typeID = 0xba912359795313f3ul;
496 
498  virtual NetworkBackendId backendId() const noexcept = 0;
499 
501  virtual TensorFormat tensorFormat() const noexcept = 0;
502 
504  virtual TensorDimension dimension() const noexcept = 0;
505 
508  virtual bool memManagedExternally() const noexcept = 0;
509 
515  virtual const void* data() const noexcept = 0;
516  };
517 
522  class IWeightsLoader : public IRefObject
523  {
524  public:
526  static const IRefObject::TypeId typeID = 0x5bac8f6ca68c52b6ul;
527 
534  virtual NeuralResult getWeightsForLayer(IWeightsData** ppWeightsDataOut, const INetworkRuntime* pNetwork, const ILayer* pLayer, const char* pName) const noexcept = 0;
535  };
536 
542  {
543  public:
545  static const IRefObject::TypeId typeID = 0x9874b8d21b0c9697ul;
546 
551  virtual NeuralResult optionsRefreshed(const ILayer* pLayer) noexcept = 0;
552  };
553 
569  {
570  public:
572  static const IRefObject::TypeId typeID = 0x1ec1c40bfc1e45a4ul;
573 
575  using LibraryId = std::uint64_t;
576 
578  virtual LibraryId libraryId() const noexcept = 0;
579 
585  virtual NeuralResult synchronize(INetworkBackend* pBackend) noexcept = 0;
586 
592  virtual NeuralResult bindCurrentThread(INetworkBackend* pBackend) noexcept = 0;
593  };
594 
601  {
602  public:
604  static const IRefObject::TypeId typeID = 0xf78683bf5a3d24a9ul;
605 
610  virtual NeuralResult getDeviceIdentifiers(std::uint64_t* pUuidLow, std::uint64_t* pUuidHigh) const noexcept = 0;
611 
617  virtual const char* getDeviceName() const noexcept = 0;
618  };
619 
621  class MemoryHandle__type;
622 
624  using MemoryHandle = MemoryHandle__type*;
625 
628  enum class MemorySemantic : std::uint32_t
629  {
630  Unspecified = 0u,
631  Tensor = 1u,
632  Weights = 2u,
633  Ephemeral = 3u,
634 
635  CustomBase = 0x4000u,
636  };
637 
641  {
642  public:
644  static const IRefObject::TypeId typeID = 0xacd7828da90108ddul;
645 
658 
660  enum class OptimizationCapability : std::uint64_t
661  {
667  SkipConcatenation = 0xdd13d58fbabb2f5bul,
668 
675  FuseBatchNormAndConvolution = 0xeaffe6d9a4acfdc9ul,
676  };
677 
684  virtual bool supportsOptimization(OptimizationCapability optimization) const noexcept = 0;
685 
687 
690 
700  virtual NeuralResult initializeFromDeviceOrdinal(std::uint32_t deviceOrdinal) noexcept = 0;
701 
712  virtual NeuralResult initializeFromDeviceIdentifier(const IBackendDeviceIdentifier* pDeviceIdentifier) noexcept = 0;
713 
718  virtual const IBackendDeviceIdentifier* deviceIdentifier() const noexcept = 0;
719 
721 
723  virtual NetworkBackendId id() const noexcept = 0;
724 
726  virtual NeuralResult synchronize() noexcept = 0;
727 
729  virtual NeuralResult bindCurrentThread() noexcept = 0;
730 
732  virtual NeuralResult transformTensor(
733  void* pDeviceDestination,
734  TensorFormat destinationFormat,
735  TensorDimension destinationSize,
736  const void* pDeviceSource,
737  TensorFormat sourceFormat,
738  TensorDimension sourceSize) noexcept = 0;
739 
742 
744  virtual NeuralResult setDeviceMemory(void* pDeviceDestination, std::uint8_t value, std::size_t byteCount) noexcept = 0;
745 
747  virtual NeuralResult copyMemoryD2D(void* pDeviceDestination, const void* pDeviceSource, std::size_t byteCount) noexcept = 0;
748 
750  virtual NeuralResult copyMemoryH2D(void* pDeviceDestination, const void* pHostSource, std::size_t byteCount) noexcept = 0;
751 
753  virtual NeuralResult copyMemoryD2H(void* pHostDestination, const void* pDeviceSource, std::size_t byteCount) noexcept = 0;
754 
756 
769 
777  virtual NeuralResult registerLibraryContext(ILibraryContext* pLibraryContext) noexcept = 0;
778 
783  virtual ILibraryContext* getLibraryContext(ILibraryContext::LibraryId libraryId) noexcept = 0;
784 
786  virtual const ILibraryContext* getLibraryContext(ILibraryContext::LibraryId libraryId) const noexcept = 0;
787 
789 
792 
801  virtual NeuralResult allocateMemoryBlock(MemoryHandle* pHandle, size_t byteCount) noexcept = 0;
802 
808  virtual NeuralResult freeMemoryBlock(MemoryHandle handle) noexcept = 0;
809 
817  virtual void* getAddressForMemoryBlock(MemoryHandle handle) noexcept = 0;
818 
826  virtual size_t getSizeForMemoryBlock(MemoryHandle handle) noexcept = 0;
827 
833  virtual NeuralResult lockMemoryBlock(MemoryHandle handle) noexcept = 0;
834 
840  virtual NeuralResult unlockMemoryBlock(MemoryHandle handle) noexcept = 0;
841 
843  virtual MemoryHandle updateTensor(
844  const ILayer* pLayer,
845  INetworkRuntime* pNetwork,
846  TensorFormat format,
847  MemoryHandle hOriginal,
848  TensorDimension stepping) noexcept = 0;
849 
851 
854 
856  virtual NeuralResult clearLoadedWeights() noexcept = 0;
857 
868  virtual NeuralResult uploadWeights(
869  const void** ppUploadedWeightsOut,
870  const ILayer* pLayer,
871  const char* pName,
872  const void* pWeightsData,
873  std::size_t weightsDataSize,
874  TensorDimension weightsDim,
875  TensorFormat format,
876  bool memManagedExternally) noexcept = 0;
877 
888  virtual const void* getAddressForWeightsData(const ILayer* pLayer, const char* pName, TensorFormat format) const noexcept = 0;
889 
899  virtual NeuralResult getDimensionsForWeightsData(TensorDimension* pDimensionOut, const ILayer* pLayer, const char* pName, TensorFormat format) const noexcept = 0;
900 
905  virtual NeuralResult getWeightsNamesForLayer(IStringList** ppListOut, const ILayer* pLayer) const noexcept = 0;
906 
908 
915  virtual NeuralResult saveImage(const ILayer* pLayer, IImage* pImage, ImageSpace imageSpace, size_t channels) noexcept = 0;
916  };
917 
926  class ILayerList : public IRefObject
927  {
928  public:
930  static const IRefObject::TypeId typeID = 0x28d94b933a3b0dabul;
931 
933  virtual size_t layerCount() const noexcept = 0;
934 
939  virtual ILayer* getLayerByIndex(size_t layerIndex) const noexcept = 0;
940  };
941 
945  class IStringList : public IRefObject
946  {
947  public:
949  static const IRefObject::TypeId typeID = 0x5952141d72c5cda0ul;
950 
952  virtual size_t stringCount() const noexcept = 0;
953 
963  virtual const char* getStringByIndex(size_t stringIndex) const noexcept = 0;
964 
971  virtual size_t getStringSizeByIndex(size_t stringIndex) const noexcept = 0;
972  };
973 
974  class INetworkDebugger; // forward reference
975 
978  {
979  public:
981  static const IRefObject::TypeId typeID = 0xde9c8f7c71a9dcbaul;
982 
984  virtual size_t debuggerCount() const noexcept = 0;
985 
990  virtual INetworkDebugger* getNetworkDebuggerByIndex(size_t index) const noexcept = 0;
991  };
992 
996  {
997  public:
999  static const IRefObject::TypeId typeID = 0x53191c073f990992ul;
1000 
1002  virtual const char* networkName() const noexcept = 0;
1003 
1008  virtual INetworkBackend* getBackend(NetworkBackendId backendId) noexcept = 0;
1009 
1011  virtual const INetworkBackend* getBackend(NetworkBackendId backendId) const noexcept = 0;
1012 
1017  virtual NeuralResult defaultForwardActivation(ILayer* pLayer) const noexcept = 0;
1018 
1020  virtual IWeightsLoader* weightsLoader() const noexcept = 0;
1021 
1023  virtual NetworkBackendId defaultBackendId() const noexcept = 0;
1024 
1026  virtual TensorFormat defaultTensorFormat() const noexcept = 0;
1027 
1031  virtual NeuralResult reshapeLater(ILayer* pLayer) noexcept = 0;
1032 
1035 
1037  virtual size_t layerCount() const noexcept = 0;
1038 
1043  virtual ILayer* getLayerByName(const char* pLayerName) const noexcept = 0;
1044 
1050  virtual NeuralResult getAllLayers(ILayerList** ppListOut) const noexcept = 0;
1051 
1059  virtual NeuralResult getInputLayers(ILayerList** ppListOut) const noexcept = 0;
1060 
1067  virtual NeuralResult getOutputLayers(ILayerList** ppListOut) const noexcept = 0;
1068 
1073  virtual NeuralResult getDependentLayers(ILayerList** ppListOut, const ILayer* pLayer) const noexcept = 0;
1074 
1080  virtual NeuralResult getAcceptorLayers(ILayerList** ppListOut, const ILayer* pLayer) const noexcept = 0;
1081 
1086  virtual NeuralResult getInfluenceLayers(ILayerList** ppListOut, const ILayer* pLayer) const noexcept = 0;
1087 
1089 
1096  virtual NeuralResult setAffectedForward(ILayer* pLayer) noexcept = 0;
1097 
1106  virtual void* getTensor(const ILayer* pDataLayer, const ILayer* pRequestingLayer, TensorFormat format) noexcept = 0;
1107 
1117  virtual void* getInternalTensor(const ILayer* pLayer, NetworkBackendId backendId) noexcept = 0;
1118 
1130  virtual NeuralResult mapLayerAsWeightsData(const ILayer* pDataLayer, const ILayer* pWeightsLayer, const char* pWeightsName) noexcept = 0;
1131 
1143  virtual const void* getWeightsForLayer(const ILayer* pLayer, const char* pWeightsName, NetworkBackendId backendId, TensorFormat format) noexcept = 0;
1144 
1152  virtual NeuralResult getWeightsDimensionForLayer(
1153  TensorDimension* pDimensionsOut,
1154  const ILayer* pLayer,
1155  const char* pWeightsName,
1156  NetworkBackendId backendId,
1157  TensorFormat format) noexcept = 0;
1158  };
1159 
1168  enum class ParamType : std::uint16_t
1169  {
1170  String = 0,
1171  SizeT = 1,
1172  Float = 2,
1173  Enumeration = 3,
1174  Dimension = 4,
1175  Bool = 5,
1176  MaxParam,
1177  CustomBase = 0x4000u,
1178  };
1179 
1184  {
1187  std::size_t structSize;
1188 
1191  };
1192 
1204  {
1207 
1209  std::size_t maxDimensions;
1210 
1212  std::size_t minDimensions;
1213  };
1214 
1226  {
1229 
1231  std::size_t optionCount;
1232 
1237  const char* const* pOptions;
1238  };
1239 
1245  {
1248 
1252  };
1253 
1257  struct ParamDesc
1258  {
1260  std::size_t structSize;
1261 
1266  const char* pName;
1267 
1272  const char* pDefault;
1273 
1278 
1283  const char* pDocumentation;
1284 
1290  };
1291 
1298  namespace common_categories
1299  {
1300  const char* const General = "General";
1301  const char* const InputOutput = "Input/Output";
1302  const char* const Training = "Training";
1303  const char* const FormatConversion = "Format Conversion";
1304  const char* const Shape = "Shape";
1305  const char* const Upsampling = "Upsampling";
1306  const char* const Fused = "Fused";
1307  const char* const Examples = "Examples";
1308  const char* const DataImageProcessing = "Data/Image Processing";
1309  const char* const DomainSpecific = "Domain Specific";
1310  const char* const DevelopmentAids = "Development Aids";
1311  const char* const Analysis = "Analysis";
1312  const char* const DefaultHidden = "Hidden";
1313  } // namespace nvneural::common_categories
1314 
1325  enum class LayerInputType : std::uint16_t
1326  {
1327  Primary = 0,
1328  PrimaryInfinite = 1,
1329  Secondary = 2,
1330  CustomBase = 0x4000u
1331  };
1332 
1335  {
1337  std::size_t structSize;
1338 
1343  const char* pName;
1344 
1349  const char* pDocumentation;
1350 
1355  };
1356 
1357 
1361  struct LayerDesc
1362  {
1366  std::size_t structSize;
1367 
1374  const char* pObjectClass;
1375 
1380  const char* pSerializedName;
1381 
1386  const char* pDocumentation;
1387 
1391  const char* pDisplayName;
1392 
1395  std::size_t numCategories;
1396 
1400  const char* const* ppCategories;
1401 
1406 
1411 
1414  std::size_t numInputs;
1415 
1420 
1423 
1428  std::size_t numParameters;
1429 
1435  };
1436 
1442  {
1446  std::size_t structSize;
1447 
1452  const char* pObjectClass;
1453 
1457  const char* pSerializedName;
1458 
1461  const char* pDocumentation;
1462 
1468  const char* pDisplayName;
1469 
1472 
1479 
1483 
1486  std::size_t numParameters;
1487 
1492  };
1493 
1495  enum class CompilationLevel : std::uint16_t
1496  {
1497  CompiledBinary = 0,
1498  JitIntermediate = 1,
1499  JitSource = 2,
1500  };
1501 
1505  {
1509  std::size_t structSize;
1510 
1515  const char* pObjectClass;
1516 
1521  const char* pSerializedName;
1522 
1526  const char* pDisplayName;
1527 
1532 
1535 
1538  };
1539 
1545  typedef bool (*PrototypeRuntimeValidatorFunction)(const INetwork* pNetwork);
1546 
1588  struct FusingRule
1589  {
1592  std::uint32_t syntaxVersion;
1593 
1596  const char* pFusingRule;
1597  };
1598 
1609  {
1610  public:
1612  static const IRefObject::TypeId typeID = 0x261ae312ee3c4979ul;
1613 
1618  virtual NeuralResult importPlugin(IPlugin* pPlugin) = 0;
1619 
1626  virtual NeuralResult importPluginLoader(IPluginLoader* pPluginLoader) = 0;
1627 
1629  virtual std::size_t exportedActivationsCount() const noexcept = 0;
1630 
1636  virtual const ActivationDesc* exportedActivationByIndex(std::size_t index) const noexcept = 0;
1637 
1639  virtual std::size_t exportedLayersCount() const noexcept = 0;
1640 
1646  virtual const LayerDesc* exportedLayerByIndex(std::size_t index) const noexcept = 0;
1647 
1649  virtual std::size_t exportedFusingRulesCount() const noexcept = 0;
1650 
1656  virtual const FusingRule* exportedFusingRuleByIndex(std::size_t index) const noexcept = 0;
1657 
1659  virtual std::size_t exportedPrototypesCount() const noexcept = 0;
1660 
1666  virtual const PrototypeDesc* exportedPrototypeByIndex(std::size_t index) const noexcept = 0;
1667 
1673  virtual PrototypeRuntimeValidatorFunction exportedPrototypeRuntimeValidatorByIndex(std::size_t index) const noexcept = 0;
1674 
1681  virtual NeuralResult createObject(IRefObject** ppOut, const char* pObjectClass) const noexcept = 0;
1682 
1688  virtual bool isPrototypeRuntimeCompatible(const char* pPrototypeObjectClass, const INetwork* pNetwork) const = 0;
1689  };
1690 
1697  {
1698  public:
1700  static const IRefObject::TypeId typeID = 0x4f0ffb1d41d49fcul;
1701 
1704 
1709  virtual NeuralResult getInteger(const char* pParameterName, std::int32_t* pIntOut) const noexcept = 0;
1710 
1715  virtual NeuralResult getSize(const char* pParameterName, std::size_t* pSizeOut) const noexcept = 0;
1716 
1721  virtual NeuralResult getFloat(const char* pParameterName, float* pFloatOut) const noexcept = 0;
1722 
1727  virtual NeuralResult getString(const char* pParameterName, const char** pStringOut) const noexcept = 0;
1728 
1738  virtual NeuralResult getDimension(const char* pParameterName, TensorDimension* pDimOut) const noexcept = 0;
1739 
1741 
1744 
1749  virtual NeuralResult setInteger(const char* pParameterName, std::int32_t value) noexcept = 0;
1750 
1755  virtual NeuralResult setSize(const char* pParameterName, std::size_t value) noexcept = 0;
1756 
1761  virtual NeuralResult setFloat(const char* pParameterName, float value) noexcept = 0;
1762 
1767  virtual NeuralResult setString(const char* pParameterName, const char* pString) noexcept = 0;
1768 
1773  virtual NeuralResult setDimension(const char* pParameterName, TensorDimension value) noexcept = 0;
1774 
1776  };
1777 
1779  class IImage : public IRefObject
1780  {
1781  public:
1783  static const IRefObject::TypeId typeID = 0x2a21f61fbfee3221ul;
1784 
1788  virtual NeuralResult resize(std::size_t height, std::size_t width, std::size_t channels) noexcept = 0;
1789 
1791  virtual std::size_t height() const noexcept = 0;
1792 
1794  virtual std::size_t width() const noexcept = 0;
1795 
1797  virtual std::size_t channels() const noexcept = 0;
1798 
1802  virtual std::size_t elements() const noexcept = 0;
1803 
1807  virtual std::uint8_t* data() noexcept = 0;
1808 
1810  virtual const std::uint8_t* data() const noexcept = 0;
1811  };
1812 
1823  {
1824  public:
1826  static const IRefObject::TypeId typeID = 0x66e36120ed8745d8ul;
1827 
1829  virtual NeuralResult setNetworkRuntime(INetworkRuntime* pNetwork) noexcept = 0;
1830 
1832  virtual NeuralResult invoke(ILayer* pLayer) noexcept = 0;
1833 
1839  virtual const char* serializedType() const noexcept = 0;
1840  };
1841 
1842 } // namespace nvneural
1843 
1844 #endif // NVNEURAL_CORETYPES_H
@ Tensor
This order is used for parameters that typically describe tensor dimensions.
MemorySemantic
Describes the intended purpose of allocated GPU memory.
Definition: CoreTypes.h:629
@ Ephemeral
Memory used for short-lived scratch computations.
@ Unspecified
Generic allocation type, not tagged for any specific use.
@ Weights
Memory used for weights data; typically long-lived.
constexpr bool failed(NeuralResult result) noexcept
Helper function akin to COM's FAILED() macro.
Definition: CoreTypes.h:287
const std::uint32_t ApiVersion
API version set.
Definition: CoreTypes.h:51
TensorDataType
Enumeration describing common tensor element types.
Definition: CoreTypes.h:59
@ Float
32-bit floating point elements (float)
@ CompressedPng
NV Internal: Used to transit png like tensor between host and inference target.
@ CustomBase
Custom entries in this enum should use IDs numerically higher than this value.
@ Invalid
Invalid value used to guard against uninitialized variables.
@ TestOnly
Only used in a testing environment.
@ Half
16-bit floating point elements (__half)
ImageSpace
ImageSpace values refer to specific tensor representations of image data.
Definition: CoreTypes.h:298
@ RgbNormalized
RGB normalized to unit range; range is [0, 1].
@ RgbCentered
RGB centered around 0; range is [-1, 1].
TensorDataLayout
Enumeration describing common tensor data layouts.
Definition: CoreTypes.h:75
LayerInputType
This enum describes what type a particular input is for the layer.
Definition: CoreTypes.h:1326
@ Primary
Most inputs are "primary" inputs.
@ Secondary
Represents an input that is typically provided by the weights system.
@ PrimaryInfinite
Layers like concat and element_wise can take arbitrary numbers of inputs. Define one of these.
MemoryHandle__type * MemoryHandle
Opaque typedef used to represent INetworkBackend memory handles.
Definition: CoreTypes.h:624
constexpr bool succeeded(NeuralResult result) noexcept
Helper function akin to COM's SUCCEEDED() macro.
Definition: CoreTypes.h:282
NetworkBackendId
Enumeration describing common network backends.
Definition: CoreTypes.h:237
@ Cpu
Pure CPU code, no GPU involvement (largely unused)
@ Cuda
CUDA/cuDNN backend.
ParamType
This enum describes what type a particular parameter.
Definition: CoreTypes.h:1169
@ MaxParam
Should also be the next number for new non-custom types.
CompilationLevel
This enum represent kernel type contained by a prototype layer.
Definition: CoreTypes.h:1496
@ JitIntermediate
Examples: PTX, SPIR-V, or a compiled HLSL shader.
@ CompiledBinary
Example: SASS.
@ JitSource
Examples: CUDA C++, GLSL, or HLSL.
ActivationFunctionId
Enumeration describing common activation functions.
Definition: CoreTypes.h:257
@ LeakySigmoid
Leaky sigmoid ([0] = negative slope, [1] = positive slope)
@ Sine
Sine (also known as SIREN)
@ LeakyTanh
Leaky tanh ([0] = negative slope, [1] = positive slope)
@ LeakyReLU
Leaky ReLU ([0] = slope)
@ Tanh
Hyperbolic tangent.
@ ReLU
ReLU ([0] = minimum value to return)
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:273
@ Success
Operation succeeded. Generic result.
@ Unsupported
Operation failed and will not pass on a retry (not implemented or logic error).
@ Failure
Operation failed. Generic result.
Float16 is a CPU-side implementation of half-precision floating point (aka FP16).
Definition: CoreTypes.h:199
Float16()=default
Default constructor, initializes to zero.
Float16 & operator=(double value)
Assignment operator from float/double.
Definition: CoreTypes.h:214
std::uint16_t data
Sized integer containing the float16 value.
Definition: CoreTypes.h:202
IActivationFunction represents a functor that can perform a specific activation function.
Definition: CoreTypes.h:1823
virtual const char * serializedType() const noexcept=0
Retrieves the type of the activation function.
virtual NeuralResult setNetworkRuntime(INetworkRuntime *pNetwork) noexcept=0
Sets the owning network runtime. Will be called before any call to invoke.
virtual NeuralResult invoke(ILayer *pLayer) noexcept=0
Performs activation for a layer.
The IApiVersionQuery interface provides this object's compiled-in ApiVersion.
Definition: CoreTypes.h:481
virtual std::uint32_t apiVersion() const noexcept=0
Returns the value of ApiVersion used to build this object.
IBackendDeviceIdentifier is an opaque identifier for an active GPU.
Definition: CoreTypes.h:601
virtual const char * getDeviceName() const noexcept=0
Retrieves the name of this GPU.
virtual NeuralResult getDeviceIdentifiers(std::uint64_t *pUuidLow, std::uint64_t *pUuidHigh) const noexcept=0
Retrieves a pair of values that uniquely identify this GPU on the local system.
Common class registry for instantiating objects and collecting plugin-provided descriptors.
Definition: CoreTypes.h:1609
virtual NeuralResult importPluginLoader(IPluginLoader *pPluginLoader)=0
Imports all plugins loaded by a plugin loader.
virtual NeuralResult importPlugin(IPlugin *pPlugin)=0
Imports everything (layer, activation, fusing rules, and prototypes) registered with a single plugin.
virtual std::size_t exportedActivationsCount() const noexcept=0
Returns the count of registered activation functions.
IImage represents a bitmap image in system memory.
Definition: CoreTypes.h:1780
virtual std::size_t height() const noexcept=0
Returns the height of the image in pixels.
virtual NeuralResult resize(std::size_t height, std::size_t width, std::size_t channels) noexcept=0
Clears the image and reserves storage.
ILayer is the base class for neural network layers.
Definition: LayerTypes.h:59
ILayerList represents an immutable collection of ILayer pointers.
Definition: CoreTypes.h:927
virtual size_t layerCount() const noexcept=0
Returns the number of layers in this collection.
ILibraryContext is a generic library handle wrapper.
Definition: CoreTypes.h:569
std::uint64_t LibraryId
Library IDs should be generated randomly similar to interface IDs.
Definition: CoreTypes.h:575
virtual LibraryId libraryId() const noexcept=0
Retrieves a stable identifier for the library being tracked in this object.
Logger interface class.
Definition: CoreTypes.h:412
virtual VerbosityLevel verbosity() const noexcept=0
Retrieves the current verbosity level.
std::int32_t VerbosityLevel
Typedef for verbosity levels.
Definition: CoreTypes.h:422
INetworkBackend is a runtime-specific interface for CUDA, DirectX, or other system- specific operatio...
Definition: CoreTypes.h:641
virtual bool supportsOptimization(OptimizationCapability optimization) const noexcept=0
Returns true if the indicated optimization is applicable to this backend.
virtual const IBackendDeviceIdentifier * deviceIdentifier() const noexcept=0
Retrieves an opaque device identifier object corresponding to the device associated with this backend...
virtual NeuralResult initializeFromDeviceIdentifier(const IBackendDeviceIdentifier *pDeviceIdentifier) noexcept=0
Initializes the backend to point to a specific device identifier.
OptimizationCapability
List of optional optimizations supported by backends.
Definition: CoreTypes.h:661
virtual NeuralResult initializeFromDeviceOrdinal(std::uint32_t deviceOrdinal) noexcept=0
Initializes the backend to point to a specific device ordinal.
INetworkDebugger defines a callback interface for network inference.
Definition: NetworkTypes.h:51
INetworkDebuggerList represents an immutable collection of INetworkDebugger pointers.
Definition: CoreTypes.h:978
virtual size_t debuggerCount() const noexcept=0
INetwork is the public interface to Network.
Definition: NetworkTypes.h:119
INetworkRuntime is a subset of the basic network interface that is accessible from layer classes duri...
Definition: CoreTypes.h:996
virtual const char * networkName() const noexcept=0
Retrieves the name of this network as a UTF-8 string.
Represents a serialized parameter block in a model definition.
Definition: CoreTypes.h:1697
virtual NeuralResult setInteger(const char *pParameterName, std::int32_t value) noexcept=0
Saves an integer.
virtual NeuralResult getString(const char *pParameterName, const char **pStringOut) const noexcept=0
Retrieves a UTF-8 string value.
virtual NeuralResult setString(const char *pParameterName, const char *pString) noexcept=0
Saves a UTF-8 string value.
virtual NeuralResult getSize(const char *pParameterName, std::size_t *pSizeOut) const noexcept=0
Retrieves an unsigned integer value that can represent the result of sizeof().
virtual NeuralResult setFloat(const char *pParameterName, float value) noexcept=0
Saves a floating-point value.
virtual NeuralResult getFloat(const char *pParameterName, float *pFloatOut) const noexcept=0
Retrieves a floating-point value.
virtual NeuralResult getDimension(const char *pParameterName, TensorDimension *pDimOut) const noexcept=0
Retrieves a tensor dimension.
virtual NeuralResult setSize(const char *pParameterName, std::size_t value) noexcept=0
Saves an unsigned integer that can represent the result of sizeof().
virtual NeuralResult setDimension(const char *pParameterName, TensorDimension value) noexcept=0
Saves a tensor dimension.
virtual NeuralResult getInteger(const char *pParameterName, std::int32_t *pIntOut) const noexcept=0
Retrieves a signed integer value.
IPlugin is the general factory interface used by NvNeural's plugin system.
Definition: PluginTypes.h:41
Platform-agnostic plugin loader interface.
Definition: PluginTypes.h:200
Base class for all objects, similar to COM's IUnknown.
Definition: CoreTypes.h:341
virtual void * queryInterface(TypeId interface) noexcept=0
Retrieves a new object interface pointer.
static const TypeId typeID
Interface TypeId for InterfaceOf purposes.
Definition: CoreTypes.h:350
std::uint64_t TypeId
Every interface must define a unique TypeId. This should be randomized.
Definition: CoreTypes.h:347
std::uint32_t RefCount
Typedef used to track the number of active references to an object.
Definition: CoreTypes.h:344
virtual RefCount addRef() const noexcept=0
Increments the object's reference count.
virtual RefCount release() const noexcept=0
Decrements the object's reference count and destroy the object if the reference count reaches zero.
IRuntimeOptionsHost is an interface that provides runtime option communication from the layer to the ...
Definition: CoreTypes.h:542
virtual NeuralResult optionsRefreshed(const ILayer *pLayer) noexcept=0
Layers should call this when the options have changed, but not when the value for the option has chan...
IStringList represents an immutable collection of strings.
Definition: CoreTypes.h:946
virtual size_t stringCount() const noexcept=0
IWeightsData represents a binary buffer provided by IWeightsLoader.
Definition: CoreTypes.h:492
virtual NetworkBackendId backendId() const noexcept=0
Returns the backend for which this weights data is relevant.
IWeightsLoader is an interface that provides weights to layers.
Definition: CoreTypes.h:523
virtual NeuralResult getWeightsForLayer(IWeightsData **ppWeightsDataOut, const INetworkRuntime *pNetwork, const ILayer *pLayer, const char *pName) const noexcept=0
Retrieves a weights data buffer in a canonical format.
const char *const Analysis
Category for visualization and analysis layers.
Definition: CoreTypes.h:1311
const char *const Examples
Category for demonstration layers.
Definition: CoreTypes.h:1307
const char *const DataImageProcessing
Category for layers that do image processing.
Definition: CoreTypes.h:1308
const char *const Fused
Category for layers that fuse multiple operations.
Definition: CoreTypes.h:1306
const char *const Training
Category for layers that represent training-only concepts.
Definition: CoreTypes.h:1302
const char *const Shape
Category for layers that adjust tensor shape.
Definition: CoreTypes.h:1304
const char *const InputOutput
Category for layers that interact with their host application.
Definition: CoreTypes.h:1301
const char *const DevelopmentAids
Category for layers that aid framework development.
Definition: CoreTypes.h:1310
const char *const DefaultHidden
Category for layers that should be hidden in the editor by default.
Definition: CoreTypes.h:1312
const char *const General
Category for layers that don't fit other categories.
Definition: CoreTypes.h:1300
const char *const Upsampling
Category for layers that upscale their input.
Definition: CoreTypes.h:1305
const char *const DomainSpecific
Category for layers that implement specialized operations.
Definition: CoreTypes.h:1309
const char *const FormatConversion
Category for layers that permute and shuffle data.
Definition: CoreTypes.h:1303
Structure describing an activation function (IActivationFunction) for tool interfaces and network bui...
Definition: CoreTypes.h:1442
std::size_t structSize
This is the sizeof() this struct.
Definition: CoreTypes.h:1446
ActivationFunctionId activationFunction
This is the activation function ID implemented by this activation function.
Definition: CoreTypes.h:1471
std::size_t numParameters
This is the number of parameters supported for this activation.
Definition: CoreTypes.h:1486
TensorFormat tensorFormat
This is the tensor format supported by this activation function.
Definition: CoreTypes.h:1482
NetworkBackendId backend
This is the backend identifier supported by this instance of the activation function.
Definition: CoreTypes.h:1478
const char * pDocumentation
An optional human-readable descriptive text.
Definition: CoreTypes.h:1461
const ParamDesc * pParameters
This is the pointer to the contiguous memory of ParamDesc structs.
Definition: CoreTypes.h:1491
const char * pSerializedName
This is the name used to represent the activation function in serialized form.
Definition: CoreTypes.h:1457
const char * pObjectClass
This is the programmatic class name used to instantiate the activation object through the IPlugin::cr...
Definition: CoreTypes.h:1452
const char * pDisplayName
An optional human-readable layer name.
Definition: CoreTypes.h:1468
For implementers, this struct needs to be replicated in each xParamTypeDesc right now.
Definition: CoreTypes.h:1184
ParamType paramType
This for additional safety and reference. Should replicate the xParamDesc::paramType.
Definition: CoreTypes.h:1190
std::size_t structSize
This is the sizeof() the xParamTypeDesc struct that contains this struct.
Definition: CoreTypes.h:1187
The DimensionParamTypeDesc further describes a parameter for the plugin and is pointed to from the hi...
Definition: CoreTypes.h:1204
std::size_t minDimensions
This is the minimum amount of dimensions that are needed.
Definition: CoreTypes.h:1212
BaseParamTypeDesc baseDesc
This is the base param desc struct which all xParamTypeDesc must have.
Definition: CoreTypes.h:1206
std::size_t maxDimensions
This is the maximum amount of dimensions that are valid.
Definition: CoreTypes.h:1209
The EnumParamTypeDesc further describes a parameter for the plugin and is pointed to from the higher ...
Definition: CoreTypes.h:1226
BaseParamTypeDesc baseDesc
This is the base param desc struct which all xParamTypeDesc must have.
Definition: CoreTypes.h:1228
const char *const * pOptions
This is the array of the enums with optionCount members.
Definition: CoreTypes.h:1237
std::size_t optionCount
This is the amount of enum options contained in the memory block.
Definition: CoreTypes.h:1231
Defines a fusing rule that can be applied during model loading.
Definition: CoreTypes.h:1589
std::uint32_t syntaxVersion
This is the version number of the fusing rule grammar.
Definition: CoreTypes.h:1592
const char * pFusingRule
This is the fusing rule text, encoded in UTF-8.
Definition: CoreTypes.h:1596
Helper template to aid retrieval of interface IDs.
Definition: CoreTypes.h:401
This structure describes an ILayer for tools and network builders.
Definition: CoreTypes.h:1362
NetworkBackendId backend
This is the backend identifier supported by this instance of the layer type.
Definition: CoreTypes.h:1405
const char * pObjectClass
This is the programmatic class name used to instantiate the layer object through the IPlugin::createO...
Definition: CoreTypes.h:1374
std::size_t numCategories
This is the number of categories.
Definition: CoreTypes.h:1395
bool generatesOutput
Describes whether the primary output from this layer generates output.
Definition: CoreTypes.h:1422
const ParamDesc * pParameters
This is the pointer to the array of ParamDesc structs.
Definition: CoreTypes.h:1434
const char * pDisplayName
An optional human-readable layer name.
Definition: CoreTypes.h:1391
std::size_t numInputs
This is the number of inputs supported by this layer.
Definition: CoreTypes.h:1414
const LayerInputDesc * pInputs
This is a pointer to the array of LayerInputDesc structs which define the inputs to this layer.
Definition: CoreTypes.h:1419
TensorFormat tensorFormat
This is a tensor format supported by this instance of the layer type.
Definition: CoreTypes.h:1410
const char * pDocumentation
An optional human-readable descriptive text.
Definition: CoreTypes.h:1386
const char * pSerializedName
This is the name used to represent the layer type in serialized form.
Definition: CoreTypes.h:1380
const char *const * ppCategories
An optional array of strings which denote categories that the host can use to organize this layer.
Definition: CoreTypes.h:1400
std::size_t numParameters
This is the number of parameters supported for this layer.
Definition: CoreTypes.h:1428
std::size_t structSize
This is the sizeof() this struct.
Definition: CoreTypes.h:1366
Describes a single input terminal for a layer. LayerDesc objects contain arrays of this structure.
Definition: CoreTypes.h:1335
const char * pDocumentation
An optional human-readable descriptive text.
Definition: CoreTypes.h:1349
std::size_t structSize
This is the sizeof() this struct. It is used for versioning.
Definition: CoreTypes.h:1337
LayerInputType inputType
This is a enum that describes this input.
Definition: CoreTypes.h:1354
const char * pName
This is the optional name of the parameter, usually a friendly name.
Definition: CoreTypes.h:1343
ParamDesc describes a parameter for the plugin, giving it a name, default value, type,...
Definition: CoreTypes.h:1258
ParamType paramType
This is a enum that describes this parameter.
Definition: CoreTypes.h:1277
const BaseParamTypeDesc * pParamTypeDetails
This is an optional struct that give greater detail to the paramType if needed, for instance,...
Definition: CoreTypes.h:1289
std::size_t structSize
This is the sizeof() this struct. It is used for versioning.
Definition: CoreTypes.h:1260
const char * pName
This is the name of the parameter, usually a friendly name.
Definition: CoreTypes.h:1266
const char * pDefault
This is the default value of the parameter.
Definition: CoreTypes.h:1272
const char * pDocumentation
An optional human-readable descriptive text.
Definition: CoreTypes.h:1283
This structure represent a prototype layer version (backend, tensor format and kernel type),...
Definition: CoreTypes.h:1505
TensorFormat tensorFormat
This is the tensor format supported by this prototype layer.
Definition: CoreTypes.h:1534
const char * pSerializedName
This is the name used to represent the prototype type in serialized form.
Definition: CoreTypes.h:1521
NetworkBackendId backend
This is the backend identifier supported by this instance of the prototype layer.
Definition: CoreTypes.h:1531
std::size_t structSize
This is the sizeof() this struct.
Definition: CoreTypes.h:1509
CompilationLevel compilationLevel
This is the compilation level of the contained kernel.
Definition: CoreTypes.h:1537
const char * pObjectClass
This is the programmatic class name used to instantiate the prototype object through the IPlugin::cre...
Definition: CoreTypes.h:1515
const char * pDisplayName
An optional human-readable prototype name.
Definition: CoreTypes.h:1526
The StringParamTypeDesc further describes a parameter for the plugin and is pointed to from the highe...
Definition: CoreTypes.h:1245
bool supportsMultilineTextbox
This is a UI hint for the size of the text box of the string.
Definition: CoreTypes.h:1251
BaseParamTypeDesc baseDesc
This is the base param desc struct which all xParamTypeDesc must have.
Definition: CoreTypes.h:1247
TensorDimension describes the dimensions of a four-dimensional image tensor.
Definition: CoreTypes.h:134
size_t c
C dimension (channel)
Definition: CoreTypes.h:136
TensorDimension & operator=(const TensorDimension &copyFrom)
Copy assignment operator.
Definition: CoreTypes.h:165
bool operator!=(const TensorDimension &other) const
Inequality operator.
Definition: CoreTypes.h:181
size_t h
H dimension (height)
Definition: CoreTypes.h:137
~TensorDimension()=default
Trivial destructor.
TensorDimension()=default
Default constructor. Initializes all members to zero.
TensorDimension(size_t N, size_t C, size_t H, size_t W)
Direct constructor, specifying all members at once.
Definition: CoreTypes.h:144
size_t w
W dimension (width)
Definition: CoreTypes.h:138
bool operator==(const TensorDimension &other) const
Equality operator.
Definition: CoreTypes.h:175
TensorDimension(const TensorDimension &copyFrom)
Copy constructor.
Definition: CoreTypes.h:156
std::size_t elementCount() const
Returns the number of elements in a tensor with these dimensions.
Definition: CoreTypes.h:188
size_t n
N dimension (batch)
Definition: CoreTypes.h:135
TensorFormat describes a specific tensor shape (element type and layout).
Definition: CoreTypes.h:86
TensorDataLayout layout
Element layout (e.g., NCHW)
Definition: CoreTypes.h:88
bool operator<(const TensorFormat &other) const noexcept
Less-than operator for convenience.
Definition: CoreTypes.h:120
TensorFormat(TensorDataType elementType_, TensorDataLayout layout_)
Convenience constructor.
Definition: CoreTypes.h:98
bool operator!=(const TensorFormat &other) const noexcept
Inequality operator for convenience.
Definition: CoreTypes.h:105
bool operator==(const TensorFormat &other) const noexcept
Equality operator for convenience.
Definition: CoreTypes.h:112
TensorFormat()
Convenience default constructor. Sets everything to "invalid.".
Definition: CoreTypes.h:91
TensorDataType elementType
Element type (e.g., Float)
Definition: CoreTypes.h:87