TensorRT 11.0.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
29
30#define NV_ONNX_PARSER_MAJOR 0
31#define NV_ONNX_PARSER_MINOR 1
32#define NV_ONNX_PARSER_PATCH 0
33
34static constexpr int32_t NV_ONNX_PARSER_VERSION
36
42namespace nvonnxparser
43{
44
50template <typename T>
51constexpr int32_t EnumMax() noexcept = delete;
52
58enum class ErrorCode : int
59{
60 kSUCCESS = 0,
61 kINTERNAL_ERROR = 1,
66 kINVALID_NODE = 6,
74 kREFIT_FAILED = 14
75};
76
78template <>
79constexpr int32_t EnumMax<ErrorCode>() noexcept
80{
81 return 14;
82}
83
91 = uint32_t;
92
93enum class OnnxParserFlag : int32_t
94{
107 // This flag is set to be OFF by default.
116};
117
119template <>
120constexpr int32_t EnumMax<OnnxParserFlag>() noexcept
121{
122 return 4;
123}
124
131{
132public:
136 virtual ErrorCode code() const = 0;
140 virtual char const* desc() const = 0;
144 virtual char const* file() const = 0;
148 virtual int line() const = 0;
152 virtual char const* func() const = 0;
156 virtual int node() const = 0;
160 virtual char const* nodeName() const = 0;
164 virtual char const* nodeOperator() const = 0;
170 virtual char const* const* localFunctionStack() const = 0;
174 // a stack size of 0.
176 virtual int32_t localFunctionStackSize() const = 0;
177
178protected:
179 virtual ~IParserError() {}
180};
181
193{
194public:
209 virtual bool parse(
210 void const* serialized_onnx_model, size_t serialized_onnx_model_size, const char* model_path = nullptr) noexcept
211 = 0;
212
223 virtual bool parseFromFile(char const* onnxModelFile, int verbosity) noexcept = 0;
224
234 virtual bool supportsOperator(const char* op_name) const noexcept = 0;
235
242 virtual int getNbErrors() const noexcept = 0;
243
249 virtual IParserError const* getError(int index) const noexcept = 0;
250
256 virtual void clearErrors() noexcept = 0;
257
258 virtual ~IParser() noexcept = default;
259
276 virtual char const* const* getUsedVCPluginLibraries(int64_t& nbPluginLibs) const noexcept = 0;
277
289 virtual void setFlags(OnnxParserFlags onnxParserFlags) noexcept = 0;
290
298 virtual OnnxParserFlags getFlags() const noexcept = 0;
299
307 virtual void clearFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
308
316 virtual void setFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
317
325 virtual bool getFlag(OnnxParserFlag onnxParserFlag) const noexcept = 0;
326
339 virtual nvinfer1::ITensor const* getLayerOutputTensor(char const* name, int64_t i) noexcept = 0;
340
353 virtual bool supportsModelV2(
354 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept = 0;
355
363 virtual int64_t getNbSubgraphs() noexcept = 0;
364
373 virtual bool isSubgraphSupported(int64_t const index) noexcept = 0;
374
385 virtual int64_t* getSubgraphNodes(int64_t const index, int64_t& subgraphLength) noexcept = 0;
386
403 virtual bool loadModelProto(
404 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept = 0;
405
428 virtual bool loadInitializer(char const* name, void const* data, size_t size) noexcept = 0;
429
435 virtual bool parseModelProto() noexcept = 0;
436
442 virtual bool setBuilderConfig(const nvinfer1::IBuilderConfig* const builderConfig) noexcept = 0;
443};
444
453{
454public:
467 virtual bool refitFromBytes(
468 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept
469 = 0;
470
481 virtual bool refitFromFile(char const* onnxModelFile) noexcept = 0;
482
488 virtual int32_t getNbErrors() const noexcept = 0;
489
495 virtual IParserError const* getError(int32_t index) const noexcept = 0;
496
502 virtual void clearErrors() = 0;
503
504 virtual ~IParserRefitter() noexcept = default;
505
521 virtual bool loadModelProto(
522 void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept = 0;
523
545 virtual bool loadInitializer(char const* name, void const* data, size_t size) noexcept = 0;
546
552 virtual bool refitModelProto() noexcept = 0;
553};
554
555} // namespace nvonnxparser
556
557extern "C" TENSORRTAPI void* createNvOnnxParser_INTERNAL(void* network, void* logger, int version) noexcept;
559 void* refitter, void* logger, int32_t version) noexcept;
560extern "C" TENSORRTAPI int getNvOnnxParserVersion() noexcept;
561
562namespace nvonnxparser
563{
564
565namespace
566{
567
584{
585 return static_cast<IParser*>(createNvOnnxParser_INTERNAL(&network, &logger, NV_ONNX_PARSER_VERSION));
586}
587
598{
599 return static_cast<IParserRefitter*>(
600 createNvOnnxParserRefitter_INTERNAL(&refitter, &logger, NV_ONNX_PARSER_VERSION));
601}
602
603} // namespace
604
605} // namespace nvonnxparser
606
607#endif // NV_ONNX_PARSER_H
#define TENSORRTAPI
Definition: NvInferRuntimeBase.h:70
TENSORRTAPI void * createNvOnnxParserRefitter_INTERNAL(void *refitter, void *logger, int32_t version) noexcept
TENSORRTAPI void * createNvOnnxParser_INTERNAL(void *network, void *logger, int version) noexcept
TENSORRTAPI int getNvOnnxParserVersion() noexcept
#define NV_ONNX_PARSER_PATCH
Definition: NvOnnxParser.h:32
#define NV_ONNX_PARSER_MINOR
Definition: NvOnnxParser.h:31
#define NV_ONNX_PARSER_MAJOR
Definition: NvOnnxParser.h:30
A network definition for input to the builder.
Definition: NvInfer.h:8164
Updates weights in an engine.
Definition: NvInferRuntime.h:2169
Application-implemented logging interface for the builder, refitter and runtime.
Definition: NvInferRuntime.h:1575
an object containing information about an error
Definition: NvOnnxParser.h:131
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:179
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:193
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 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 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() or parseFromFile() functions,...
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 parseFromFile(char const *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 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:453
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: NvInferSafePlugin.h:33
IParser * createParser(nvinfer1::INetworkDefinition &network, nvinfer1::ILogger &logger) noexcept
Create a new parser object.
Definition: NvOnnxParser.h:583
IParserRefitter * createParserRefitter(nvinfer1::IRefitter &refitter, nvinfer1::ILogger &logger) noexcept
Create a new ONNX refitter object.
Definition: NvOnnxParser.h:597
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:91
ErrorCode
The type of error that the parser or refitter may return.
Definition: NvOnnxParser.h:59
OnnxParserFlag
Definition: NvOnnxParser.h:94
@ kADJUST_FOR_DLA
Opportunistically rewrite or modify layers to make them more amenable to running on DLA.
constexpr int32_t EnumMax< ErrorCode >() noexcept
Specialization. See nvonnxparser::EnumMax() for details.
Definition: NvOnnxParser.h:79
constexpr int32_t EnumMax() noexcept=delete
constexpr int32_t EnumMax< OnnxParserFlag >() noexcept
Specialization. See nvonnxparser::EnumMax() for details.
Definition: NvOnnxParser.h:120

  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