TensorRT 10.0.0
NvOnnxParser.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1993-2023, NVIDIA CORPORATION. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23#ifndef NV_ONNX_PARSER_H
24#define NV_ONNX_PARSER_H
25
26#include "NvInfer.h"
27#include <stddef.h>
28#include <string>
29#include <vector>
30
36
37#define NV_ONNX_PARSER_MAJOR 0
38#define NV_ONNX_PARSER_MINOR 1
39#define NV_ONNX_PARSER_PATCH 0
40
41static constexpr int32_t NV_ONNX_PARSER_VERSION
43
50typedef std::pair<std::vector<size_t>, bool> SubGraph_t;
51
58typedef std::vector<SubGraph_t> SubGraphCollection_t;
59
65namespace nvonnxparser
66{
67
68template <typename T>
69constexpr inline int32_t EnumMax();
70
76enum class ErrorCode : int
77{
78 kSUCCESS = 0,
84 kINVALID_NODE = 6,
92 kREFIT_FAILED = 14
93};
94
100template <>
101constexpr inline int32_t EnumMax<ErrorCode>()
102{
103 return 14;
104}
105
112using OnnxParserFlags = uint32_t;
113
114enum class OnnxParserFlag : int32_t
115{
121};
122
128template <>
129constexpr inline int32_t EnumMax<OnnxParserFlag>()
130{
131 return 1;
132}
133
140{
141public:
145 virtual ErrorCode code() const = 0;
149 virtual char const* desc() const = 0;
153 virtual char const* file() const = 0;
157 virtual int line() const = 0;
161 virtual char const* func() const = 0;
165 virtual int node() const = 0;
169 virtual char const* nodeName() const = 0;
173 virtual char const* nodeOperator() const = 0;
179 virtual char const* const* localFunctionStack() const = 0;
183 // a stack size of 0.
185 virtual int32_t localFunctionStackSize() const = 0;
186
187protected:
188 virtual ~IParserError() {}
189};
190
197{
198public:
213 virtual bool parse(
214 void const* serialized_onnx_model, size_t serialized_onnx_model_size, const char* model_path = nullptr)
215 = 0;
216
227 virtual bool parseFromFile(const char* onnxModelFile, int verbosity) = 0;
228
241 virtual bool supportsModel(void const* serialized_onnx_model, size_t serialized_onnx_model_size,
242 SubGraphCollection_t& sub_graph_collection, const char* model_path = nullptr)
243 = 0;
244
255 virtual bool parseWithWeightDescriptors(void const* serialized_onnx_model, size_t serialized_onnx_model_size) = 0;
256
266 virtual bool supportsOperator(const char* op_name) const = 0;
267
274 virtual int getNbErrors() const = 0;
275
281 virtual IParserError const* getError(int index) const = 0;
282
288 virtual void clearErrors() = 0;
289
290 virtual ~IParser() noexcept = default;
291
308 virtual char const* const* getUsedVCPluginLibraries(int64_t& nbPluginLibs) const noexcept = 0;
309
321 virtual void setFlags(OnnxParserFlags onnxParserFlags) noexcept = 0;
322
330 virtual OnnxParserFlags getFlags() const noexcept = 0;
331
339 virtual void clearFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
340
348 virtual void setFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
349
357 virtual bool getFlag(OnnxParserFlag onnxParserFlag) const noexcept = 0;
358
371 virtual nvinfer1::ITensor const* getLayerOutputTensor(char const* name, int64_t i) = 0;
372};
373
380{
381public:
394 virtual bool refitFromBytes(
395 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept
396 = 0;
397
408 virtual bool refitFromFile(char const* onnxModelFile) noexcept = 0;
409
415 virtual int32_t getNbErrors() const noexcept = 0;
416
422 virtual IParserError const* getError(int32_t index) const noexcept = 0;
423
429 virtual void clearErrors() = 0;
430
431 virtual ~IParserRefitter() noexcept = default;
432};
433
434} // namespace nvonnxparser
435
436extern "C" TENSORRTAPI void* createNvOnnxParser_INTERNAL(void* network, void* logger, int version);
437extern "C" TENSORRTAPI void* createNvOnnxParserRefitter_INTERNAL(void* refitter, void* logger, int32_t version);
439
440namespace nvonnxparser
441{
442
443namespace
444{
445
462{
463 return static_cast<IParser*>(createNvOnnxParser_INTERNAL(&network, &logger, NV_ONNX_PARSER_VERSION));
464}
465
476{
477 return static_cast<IParserRefitter*>(
478 createNvOnnxParserRefitter_INTERNAL(&refitter, &logger, NV_ONNX_PARSER_VERSION));
479}
480
481} // namespace
482
483} // namespace nvonnxparser
484
485#endif // NV_ONNX_PARSER_H
#define TENSORRTAPI
Definition: NvInferRuntimeBase.h:59
std::vector< SubGraph_t > SubGraphCollection_t
The data structure containing all SubGraph_t partitioned out of an ONNX graph.
Definition: NvOnnxParser.h:58
TENSORRTAPI void * createNvOnnxParserRefitter_INTERNAL(void *refitter, void *logger, int32_t version)
#define NV_ONNX_PARSER_PATCH
Definition: NvOnnxParser.h:39
#define NV_ONNX_PARSER_MINOR
Definition: NvOnnxParser.h:38
TENSORRTAPI int getNvOnnxParserVersion()
std::pair< std::vector< size_t >, bool > SubGraph_t
The data structure containing the parsing capability of a set of nodes in an ONNX graph.
Definition: NvOnnxParser.h:50
#define NV_ONNX_PARSER_MAJOR
Definition: NvOnnxParser.h:37
TENSORRTAPI void * createNvOnnxParser_INTERNAL(void *network, void *logger, int version)
Application-implemented logging interface for the builder, refitter and runtime.
Definition: NvInferRuntimeBase.h:676
A network definition for input to the builder.
Definition: NvInfer.h:6184
Updates weights in an engine.
Definition: NvInferRuntime.h:1603
an object containing information about an error
Definition: NvOnnxParser.h:140
virtual char const * nodeOperator() const =0
name of the node operation in which the error occurred.
virtual char const * func() const =0
source function in which the error occurred.
virtual int line() const =0
source line at which the error occurred.
virtual char const * desc() const =0
description of the error.
virtual ~IParserError()
Definition: NvOnnxParser.h:188
virtual ErrorCode code() const =0
the error code.
virtual char const * nodeName() const =0
name of the node in which the error occurred.
virtual char const *const * localFunctionStack() const =0
A list of the local function names, from the top level down, constituting the current stack trace in ...
virtual int node() const =0
index of the ONNX model node in which the error occurred.
virtual char const * file() const =0
source file in which the error occurred.
virtual int32_t localFunctionStackSize() const =0
The size of the stack of local functions at the point where the error occurred. A top-level node that...
an object for parsing ONNX models into a TensorRT network definition
Definition: NvOnnxParser.h:197
virtual bool parseFromFile(const char *onnxModelFile, int verbosity)=0
Parse an onnx model file, which can be a binary protobuf or a text onnx model calls parse method insi...
virtual int getNbErrors() const =0
Get the number of errors that occurred during prior calls to parse.
virtual char const *const * getUsedVCPluginLibraries(int64_t &nbPluginLibs) const noexcept=0
Query the plugin libraries needed to implement operations used by the parser in a version-compatible ...
virtual IParserError const * getError(int index) const =0
Get an error that occurred during prior calls to parse.
virtual ~IParser() noexcept=default
virtual void clearErrors()=0
Clear errors from prior calls to parse.
virtual void setFlag(OnnxParserFlag onnxParserFlag) noexcept=0
Set a single parser flag.
virtual bool supportsOperator(const char *op_name) const =0
Returns whether the specified operator may be supported by the parser.
virtual bool parse(void const *serialized_onnx_model, size_t serialized_onnx_model_size, const char *model_path=nullptr)=0
Parse a serialized ONNX model into the TensorRT network. This method has very limited diagnostics....
virtual nvinfer1::ITensor const * getLayerOutputTensor(char const *name, int64_t i)=0
Return the i-th output ITensor object for the ONNX layer "name".
virtual bool getFlag(OnnxParserFlag onnxParserFlag) const noexcept=0
Returns true if the parser flag is set.
virtual void clearFlag(OnnxParserFlag onnxParserFlag) noexcept=0
clear a parser flag.
virtual OnnxParserFlags getFlags() const noexcept=0
Get the parser flags. Defaults to 0.
virtual bool supportsModel(void const *serialized_onnx_model, size_t serialized_onnx_model_size, SubGraphCollection_t &sub_graph_collection, const char *model_path=nullptr)=0
Check whether TensorRT supports a particular ONNX model. If the function returns True,...
virtual bool parseWithWeightDescriptors(void const *serialized_onnx_model, size_t serialized_onnx_model_size)=0
Parse a serialized ONNX model into the TensorRT network with consideration of user provided weights.
virtual void setFlags(OnnxParserFlags onnxParserFlags) noexcept=0
Set the parser flags.
An interface designed to refit weights from an ONNX model.
Definition: NvOnnxParser.h:380
virtual bool refitFromBytes(void const *serializedOnnxModel, size_t serializedOnnxModelSize, char const *modelPath=nullptr) noexcept=0
Load a serialized ONNX model from memory and perform weight refit.
The TensorRT API version 1 namespace.
IParserRefitter * createParserRefitter(nvinfer1::IRefitter &refitter, nvinfer1::ILogger &logger)
Create a new ONNX refitter object.
Definition: NvOnnxParser.h:475
IParser * createParser(nvinfer1::INetworkDefinition &network, nvinfer1::ILogger &logger)
Create a new parser object.
Definition: NvOnnxParser.h:461
The TensorRT ONNX parser API namespace.
Definition: NvOnnxConfig.h:24
uint32_t OnnxParserFlags
Represents one or more OnnxParserFlag values using binary OR operations, e.g., 1U << OnnxParserFlag::...
Definition: NvOnnxParser.h:112
constexpr int32_t EnumMax< OnnxParserFlag >()
Definition: NvOnnxParser.h:129
ErrorCode
The type of error that the parser or refitter may return.
Definition: NvOnnxParser.h:77
OnnxParserFlag
Definition: NvOnnxParser.h:115
constexpr int32_t EnumMax< ErrorCode >()
Definition: NvOnnxParser.h:101
constexpr int32_t EnumMax()

  Copyright © 2024 NVIDIA Corporation
  Privacy Policy | Manage My Privacy | Do Not Sell or Share My Data | Terms of Service | Accessibility | Corporate Policies | Product Security | Contact