TensorRT 8.6.1
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 <vector>
29
35
36#define NV_ONNX_PARSER_MAJOR 0
37#define NV_ONNX_PARSER_MINOR 1
38#define NV_ONNX_PARSER_PATCH 0
39
40static constexpr int32_t NV_ONNX_PARSER_VERSION
42
49typedef std::pair<std::vector<size_t>, bool> SubGraph_t;
50
57typedef std::vector<SubGraph_t> SubGraphCollection_t;
58
64namespace nvonnxparser
65{
66
67template <typename T>
68constexpr inline int32_t EnumMax();
69
75enum class ErrorCode : int
76{
77 kSUCCESS = 0,
83 kINVALID_NODE = 6,
86};
87
93template <>
94constexpr inline int32_t EnumMax<ErrorCode>()
95{
96 return 9;
97}
98
105using OnnxParserFlags = uint32_t;
106
107enum class OnnxParserFlag : int32_t
108{
114};
115
121template <>
122constexpr inline int32_t EnumMax<OnnxParserFlag>()
123{
124 return 1;
125}
126
133{
134public:
138 virtual ErrorCode code() const = 0;
142 virtual const char* desc() const = 0;
146 virtual const char* file() const = 0;
150 virtual int line() const = 0;
154 virtual const char* func() const = 0;
158 virtual int node() const = 0;
159
160protected:
161 virtual ~IParserError() {}
162};
163
170{
171public:
186 virtual bool parse(
187 void const* serialized_onnx_model, size_t serialized_onnx_model_size, const char* model_path = nullptr)
188 = 0;
189
200 virtual bool parseFromFile(const char* onnxModelFile, int verbosity) = 0;
201
214 virtual bool supportsModel(void const* serialized_onnx_model, size_t serialized_onnx_model_size,
215 SubGraphCollection_t& sub_graph_collection, const char* model_path = nullptr)
216 = 0;
217
228 virtual bool parseWithWeightDescriptors(void const* serialized_onnx_model, size_t serialized_onnx_model_size) = 0;
229
239 virtual bool supportsOperator(const char* op_name) const = 0;
240
246 TRT_DEPRECATED virtual void destroy() = 0;
247
254 virtual int getNbErrors() const = 0;
255
261 virtual IParserError const* getError(int index) const = 0;
262
268 virtual void clearErrors() = 0;
269
270 virtual ~IParser() noexcept = default;
271
288 virtual char const* const* getUsedVCPluginLibraries(int64_t& nbPluginLibs) const noexcept = 0;
289
301 virtual void setFlags(OnnxParserFlags onnxParserFlags) noexcept = 0;
302
310 virtual OnnxParserFlags getFlags() const noexcept = 0;
311
319 virtual void clearFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
320
328 virtual void setFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
329
337 virtual bool getFlag(OnnxParserFlag onnxParserFlag) const noexcept = 0;
338};
339
340} // namespace nvonnxparser
341
342extern "C" TENSORRTAPI void* createNvOnnxParser_INTERNAL(void* network, void* logger, int version);
344
345namespace nvonnxparser
346{
347
348namespace
349{
350
366inline IParser* createParser(nvinfer1::INetworkDefinition& network, nvinfer1::ILogger& logger)
367{
368 return static_cast<IParser*>(createNvOnnxParser_INTERNAL(&network, &logger, NV_ONNX_PARSER_VERSION));
369}
370
371} // namespace
372
373} // namespace nvonnxparser
374
375#endif // NV_ONNX_PARSER_H
#define TENSORRTAPI
Definition: NvInferRuntimeBase.h:54
#define TRT_DEPRECATED
Definition: NvInferRuntimeBase.h:40
std::vector< SubGraph_t > SubGraphCollection_t
The data structure containing all SubGraph_t partitioned out of an ONNX graph.
Definition: NvOnnxParser.h:57
#define NV_ONNX_PARSER_PATCH
Definition: NvOnnxParser.h:38
#define NV_ONNX_PARSER_MINOR
Definition: NvOnnxParser.h:37
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:49
#define NV_ONNX_PARSER_MAJOR
Definition: NvOnnxParser.h:36
TENSORRTAPI void * createNvOnnxParser_INTERNAL(void *network, void *logger, int version)
Application-implemented logging interface for the builder, refitter and runtime.
Definition: NvInferRuntimeBase.h:505
A network definition for input to the builder.
Definition: NvInfer.h:6863
an object containing information about an error
Definition: NvOnnxParser.h:133
virtual int line() const =0
source line at which the error occurred
virtual ~IParserError()
Definition: NvOnnxParser.h:161
virtual ErrorCode code() const =0
the error code
virtual const char * file() const =0
source file in which the error occurred
virtual const char * desc() const =0
description of the error
virtual int node() const =0
index of the ONNX model node in which the error occurred
virtual const char * func() const =0
source function in which the error occurred
an object for parsing ONNX models into a TensorRT network definition
Definition: NvOnnxParser.h:170
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 TRT_DEPRECATED void destroy()=0
destroy this object
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 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.
The TensorRT ONNX parser API namespace.
Definition: NvOnnxConfig.h:19
uint32_t OnnxParserFlags
Represents one or more OnnxParserFlag values using binary OR operations, e.g., 1U << OnnxParserFlag::...
Definition: NvOnnxParser.h:105
constexpr int32_t EnumMax< OnnxParserFlag >()
Definition: NvOnnxParser.h:122
ErrorCode
The type of error that the parser may return.
Definition: NvOnnxParser.h:76
OnnxParserFlag
Definition: NvOnnxParser.h:108
constexpr int32_t EnumMax< ErrorCode >()
Definition: NvOnnxParser.h:94
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