TensorRT 10.11.0
NvOnnxParser.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1993-2024, 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#if !TRT_WINML
29#include <string>
30#include <vector>
31#endif // !TRT_WINML
32
38
39#define NV_ONNX_PARSER_MAJOR 0
40#define NV_ONNX_PARSER_MINOR 1
41#define NV_ONNX_PARSER_PATCH 0
42
43static constexpr int32_t NV_ONNX_PARSER_VERSION
45
46#if !TRT_WINML
53typedef std::pair<std::vector<size_t>, bool> SubGraph_t;
54
61typedef std::vector<SubGraph_t> SubGraphCollection_t;
62
63#endif // !TRT_WINML
69namespace nvonnxparser
70{
71
72template <typename T>
73constexpr inline int32_t EnumMax() noexcept;
74
80enum class ErrorCode : int
81{
82 kSUCCESS = 0,
83 kINTERNAL_ERROR = 1,
88 kINVALID_NODE = 6,
96 kREFIT_FAILED = 14
97};
98
104template <>
105constexpr inline int32_t EnumMax<ErrorCode>() noexcept
106{
107 return 14;
108}
109
116using OnnxParserFlags = uint32_t;
117
118enum class OnnxParserFlag : int32_t
119{
129};
130
136template <>
137constexpr inline int32_t EnumMax<OnnxParserFlag>() noexcept
138{
139 return 2;
140}
141
148{
149public:
153 virtual ErrorCode code() const = 0;
157 virtual char const* desc() const = 0;
161 virtual char const* file() const = 0;
165 virtual int line() const = 0;
169 virtual char const* func() const = 0;
173 virtual int node() const = 0;
177 virtual char const* nodeName() const = 0;
181 virtual char const* nodeOperator() const = 0;
187 virtual char const* const* localFunctionStack() const = 0;
191 // a stack size of 0.
193 virtual int32_t localFunctionStackSize() const = 0;
194
195protected:
196 virtual ~IParserError() {}
197};
198
210{
211public:
226 virtual bool parse(
227 void const* serialized_onnx_model, size_t serialized_onnx_model_size, const char* model_path = nullptr) noexcept
228 = 0;
229
240 virtual bool parseFromFile(const char* onnxModelFile, int verbosity) noexcept = 0;
241
242#if !TRT_WINML
257 TRT_DEPRECATED virtual bool supportsModel(void const* serialized_onnx_model, size_t serialized_onnx_model_size,
258 SubGraphCollection_t& sub_graph_collection, const char* model_path = nullptr) noexcept = 0;
259
260#endif // !TRT_WINML
270 virtual bool parseWithWeightDescriptors(
271 void const* serialized_onnx_model, size_t serialized_onnx_model_size) noexcept
272 = 0;
273
283 virtual bool supportsOperator(const char* op_name) const noexcept = 0;
284
291 virtual int getNbErrors() const noexcept = 0;
292
298 virtual IParserError const* getError(int index) const noexcept = 0;
299
305 virtual void clearErrors() noexcept = 0;
306
307 virtual ~IParser() noexcept = default;
308
325 virtual char const* const* getUsedVCPluginLibraries(int64_t& nbPluginLibs) const noexcept = 0;
326
338 virtual void setFlags(OnnxParserFlags onnxParserFlags) noexcept = 0;
339
347 virtual OnnxParserFlags getFlags() const noexcept = 0;
348
356 virtual void clearFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
357
365 virtual void setFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
366
374 virtual bool getFlag(OnnxParserFlag onnxParserFlag) const noexcept = 0;
375
388 virtual nvinfer1::ITensor const* getLayerOutputTensor(char const* name, int64_t i) noexcept = 0;
389
402 virtual bool supportsModelV2(
403 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept = 0;
404
412 virtual int64_t getNbSubgraphs() noexcept = 0;
413
422 virtual bool isSubgraphSupported(int64_t const index) noexcept = 0;
423
434 virtual int64_t* getSubgraphNodes(int64_t const index, int64_t& subgraphLength) noexcept = 0;
435};
436
445{
446public:
459 virtual bool refitFromBytes(
460 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept
461 = 0;
462
473 virtual bool refitFromFile(char const* onnxModelFile) noexcept = 0;
474
480 virtual int32_t getNbErrors() const noexcept = 0;
481
487 virtual IParserError const* getError(int32_t index) const noexcept = 0;
488
494 virtual void clearErrors() = 0;
495
496 virtual ~IParserRefitter() noexcept = default;
497};
498
499} // namespace nvonnxparser
500
501extern "C" TENSORRTAPI void* createNvOnnxParser_INTERNAL(void* network, void* logger, int version) noexcept;
503 void* refitter, void* logger, int32_t version) noexcept;
504extern "C" TENSORRTAPI int getNvOnnxParserVersion() noexcept;
505
506namespace nvonnxparser
507{
508
509namespace
510{
511
528{
529 return static_cast<IParser*>(createNvOnnxParser_INTERNAL(&network, &logger, NV_ONNX_PARSER_VERSION));
530}
531
542{
543 return static_cast<IParserRefitter*>(
544 createNvOnnxParserRefitter_INTERNAL(&refitter, &logger, NV_ONNX_PARSER_VERSION));
545}
546
547} // namespace
548
549} // namespace nvonnxparser
550
551#endif // NV_ONNX_PARSER_H
#define TENSORRTAPI
Definition: NvInferRuntimeBase.h:69
#define TRT_DEPRECATED
Definition: NvInferRuntimeBase.h:42
TENSORRTAPI void * createNvOnnxParserRefitter_INTERNAL(void *refitter, void *logger, int32_t version) noexcept
std::vector< SubGraph_t > SubGraphCollection_t
The data structure containing all SubGraph_t partitioned out of an ONNX graph.
Definition: NvOnnxParser.h:61
TENSORRTAPI void * createNvOnnxParser_INTERNAL(void *network, void *logger, int version) noexcept
TENSORRTAPI int getNvOnnxParserVersion() noexcept
#define NV_ONNX_PARSER_PATCH
Definition: NvOnnxParser.h:41
#define NV_ONNX_PARSER_MINOR
Definition: NvOnnxParser.h:40
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:53
#define NV_ONNX_PARSER_MAJOR
Definition: NvOnnxParser.h:39
Application-implemented logging interface for the builder, refitter and runtime.
Definition: NvInferRuntime.h:1542
A network definition for input to the builder.
Definition: NvInfer.h:6673
Updates weights in an engine.
Definition: NvInferRuntime.h:2138
an object containing information about an error
Definition: NvOnnxParser.h:148
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:196
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:210
virtual bool supportsOperator(const char *op_name) const noexcept=0
Returns whether the specified operator may be supported by the parser.
virtual TRT_DEPRECATED bool supportsModel(void const *serialized_onnx_model, size_t serialized_onnx_model_size, SubGraphCollection_t &sub_graph_collection, const char *model_path=nullptr) noexcept=0
Check whether TensorRT supports a particular ONNX model. If the function returns True,...
virtual bool parse(void const *serialized_onnx_model, size_t serialized_onnx_model_size, const char *model_path=nullptr) noexcept=0
Parse a serialized ONNX model into the TensorRT network. This method has very limited diagnostics....
virtual int getNbErrors() const noexcept=0
Get the number of errors that occurred during prior calls to parse.
An interface designed to refit weights from an ONNX model.
Definition: NvOnnxParser.h:445
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.
IParser * createParser(nvinfer1::INetworkDefinition &network, nvinfer1::ILogger &logger) noexcept
Create a new parser object.
Definition: NvOnnxParser.h:527
IParserRefitter * createParserRefitter(nvinfer1::IRefitter &refitter, nvinfer1::ILogger &logger) noexcept
Create a new ONNX refitter object.
Definition: NvOnnxParser.h:541
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:116
constexpr int32_t EnumMax() noexcept
ErrorCode
The type of error that the parser or refitter may return.
Definition: NvOnnxParser.h:81
OnnxParserFlag
Definition: NvOnnxParser.h:119
constexpr int32_t EnumMax< ErrorCode >() noexcept
Definition: NvOnnxParser.h:105
constexpr int32_t EnumMax< OnnxParserFlag >() noexcept
Definition: NvOnnxParser.h:137

  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