NVIDIA NvNeural SDK  2022.2
GPU inference framework for NVIDIA Nsight Deep Learning Designer
OnnxTypes.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_ONNXTYPES_H
26 #define NVNEURAL_ONNXTYPES_H
27 
28 #include <nvneural/CoreTypes.h>
29 
30 namespace nvneural {
31 
35 enum class OnnxTensorDataType : std::int32_t
36 {
37  Undefined = 0,
38  Float = 1,
39  Uint8 = 2,
40  Int8 = 3,
41  Uint16 = 4,
42  Int16 = 5,
43  Int32 = 6,
44  Int64 = 7,
45  String = 8,
46  Bool = 9,
47  Float16 = 10,
48  Double = 11,
49  Uint32 = 12,
50  Uint64 = 13,
51  Complex64 = 14,
52  Complex128 = 15,
53  Bfloat16 = 16,
54 };
55 
58 {
59 public:
61  static const IRefObject::TypeId typeID = 0x759f0395a35632cful;
62 
64  virtual NeuralResult setName(const char* pName) noexcept = 0;
65 
71  virtual NeuralResult setDocString(const char* pDocString) noexcept = 0;
72 
81 
85  virtual NeuralResult assignFloat(float value) noexcept = 0;
86 
90  virtual NeuralResult assignInteger(std::int64_t value) noexcept = 0;
91 
95  virtual NeuralResult assignString(const char* pBuffer) noexcept = 0;
96 
101  virtual NeuralResult assignBytes(const char* pBuffer, size_t bufferBytes) noexcept = 0;
102 
104 
114 
118  virtual NeuralResult pushFloat(float value) noexcept = 0;
119 
123  virtual NeuralResult pushInteger(int64_t value) noexcept = 0;
124 
128  virtual NeuralResult pushString(const char* pBuffer) noexcept = 0;
129 
134  virtual NeuralResult pushString(const char* pBuffer, size_t bufferBytes) noexcept = 0;
135 
137 };
138 
141 {
142 public:
144  static const IRefObject::TypeId typeID = 0x9e2ed4d9912fa1aeul;
145 
152  virtual NeuralResult addInput(const char* pName) noexcept = 0;
153 
163  virtual NeuralResult addOutput(const char* pName) noexcept = 0;
164 
168  virtual NeuralResult setName(const char* pName) noexcept = 0;
169 
175  virtual NeuralResult setOperatorType(const char* pOpType) noexcept = 0;
176 
182  virtual NeuralResult setOperatorSetDomain(const char* pDomain) noexcept = 0;
183 
187  virtual NeuralResult createAttribute(IOnnxGenerationGraphAttribute** ppAttrOut) noexcept = 0;
188 
194  virtual NeuralResult setDocString(const char* pDocString) noexcept = 0;
195 };
196 
199 {
200 public:
202  static const IRefObject::TypeId typeID = 0xde33951dcbbaafc7ul;
203 
211  virtual NeuralResult addGraphInput(const char* pInputName, bool fp16Eligible) noexcept = 0;
212 
218  virtual NeuralResult addGraphInput(const char* pInputName, bool fp16Eligible, TensorDimension tensorDim) noexcept = 0;
219 
230  virtual NeuralResult addGraphOutput(const char* pOutputName, bool fp16Eligible) noexcept = 0;
231 
237  virtual NeuralResult addGraphOutput(const char* pOutputName, bool fp16Eligible, TensorDimension tensorDim) noexcept = 0;
238 
248  virtual NeuralResult addWeightsConstant(const char* pInitializerName, const IWeightsData* pWeightsData, bool fp16Eligible, const std::int64_t* pTensorDims, std::size_t numTensorDims) noexcept = 0;
249 
253  virtual NeuralResult addWeightsConstant(const char* pInitializerName, const IWeightsData* pWeightsData, bool fp16Eligible) noexcept = 0;
254 
267  virtual NeuralResult addGraphInitializer(const char* pInitializerName, OnnxTensorDataType dataType, bool fp16Eligible, TensorDimension tensorSize, const void* pTensorData, std::size_t tensorDataBytes) noexcept = 0;
268 
278  virtual NeuralResult addGraphInitializer(const char* pInitializerName, OnnxTensorDataType dataType, bool fp16Eligible, const std::int64_t* pTensorDims, std::size_t numTensorDims, const void* pTensorData, std::size_t tensorDataBytes) noexcept = 0;
279 
283  virtual NeuralResult createGraphNode(IOnnxGenerationGraphNode** ppNodeOut) noexcept = 0;
284 
295  virtual NeuralResult setLayerOutputName(const ILayer* pLayer, const char* pOutputName) noexcept = 0;
296 
304  virtual const char* getLayerOutputName(const ILayer* pLayer) const noexcept = 0;
305 
314  virtual NeuralResult importOperatorSet(const char* pDomain, std::int64_t version) noexcept = 0;
315 
326  virtual bool shouldUseExplicitTensorSizes() const noexcept = 0;
327 
337  virtual bool automaticFp16ConversionEnabled() const noexcept = 0;
338 
346  virtual bool placeholdersEnabled() const noexcept = 0;
347 };
348 
354 {
355 public:
357  static const IRefObject::TypeId typeID = 0x3846c67a6509ae19ul;
358 
372  virtual NeuralResult generateLayerOnnx(IOnnxGenerationHost* pOnnxHost) const noexcept = 0;
373 };
374 
380 {
381 public:
383  static const IRefObject::TypeId typeID = 0x5cb7974e7d598a97ul;
384 
394  virtual NeuralResult generateActivationOnnx(IOnnxGenerationHost* pOnnxHost, const ILayer* pLayer) const noexcept = 0;
395 };
396 
397 } // namespace nvneural
398 
399 #endif // NVNEURAL_ONNXTYPES_H
Fundamental NvNeural data types are declared here.
@ Float
32-bit floating point elements (float)
NeuralResult
NeuralResult is a generic success/failure result type similar to COM HRESULT.
Definition: CoreTypes.h:275
OnnxTensorDataType
Enum class wrapping ONNX TensorProto.DataType.
Definition: OnnxTypes.h:36
@ Uint32
32-bit unsigned integer (uint32_t, unsigned int)
@ Uint16
16-bit unsigned integer (uint16_t)
@ Int16
16-bit signed integer (int16_t)
@ Uint8
8-bit unsigned integer (uint8_t)
@ Int8
8-bit signed integer (int8_t)
@ Int32
32-bit signed integer (int32_t, int)
@ Uint64
64-bit unsigned integer (uint64_t, unsigned long long, size_t)
@ Double
64-bit floating point (double)
@ Complex64
Pair of 32-bit floating point values representing real/imaginary.
@ Complex128
Pair of 64-bit floating point values representing real/imaginary.
@ Int64
64-bit signed integer (int64_t, long long)
@ Bfloat16
Non-IEEE 16-bit floating-point (1 sign, 8 exponent, 7 mantissa)
Float16 is a CPU-side implementation of half-precision floating point (aka FP16).
Definition: CoreTypes.h:201
ILayer is the base class for neural network layers.
Definition: LayerTypes.h:59
ONNX export interface for IActivationFunction.
Definition: OnnxTypes.h:380
virtual NeuralResult generateActivationOnnx(IOnnxGenerationHost *pOnnxHost, const ILayer *pLayer) const noexcept=0
Generates ONNX operators for this activation function.
Tool-provided interface representing an AttributeProto in an ONNX graph node.
Definition: OnnxTypes.h:58
virtual NeuralResult assignInteger(std::int64_t value) noexcept=0
Assigns a scalar value of type INT.
virtual NeuralResult pushInteger(int64_t value) noexcept=0
Appends to a vector of type INTS.
virtual NeuralResult assignBytes(const char *pBuffer, size_t bufferBytes) noexcept=0
Assigns a scalar value of type STRING.
virtual NeuralResult setDocString(const char *pDocString) noexcept=0
Assigns a human-readable documentation string to the node.
static const IRefObject::TypeId typeID
Interface TypeId for InterfaceOf purposes.
Definition: OnnxTypes.h:61
virtual NeuralResult assignString(const char *pBuffer) noexcept=0
Assigns a scalar value of type STRING.
virtual NeuralResult pushString(const char *pBuffer) noexcept=0
Appends to a vector of type STRINGS.
virtual NeuralResult assignFloat(float value) noexcept=0
Assigns a scalar value of type FLOAT.
virtual NeuralResult pushString(const char *pBuffer, size_t bufferBytes) noexcept=0
Appends to a vector of type STRINGS.
virtual NeuralResult pushFloat(float value) noexcept=0
Appends to a vector of type FLOATS.
virtual NeuralResult setName(const char *pName) noexcept=0
Sets the name of this attribute.
Tool-provided interface representing a NodeProto in an ONNX graph.
Definition: OnnxTypes.h:141
virtual NeuralResult setDocString(const char *pDocString) noexcept=0
Assigns a human-readable documentation string to the node.
virtual NeuralResult setName(const char *pName) noexcept=0
Sets the name of the node.
virtual NeuralResult setOperatorSetDomain(const char *pDomain) noexcept=0
Sets the operator set domain used by this node.
virtual NeuralResult createAttribute(IOnnxGenerationGraphAttribute **ppAttrOut) noexcept=0
Creates a new attribute for this node and returns it.
static const IRefObject::TypeId typeID
Interface TypeId for InterfaceOf purposes.
Definition: OnnxTypes.h:144
virtual NeuralResult setOperatorType(const char *pOpType) noexcept=0
Sets the operator type of the node.
virtual NeuralResult addInput(const char *pName) noexcept=0
Adds an input reference to the node.
virtual NeuralResult addOutput(const char *pName) noexcept=0
Adds an output reference to the node.
Tool-provided interface for creating ONNX model graphs in an ABI-stable fashion.
Definition: OnnxTypes.h:199
virtual NeuralResult setLayerOutputName(const ILayer *pLayer, const char *pOutputName) noexcept=0
Sets the "output name" associated with a layer.
virtual bool automaticFp16ConversionEnabled() const noexcept=0
Returns true if automatic fp16 conversion is enabled.
virtual NeuralResult addGraphOutput(const char *pOutputName, bool fp16Eligible, TensorDimension tensorDim) noexcept=0
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual NeuralResult addGraphOutput(const char *pOutputName, bool fp16Eligible) noexcept=0
Adds a new graph output.
virtual NeuralResult addGraphInitializer(const char *pInitializerName, OnnxTensorDataType dataType, bool fp16Eligible, TensorDimension tensorSize, const void *pTensorData, std::size_t tensorDataBytes) noexcept=0
Adds a tensor as a named graph initializer.
virtual NeuralResult addGraphInput(const char *pInputName, bool fp16Eligible) noexcept=0
Adds a new graph input.
virtual NeuralResult importOperatorSet(const char *pDomain, std::int64_t version) noexcept=0
Adds a versioned operator set to the graph's import list.
virtual NeuralResult addWeightsConstant(const char *pInitializerName, const IWeightsData *pWeightsData, bool fp16Eligible) noexcept=0
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual NeuralResult addWeightsConstant(const char *pInitializerName, const IWeightsData *pWeightsData, bool fp16Eligible, const std::int64_t *pTensorDims, std::size_t numTensorDims) noexcept=0
Adds weights data as a named graph initializer.
virtual NeuralResult createGraphNode(IOnnxGenerationGraphNode **ppNodeOut) noexcept=0
Creates a new graph node (GraphProto.node) and returns a pointer to it.
static const IRefObject::TypeId typeID
Interface TypeId for InterfaceOf purposes.
Definition: OnnxTypes.h:202
virtual NeuralResult addGraphInput(const char *pInputName, bool fp16Eligible, TensorDimension tensorDim) noexcept=0
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual const char * getLayerOutputName(const ILayer *pLayer) const noexcept=0
Returns the "output name" associated with a layer.
virtual NeuralResult addGraphInitializer(const char *pInitializerName, OnnxTensorDataType dataType, bool fp16Eligible, const std::int64_t *pTensorDims, std::size_t numTensorDims, const void *pTensorData, std::size_t tensorDataBytes) noexcept=0
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual bool shouldUseExplicitTensorSizes() const noexcept=0
Returns true if graph inputs and outputs should be sized explicitly.
virtual bool placeholdersEnabled() const noexcept=0
Returns true if placeholder operators are permitted.
ONNX export interface for ILayer.
Definition: OnnxTypes.h:354
virtual NeuralResult generateLayerOnnx(IOnnxGenerationHost *pOnnxHost) const noexcept=0
Generates ONNX operators for this layer.
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
IWeightsData represents a binary buffer provided by IWeightsLoader.
Definition: CoreTypes.h:494
TensorDimension describes the dimensions of a four-dimensional image tensor.
Definition: CoreTypes.h:136