TensorRT 8.2.5
NvOnnxParser.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021, 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 const int NV_ONNX_PARSER_VERSION = ((NV_ONNX_PARSER_MAJOR * 10000) + (NV_ONNX_PARSER_MINOR * 100) + NV_ONNX_PARSER_PATCH);
41
47typedef std::pair<std::vector<size_t>, bool> SubGraph_t;
48
54typedef std::vector<SubGraph_t> SubGraphCollection_t;
55
61namespace nvonnxparser
62{
63
64template <typename T>
65inline int32_t EnumMax();
66
71enum class ErrorCode : int
72{
73 kSUCCESS = 0,
74 kINTERNAL_ERROR = 1,
75 kMEM_ALLOC_FAILED = 2,
76 kMODEL_DESERIALIZE_FAILED = 3,
77 kINVALID_VALUE = 4,
78 kINVALID_GRAPH = 5,
79 kINVALID_NODE = 6,
80 kUNSUPPORTED_GRAPH = 7,
81 kUNSUPPORTED_NODE = 8
82};
83
84template <>
85inline int32_t EnumMax<ErrorCode>()
86{
87 return 9;
88}
89
95{
96public:
99 virtual ErrorCode code() const = 0;
102 virtual const char* desc() const = 0;
105 virtual const char* file() const = 0;
108 virtual int line() const = 0;
111 virtual const char* func() const = 0;
114 virtual int node() const = 0;
115
116protected:
117 virtual ~IParserError() {}
118};
119
125{
126public:
140 virtual bool parse(void const* serialized_onnx_model,
141 size_t serialized_onnx_model_size,
142 const char* model_path = nullptr)
143 = 0;
144
154 virtual bool parseFromFile(const char* onnxModelFile, int verbosity) = 0;
155
165 virtual bool supportsModel(void const* serialized_onnx_model,
166 size_t serialized_onnx_model_size,
167 SubGraphCollection_t& sub_graph_collection,
168 const char* model_path = nullptr)
169 = 0;
170
181 void const* serialized_onnx_model, size_t serialized_onnx_model_size)
182 = 0;
183
192 virtual bool supportsOperator(const char* op_name) const = 0;
197 TRT_DEPRECATED virtual void destroy() = 0;
203 virtual int getNbErrors() const = 0;
208 virtual IParserError const* getError(int index) const = 0;
213 virtual void clearErrors() = 0;
214
215 virtual ~IParser() noexcept = default;
216};
217
218} // namespace nvonnxparser
219
220extern "C" TENSORRTAPI void* createNvOnnxParser_INTERNAL(void* network, void* logger, int version);
221extern "C" TENSORRTAPI int getNvOnnxParserVersion();
222
223namespace nvonnxparser
224{
225
226namespace
227{
228
243{
244 return static_cast<IParser*>(createNvOnnxParser_INTERNAL(&network, &logger, NV_ONNX_PARSER_VERSION));
245}
246
247} // namespace
248
249} // namespace nvonnxparser
250
251#endif // NV_ONNX_PARSER_H
#define TRT_DEPRECATED
< Items that are marked as deprecated will be removed in a future release.
Definition: NvInferRuntimeCommon.h:77
std::vector< SubGraph_t > SubGraphCollection_t
The data structure containing all SubGraph_t partitioned out of an ONNX graph.
Definition: NvOnnxParser.h:54
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:47
Application-implemented logging interface for the builder, refitter and runtime.
Definition: NvInferRuntimeCommon.h:1506
A network definition for input to the builder.
Definition: NvInfer.h:6030
an object containing information about an error
Definition: NvOnnxParser.h:95
virtual int line() const =0
source line at which the error occurred
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:125
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 IParserError const * getError(int index) const =0
Get an error that occurred during prior calls to parse.
virtual void clearErrors()=0
Clear errors from prior calls to parse.
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 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.
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.
IParser * createParser(nvinfer1::INetworkDefinition &network, nvinfer1::ILogger &logger)
Create a new parser object.
Definition: NvOnnxParser.h:242
The TensorRT ONNX parser API namespace.
Definition: NvOnnxConfig.h:56
ErrorCode
the type of parser error
Definition: NvOnnxParser.h:72

  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