TensorRT for RTX 1.3.0
NvOnnxParser.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 1993-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef NV_ONNX_PARSER_H
19#define NV_ONNX_PARSER_H
20
21#include "NvInfer.h"
22#include <stddef.h>
23#include <string>
24#include <vector>
25
31
32#define NV_ONNX_PARSER_MAJOR 0
33#define NV_ONNX_PARSER_MINOR 1
34#define NV_ONNX_PARSER_PATCH 0
35
36static constexpr int32_t NV_ONNX_PARSER_VERSION
38
45typedef std::pair<std::vector<size_t>, bool> SubGraph_t;
46
53typedef std::vector<SubGraph_t> SubGraphCollection_t;
54
60namespace nvonnxparser
61{
62
63template <typename T>
64constexpr inline int32_t EnumMax() noexcept;
65
71enum class ErrorCode : int
72{
73 kSUCCESS = 0,
74 kINTERNAL_ERROR = 1,
79 kINVALID_NODE = 6,
87 kREFIT_FAILED = 14
88};
89
95template <>
96constexpr inline int32_t EnumMax<ErrorCode>() noexcept
97{
98 return 14;
99}
100
107using OnnxParserFlags = uint32_t;
108
109enum class OnnxParserFlag : int32_t
110{
123 // This flag is set to be OFF by default.
130};
131
137template <>
138constexpr inline int32_t EnumMax<OnnxParserFlag>() noexcept
139{
140 return 3;
141}
142
149{
150public:
154 virtual ErrorCode code() const = 0;
158 virtual char const* desc() const = 0;
162 virtual char const* file() const = 0;
166 virtual int line() const = 0;
170 virtual char const* func() const = 0;
174 virtual int node() const = 0;
178 virtual char const* nodeName() const = 0;
182 virtual char const* nodeOperator() const = 0;
188 virtual char const* const* localFunctionStack() const = 0;
192 // a stack size of 0.
194 virtual int32_t localFunctionStackSize() const = 0;
195
196protected:
197 virtual ~IParserError() {}
198};
199
211{
212public:
227 virtual bool parse(
228 void const* serialized_onnx_model, size_t serialized_onnx_model_size, const char* model_path = nullptr) noexcept
229 = 0;
230
241 virtual bool parseFromFile(const char* onnxModelFile, int verbosity) noexcept = 0;
242
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
273 void const* serialized_onnx_model, size_t serialized_onnx_model_size) noexcept = 0;
274
284 virtual bool supportsOperator(const char* op_name) const noexcept = 0;
285
292 virtual int getNbErrors() const noexcept = 0;
293
299 virtual IParserError const* getError(int index) const noexcept = 0;
300
306 virtual void clearErrors() noexcept = 0;
307
308 virtual ~IParser() noexcept = default;
309
326 virtual char const* const* getUsedVCPluginLibraries(int64_t& nbPluginLibs) const noexcept = 0;
327
339 virtual void setFlags(OnnxParserFlags onnxParserFlags) noexcept = 0;
340
348 virtual OnnxParserFlags getFlags() const noexcept = 0;
349
357 virtual void clearFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
358
366 virtual void setFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
367
375 virtual bool getFlag(OnnxParserFlag onnxParserFlag) const noexcept = 0;
376
389 virtual nvinfer1::ITensor const* getLayerOutputTensor(char const* name, int64_t i) noexcept = 0;
390
403 virtual bool supportsModelV2(
404 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept = 0;
405
413 virtual int64_t getNbSubgraphs() noexcept = 0;
414
423 virtual bool isSubgraphSupported(int64_t const index) noexcept = 0;
424
435 virtual int64_t* getSubgraphNodes(int64_t const index, int64_t& subgraphLength) noexcept = 0;
436
453 virtual bool loadModelProto(
454 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept = 0;
455
478 virtual bool loadInitializer(char const* name, void const* data, size_t size) noexcept = 0;
479
485 virtual bool parseModelProto() noexcept = 0;
486
492 virtual bool setBuilderConfig(const nvinfer1::IBuilderConfig* const builderConfig) noexcept = 0;
493};
494
503{
504public:
517 virtual bool refitFromBytes(
518 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept
519 = 0;
520
531 virtual bool refitFromFile(char const* onnxModelFile) noexcept = 0;
532
538 virtual int32_t getNbErrors() const noexcept = 0;
539
545 virtual IParserError const* getError(int32_t index) const noexcept = 0;
546
552 virtual void clearErrors() = 0;
553
554 virtual ~IParserRefitter() noexcept = default;
555
571 virtual bool loadModelProto(
572 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept = 0;
573
595 virtual bool loadInitializer(char const* name, void const* data, size_t size) noexcept = 0;
596
602 virtual bool refitModelProto() noexcept = 0;
603};
604
605} // namespace nvonnxparser
606
607extern "C" TENSORRTAPI void* createNvOnnxParser_INTERNAL(void* network, void* logger, int version) noexcept;
609 void* refitter, void* logger, int32_t version) noexcept;
610extern "C" TENSORRTAPI int getNvOnnxParserVersion() noexcept;
611
612namespace nvonnxparser
613{
614
615namespace
616{
617
634{
635 return static_cast<IParser*>(createNvOnnxParser_INTERNAL(&network, &logger, NV_ONNX_PARSER_VERSION));
636}
637
648{
649 return static_cast<IParserRefitter*>(
650 createNvOnnxParserRefitter_INTERNAL(&refitter, &logger, NV_ONNX_PARSER_VERSION));
651}
652
653} // namespace
654
655} // namespace nvonnxparser
656
657#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:53
TENSORRTAPI void * createNvOnnxParser_INTERNAL(void *network, void *logger, int version) noexcept
TENSORRTAPI int getNvOnnxParserVersion() noexcept
#define NV_ONNX_PARSER_PATCH
Definition: NvOnnxParser.h:34
#define NV_ONNX_PARSER_MINOR
Definition: NvOnnxParser.h:33
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:45
#define NV_ONNX_PARSER_MAJOR
Definition: NvOnnxParser.h:32
Application-implemented logging interface for the builder, refitter and runtime.
Definition: NvInferRuntime.h:1588
A network definition for input to the builder.
Definition: NvInfer.h:7344
Updates weights in an engine.
Definition: NvInferRuntime.h:2264
an object containing information about an error
Definition: NvOnnxParser.h:149
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:197
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:211
virtual IParserError const * getError(int index) const noexcept=0
Get an error 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 void setFlag(OnnxParserFlag onnxParserFlag) noexcept=0
Set a single parser flag.
virtual bool loadInitializer(char const *name, void const *data, size_t size) noexcept=0
Prompt the ONNX parser to load an initializer with user-provided binary data. The lifetime of the dat...
virtual bool supportsOperator(const char *op_name) const noexcept=0
Returns whether the specified operator may be supported by the parser.
virtual bool parseModelProto() noexcept=0
Begin the parsing and conversion process of the loaded ONNX model into a TensorRT INetworkDefinition.
virtual bool supportsModelV2(void const *serializedOnnxModel, size_t serializedOnnxModelSize, char const *modelPath=nullptr) noexcept=0
Check whether TensorRT supports a particular ONNX model. If the function returns True,...
virtual void clearErrors() noexcept=0
Clear errors from prior calls to parse.
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 TRT_DEPRECATED bool parseWithWeightDescriptors(void const *serialized_onnx_model, size_t serialized_onnx_model_size) noexcept=0
Parse a serialized ONNX model into the TensorRT network with consideration of user provided weights.
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 parseFromFile(const char *onnxModelFile, int verbosity) noexcept=0
Parse an onnx model file, which can be a binary protobuf or a text onnx model calls parse method insi...
virtual bool isSubgraphSupported(int64_t const index) noexcept=0
Returns whether the subgraph is supported. Calling this function before calling supportsModelV2 resul...
virtual int64_t getNbSubgraphs() noexcept=0
Get the number of subgraphs. Calling this function before calling supportsModelV2 results in undefine...
virtual bool loadModelProto(void const *serializedOnnxModel, size_t serializedOnnxModelSize, char const *modelPath=nullptr) noexcept=0
Load a serialized ONNX model into the parser. Unlike the parse(), parseFromFile(),...
virtual int64_t * getSubgraphNodes(int64_t const index, int64_t &subgraphLength) noexcept=0
Get the nodes of the specified subgraph. Calling this function before calling supportsModelV2 results...
virtual bool setBuilderConfig(const nvinfer1::IBuilderConfig *const builderConfig) noexcept=0
Set the BuilderConfig for the parser.
virtual void setFlags(OnnxParserFlags onnxParserFlags) noexcept=0
Set the parser flags.
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.
virtual nvinfer1::ITensor const * getLayerOutputTensor(char const *name, int64_t i) noexcept=0
Return the i-th output ITensor object for the ONNX layer "name".
An interface designed to refit weights from an ONNX model.
Definition: NvOnnxParser.h:503
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.
Definition: NvInferPluginBase.h:29
IParser * createParser(nvinfer1::INetworkDefinition &network, nvinfer1::ILogger &logger) noexcept
Create a new parser object.
Definition: NvOnnxParser.h:633
IParserRefitter * createParserRefitter(nvinfer1::IRefitter &refitter, nvinfer1::ILogger &logger) noexcept
Create a new ONNX refitter object.
Definition: NvOnnxParser.h:647
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:107
constexpr int32_t EnumMax() noexcept
ErrorCode
The type of error that the parser or refitter may return.
Definition: NvOnnxParser.h:72
OnnxParserFlag
Definition: NvOnnxParser.h:110
constexpr int32_t EnumMax< ErrorCode >() noexcept
Definition: NvOnnxParser.h:96
constexpr int32_t EnumMax< OnnxParserFlag >() noexcept
Definition: NvOnnxParser.h:138

  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