Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
NvOnnxParser.h658 linesDownload Raw Back to include
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
26//!
27//! \file NvOnnxParser.h
28//!
29//! This is the API for the ONNX Parser
30//!
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
37    = ((NV_ONNX_PARSER_MAJOR * 10000) + (NV_ONNX_PARSER_MINOR * 100) + NV_ONNX_PARSER_PATCH);
38
39//!
40//! \typedef SubGraph_t
41//!
42//! \brief The data structure containing the parsing capability of
43//! a set of nodes in an ONNX graph.
44//!
45typedef std::pair<std::vector<size_t>, bool> SubGraph_t;
46
47//!
48//! \typedef SubGraphCollection_t
49//!
50//! \brief The data structure containing all SubGraph_t partitioned
51//! out of an ONNX graph.
52//!
53typedef std::vector<SubGraph_t> SubGraphCollection_t;
54
55//!
56//! \namespace nvonnxparser
57//!
58//! \brief The TensorRT ONNX parser API namespace
59//!
60namespace nvonnxparser
61{
62
63//! \return the numerical value of the highest-valued enumerator for type T.
64//! It must be specialized for each enum type that uses it.
65//! {$nv-internal-release begin}
66//! \note This is different from nvinfer1::EnumMax<T>(), which is one more than that.
67//! {$nv-internal-release end}
68template <typename T>
69constexpr int32_t EnumMax() noexcept = delete;
70
71//!
72//! \enum ErrorCode
73//!
74//! \brief The type of error that the parser or refitter may return
75//!
76enum class ErrorCode : int
77{
78    kSUCCESS = 0,
79    kINTERNAL_ERROR = 1,
80    kMEM_ALLOC_FAILED = 2,
81    kMODEL_DESERIALIZE_FAILED = 3,
82    kINVALID_VALUE = 4,
83    kINVALID_GRAPH = 5,
84    kINVALID_NODE = 6,
85    kUNSUPPORTED_GRAPH = 7,
86    kUNSUPPORTED_NODE = 8,
87    kUNSUPPORTED_NODE_ATTR = 9,
88    kUNSUPPORTED_NODE_INPUT = 10,
89    kUNSUPPORTED_NODE_DATATYPE = 11,
90    kUNSUPPORTED_NODE_DYNAMIC = 12,
91    kUNSUPPORTED_NODE_SHAPE = 13,
92    kREFIT_FAILED = 14
93};
94
95//! Specialization. See `nvonnxparser::EnumMax()` for details.
96template <>
97constexpr int32_t EnumMax<ErrorCode>() noexcept
98{
99    return 14;
100}
101
102//!
103//! \brief Represents one or more OnnxParserFlag values using binary OR
104//! operations, e.g., 1U << OnnxParserFlag::kNATIVE_INSTANCENORM
105//!
106//! \see IParser::setFlags() and IParser::getFlags()
107//!
108using OnnxParserFlags
109    = uint32_t;
110
111enum class OnnxParserFlag : int32_t
112{
113    //! Parse the ONNX model into the INetworkDefinition with the intention of using TensorRT's native layer
114    //! implementation over the plugin implementation for InstanceNormalization nodes.
115    //! This flag is required when building version-compatible or hardware-compatible engines.
116    //! This flag is set to be ON by default.
117    kNATIVE_INSTANCENORM = 0,
118    //! Enable UINT8 as a quantization data type and asymmetric quantization with non-zero zero-point values
119    //! in Quantize and Dequantize nodes. This flag is set to be OFF by default.
120    //! The resulting engine must be built targeting DLA version >= 3.16.
121    kENABLE_UINT8_AND_ASYMMETRIC_QUANTIZATION_DLA = 1,
122    //! Parse the ONNX model with per-node validation for DLA. If the model is not fully supported by DLA, then
123    //! parsing will fail. If this flag is set, isSubGraphSupported() will also return capability in the context of DLA
124    //! support. When this flag is set, a valid IBuilderConfig must be provided to the parser via setBuilderConfig().
125    // This flag is set to be OFF by default.
126    kREPORT_CAPABILITY_DLA = 2,
127    //! Allow a loaded plugin with the same name as an ONNX operator type to override the default ONNX implementation,
128    //! even if the plugin namespace attribute is not set.
129    //! Useful for custom plugins that replace standard ONNX operators, such as alternative implementations for better
130    //! performance. This flag is set to be OFF by default.
131    kENABLE_PLUGIN_OVERRIDE = 3,
132    //! Opportunistically rewrite or modify layers to make them more amenable to running on DLA.
133    kADJUST_FOR_DLA = 4
134};
135
136//! Specialization. See `nvonnxparser::EnumMax()` for details.
137template <>
138constexpr int32_t EnumMax<OnnxParserFlag>() noexcept
139{
140    return 3;
141}
142
143//!
144//! \class IParserError
145//!
146//! \brief an object containing information about an error
147//!
148class IParserError
149{
150public:
151    //!
152    //!\brief the error code.
153    //!
154    virtual ErrorCode code() const = 0;
155    //!
156    //!\brief description of the error.
157    //!
158    virtual char const* desc() const = 0;
159    //!
160    //!\brief source file in which the error occurred.
161    //!
162    virtual char const* file() const = 0;
163    //!
164    //!\brief source line at which the error occurred.
165    //!
166    virtual int line() const = 0;
167    //!
168    //!\brief source function in which the error occurred.
169    //!
170    virtual char const* func() const = 0;
171    //!
172    //!\brief index of the ONNX model node in which the error occurred.
173    //!
174    virtual int node() const = 0;
175    //!
176    //!\brief name of the node in which the error occurred.
177    //!
178    virtual char const* nodeName() const = 0;
179    //!
180    //!\brief name of the node operation in which the error occurred.
181    //!
182    virtual char const* nodeOperator() const = 0;
183    //!
184    //!\brief A list of the local function names, from the top level down, constituting the current
185    //!             stack trace in which the error occurred. A top-level node that is not inside any
186    //!             local function would return a nullptr.
187    //!
188    virtual char const* const* localFunctionStack() const = 0;
189    //!
190    //!\brief The size of the stack of local functions at the point where the error occurred.
191    //!             A top-level node that is not inside any local function would correspond to
192    //              a stack size of 0.
193    //!
194    virtual int32_t localFunctionStackSize() const = 0;
195
196protected:
197    virtual ~IParserError() {}
198};
199
200//!
201//! \class IParser
202//!
203//! \brief an object for parsing ONNX models into a TensorRT network definition
204//!
205//! \warning If the ONNX model has a graph output with the same name as a graph input,
206//!          the output will be renamed by prepending "__".
207//!
208//! \warning Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.
209//!
210class IParser
211{
212public:
213    //!
214    //! \brief Parse a serialized ONNX model into the TensorRT network.
215    //!         This method has very limited diagnostics. If parsing the serialized model
216    //!         fails for any reason (e.g. unsupported IR version, unsupported opset, etc.)
217    //!         it the user responsibility to intercept and report the error.
218    //!         To obtain a better diagnostic, use the parseFromFile method below.
219    //!
220    //! \param serialized_onnx_model Pointer to the serialized ONNX model. Can be freed after this function returns.
221    //! \param serialized_onnx_model_size Size of the serialized ONNX model
222    //!        in bytes
223    //! \param model_path Absolute path to the model file for loading external weights if required
224    //! \return true if the model was parsed successfully
225    //! \see getNbErrors() getError()
226    //!
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
231    //!
232    //! \brief Parse an onnx model file, which can be a binary protobuf or a text onnx model
233    //!         calls parse method inside.
234    //!
235    //! \param onnxModelFile name
236    //! \param verbosity Level
237    //!
238    //! \return true if the model was parsed successfully
239    //!
240    //!
241    virtual bool parseFromFile(const char* onnxModelFile, int verbosity) noexcept = 0;
242
243    //!
244    //! [DEPRECATED] Deprecated in TensorRT 10.1. See supportsModelV2.
245    //!
246    //! \brief Check whether TensorRT supports a particular ONNX model.
247    //!        If the function returns True, one can proceed to engine building
248    //!        without having to call \p parse or \p parseFromFile.
249    //!
250    //! \param serialized_onnx_model Pointer to the serialized ONNX model. Can be freed after this function returns.
251    //! \param serialized_onnx_model_size Size of the serialized ONNX model
252    //!        in bytes
253    //! \param sub_graph_collection Container to hold supported subgraphs
254    //! \param model_path Absolute path to the model file for loading external weights if required
255    //! \return true if the model is supported
256    //!
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    //!
261    //! [DEPRECATED] Deprecated in TensorRT 10.13. See loadInitializer().
262    //!
263    //!\brief Parse a serialized ONNX model into the TensorRT network
264    //! with consideration of user provided weights
265    //!
266    //! \param serialized_onnx_model Pointer to the serialized ONNX model. Can be freed after this function returns.
267    //! \param serialized_onnx_model_size Size of the serialized ONNX model
268    //!        in bytes
269    //! \return true if the model was parsed successfully
270    //! \see getNbErrors() getError()
271    //!
272    TRT_DEPRECATED virtual bool parseWithWeightDescriptors(
273        void const* serialized_onnx_model, size_t serialized_onnx_model_size) noexcept = 0;
274
275    //!
276    //!\brief Returns whether the specified operator may be supported by the
277    //!         parser.
278    //!
279    //! Note that a result of true does not guarantee that the operator will be
280    //! supported in all cases (i.e., this function may return false-positives).
281    //!
282    //! \param op_name The name of the ONNX operator to check for support
283    //!
284    virtual bool supportsOperator(const char* op_name) const noexcept = 0;
285
286    //!
287    //!\brief Get the number of errors that occurred during prior calls to
288    //!         \p parse
289    //!
290    //! \see getError() clearErrors() IParserError
291    //!
292    virtual int getNbErrors() const noexcept = 0;
293
294    //!
295    //!\brief Get an error that occurred during prior calls to \p parse
296    //!
297    //! \see getNbErrors() clearErrors() IParserError
298    //!
299    virtual IParserError const* getError(int index) const noexcept = 0;
300
301    //!
302    //!\brief Clear errors from prior calls to \p parse
303    //!
304    //! \see getNbErrors() getError() IParserError
305    //!
306    virtual void clearErrors() noexcept = 0;
307
308    virtual ~IParser() noexcept = default;
309
310    //!
311    //! \brief Query the plugin libraries needed to implement operations used by the parser in a version-compatible
312    //! engine.
313    //!
314    //! This provides a list of plugin libraries on the filesystem needed to implement operations
315    //! in the parsed network.  If you are building a version-compatible engine using this network,
316    //! provide this list to IBuilderConfig::setPluginsToSerialize to serialize these plugins along
317    //! with the version-compatible engine, or, if you want to ship these plugin libraries externally
318    //! to the engine, ensure that IPluginRegistry::loadLibrary is used to load these libraries in the
319    //! appropriate runtime before deserializing the corresponding engine.
320    //!
321    //! \param[out] nbPluginLibs Returns the number of plugin libraries in the array, or -1 if there was an error.
322    //! \return Array of `nbPluginLibs` C-strings describing plugin library paths on the filesystem if nbPluginLibs > 0,
323    //! or nullptr otherwise.  This array is owned by the IParser, and the pointers in the array are only valid until
324    //! the next call to parse(), supportsModel(), parseFromFile(), or parseWithWeightDescriptors().
325    //!
326    virtual char const* const* getUsedVCPluginLibraries(int64_t& nbPluginLibs) const noexcept = 0;
327
328    //!
329    //! \brief Set the parser flags.
330    //!
331    //! The flags are listed in the OnnxParserFlag enum.
332    //!
333    //! \param OnnxParserFlags The flags used when parsing an ONNX model.
334    //!
335    //! \note This function will override the previous set flags, rather than bitwise ORing the new flag.
336    //!
337    //! \see getFlags()
338    //!
339    virtual void setFlags(OnnxParserFlags onnxParserFlags) noexcept = 0;
340
341    //!
342    //! \brief Get the parser flags. Defaults to 0.
343    //!
344    //! \return The parser flags as a bitmask.
345    //!
346    //! \see setFlags()
347    //!
348    virtual OnnxParserFlags getFlags() const noexcept = 0;
349
350    //!
351    //! \brief clear a parser flag.
352    //!
353    //! clears the parser flag from the enabled flags.
354    //!
355    //! \see setFlags()
356    //!
357    virtual void clearFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
358
359    //!
360    //! \brief Set a single parser flag.
361    //!
362    //! Add the input parser flag to the already enabled flags.
363    //!
364    //! \see setFlags()
365    //!
366    virtual void setFlag(OnnxParserFlag onnxParserFlag) noexcept = 0;
367
368    //!
369    //! \brief Returns true if the parser flag is set
370    //!
371    //! \see getFlags()
372    //!
373    //! \return True if flag is set, false if unset.
374    //!
375    virtual bool getFlag(OnnxParserFlag onnxParserFlag) const noexcept = 0;
376
377    //!
378    //!\brief Return the i-th output ITensor object for the ONNX layer "name".
379    //!
380    //! Return the i-th output ITensor object for the ONNX layer "name".
381    //! If "name" is not found or i is out of range, return nullptr.
382    //! In the case of multiple nodes sharing the same name this function will return
383    //! the output tensors of the first instance of the node in the ONNX graph.
384    //!
385    //! \param name The name of the ONNX layer.
386    //!
387    //! \param i The index of the output. i must be in range [0, layer.num_outputs).
388    //!
389    virtual nvinfer1::ITensor const* getLayerOutputTensor(char const* name, int64_t i) noexcept = 0;
390
391    //!
392    //! \brief Check whether TensorRT supports a particular ONNX model.
393    //!            If the function returns True, one can proceed to engine building
394    //!            without having to call \p parse or \p parseFromFile.
395    //!            Results can be queried through \p getNbSubgraphs, \p isSubgraphSupported,
396    //!            \p getSubgraphNodes.
397    //!
398    //! \param serializedOnnxModel Pointer to the serialized ONNX model. Can be freed after this function returns.
399    //! \param serializedOnnxModelSize Size of the serialized ONNX model in bytes
400    //! \param modelPath Absolute path to the model file for loading external weights if required
401    //! \return true if the model is supported
402    //!
403    virtual bool supportsModelV2(
404        void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept = 0;
405
406    //!
407    //! \brief Get the number of subgraphs. Calling this function before calling \p supportsModelV2 results in undefined
408    //! behavior.
409    //!
410    //!
411    //! \return Number of subgraphs.
412    //!
413    virtual int64_t getNbSubgraphs() noexcept = 0;
414
415    //!
416    //! \brief Returns whether the subgraph is supported. Calling this function before calling \p supportsModelV2
417    //! results in undefined behavior.
418    //!
419    //!
420    //! \param index Index of the subgraph.
421    //! \return Whether the subgraph is supported.
422    //!
423    virtual bool isSubgraphSupported(int64_t const index) noexcept = 0;
424
425    //!
426    //! \brief Get the nodes of the specified subgraph. Calling this function before calling \p supportsModelV2 results
427    //! in undefined behavior.
428    //!
429    //!
430    //! \param index Index of the subgraph.
431    //! \param subgraphLength Returns the length of the subgraph as reference.
432    //!
433    //! \return Pointer to the subgraph nodes array. This pointer is owned by the Parser.
434    //!
435    virtual int64_t* getSubgraphNodes(int64_t const index, int64_t& subgraphLength) noexcept = 0;
436
437    //!
438    //! \brief Load a serialized ONNX model into the parser. Unlike the parse(), parseFromFile(), or
439    //! parseWithWeightDescriptors() functions, this function does not immediately convert the model into a TensorRT
440    //! INetworkDefinition. Using this function allows users to provide their own initializers for the ONNX model
441    //! through the loadInitializer() function.
442    //!
443    //! Only one model can be loaded at a time. Subsequent calls to loadModelProto() will result in an error.
444    //!
445    //! To begin the conversion of the model into a TensorRT INetworkDefinition, use parseModelProto().
446    //!
447    //! \param serializedOnnxModel Pointer to the serialized ONNX model. Can be freed after this function returns.
448    //! \param serializedOnnxModelSize Size of the serialized ONNX model in bytes.
449    //! \param modelPath Absolute path to the model file for loading external weights if required.
450    //! \return true if the model was loaded successfully
451    //! \see getNbErrors() getError()
452    //!
453    virtual bool loadModelProto(
454        void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept = 0;
455
456    //!
457    //! \brief Prompt the ONNX parser to load an initializer with user-provided binary data.
458    //! The lifetime of the data must exceed the lifetime of the parser.
459    //!
460    //! All user-provided initializers must be provided prior to calling refitModelProto().
461    //!
462    //! This function can be called multiple times to specify the names of multiple initializers.
463    //!
464    //! Calling this function with an initializer previously specified will overwrite the previous instance.
465    //!
466    //!
467    //! This function will return false if initializer validation fails. Possible validation errors are:
468    //! * This function was called prior to loadModelProto().
469    //! * The requested initializer was not found in the model.
470    //! * The size of the data provided is different from the corresponding initializer in the model.
471    //!
472    //! \param name Name of the initializer.
473    //! \param data Binary data containing the values of the initializer.
474    //! \param size Size of the initializer in bytes.
475    //! \return true if the initializer was loaded successfully
476    //! \see loadModelProto()
477    //!
478    virtual bool loadInitializer(char const* name, void const* data, size_t size) noexcept = 0;
479
480    //! \brief Begin the parsing and conversion process of the loaded ONNX model into a TensorRT INetworkDefinition.
481    //!
482    //! \return true if conversion was successful
483    //! \see getNbErrors() getError() loadModelProto() loadModelProtoFromFile()
484    //!
485    virtual bool parseModelProto() noexcept = 0;
486
487    //!
488    //! \brief Set the BuilderConfig for the parser.
489    //!
490    //! \return true if the IBuilderConfig was set successfully, false otherwise.
491    //!
492    virtual bool setBuilderConfig(const nvinfer1::IBuilderConfig* const builderConfig) noexcept = 0;
493};
494
495//!
496//! \class IParserRefitter
497//!
498//! \brief An interface designed to refit weights from an ONNX model.
499//!
500//! \warning Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.
501//!
502class IParserRefitter
503{
504public:
505    //!
506    //! \brief Load a serialized ONNX model from memory and perform weight refit.
507    //!
508    //! \param serializedOnnxModel Pointer to the serialized ONNX model
509    //! \param serializedOnnxModelSize Size of the serialized ONNX model
510    //!        in bytes
511    //! \param modelPath Absolute path to the model file for loading external weights if required
512    //! \return true if all the weights in the engine were refit successfully.
513    //!
514    //! The serialized ONNX model must be identical to the one used to generate the engine
515    //! that will be refit.
516    //!
517    virtual bool refitFromBytes(
518        void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept
519        = 0;
520
521    //!
522    //! \brief Load and parse a ONNX model from disk and perform weight refit.
523    //!
524    //! \param onnxModelFile Path to the ONNX model to load from disk.
525    //!
526    //! \return true if the model was loaded successfully, and if all the weights in the engine were refit successfully.
527    //!
528    //! The provided ONNX model must be identical to the one used to generate the engine
529    //! that will be refit.
530    //!
531    virtual bool refitFromFile(char const* onnxModelFile) noexcept = 0;
532
533    //!
534    //!\brief Get the number of errors that occurred during prior calls to \p refitFromBytes or \p refitFromFile
535    //!
536    //! \see getError() IParserError
537    //!
538    virtual int32_t getNbErrors() const noexcept = 0;
539
540    //!
541    //!\brief Get an error that occurred during prior calls to \p refitFromBytes or \p refitFromFile
542    //!
543    //! \see getNbErrors() IParserError
544    //!
545    virtual IParserError const* getError(int32_t index) const noexcept = 0;
546
547    //!
548    //!\brief Clear errors from prior calls to \p refitFromBytes or \p refitFromFile
549    //!
550    //! \see getNbErrors() getError() IParserError
551    //!
552    virtual void clearErrors() = 0;
553
554    virtual ~IParserRefitter() noexcept = default;
555
556    //!
557    //! \brief Load a serialized ONNX model into the parser. Unlike the refit(), or refitFromFile()
558    //! functions, this function does not immediately begin the refit process. Using this function
559    //! allows users to provide their own initializers for the ONNX model through the loadInitializer() function.
560    //!
561    //! Only one model can be loaded at a time. Subsequent calls to loadModelProto() will result in an error.
562    //!
563    //! To begin the refit process, use refitModelProto().
564    //!
565    //! \param serializedOnnxModel Pointer to the serialized ONNX model. Can be freed after this function returns.
566    //! \param serializedOnnxModelSize Size of the serialized ONNX model in bytes.
567    //! \param modelPath Absolute path to the model file for loading external weights if required.
568    //! \return true if the model was loaded successfully
569    //! \see getNbErrors() getError()
570    //!
571    virtual bool loadModelProto(
572        void const* serializedOnnxModel, size_t serializedOnnxModelSize, char const* modelPath = nullptr) noexcept = 0;
573
574    //!
575    //! \brief Prompt the ONNX refitter to load an initializer with user-provided binary data.
576    //! The lifetime of the data must exceed the lifetime of the refitter.
577    //!
578    //! All user-provided initializers must be provided prior to calling refitModelProto().
579    //!
580    //! This function can be called multiple times to specify the names of multiple initializers.
581    //!
582    //! Calling this function with an initializer previously specified will overwrite the previous instance.
583    //!
584    //! This function will return false if initializer validation fails. Possible validation errors are:
585    //! * This function was called prior to loadModelProto()
586    //! * The requested initializer was not found in the model.
587    //! * The size of the data provided is different from the corresponding initializer in the model.
588    //!
589    //! \param name Name of the initializer.
590    //! \param data Binary data containing the values of the initializer.
591    //! \param size Size of the initializer in bytes.
592    //! \return true if the initializer was loaded successfully
593    //! \see loadModelProto()
594    //!
595    virtual bool loadInitializer(char const* name, void const* data, size_t size) noexcept = 0;
596
597    //! \brief Begin the refit process from the loaded ONNX model.
598    //!
599    //! \return true if refit was successful
600    //! \see getNbErrors() getError() loadModelProto()
601    //!
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;
608extern "C" TENSORRTAPI void* createNvOnnxParserRefitter_INTERNAL(
609    void* refitter, void* logger, int32_t version) noexcept;
610extern "C" TENSORRTAPI int getNvOnnxParserVersion() noexcept;
611
612namespace nvonnxparser
613{
614
615namespace
616{
617
618//!
619//! \brief Create a new parser object
620//!
621//! \param network The network definition that the parser will write to
622//! \param logger The logger to use
623//! \return a new parser object or NULL if an error occurred
624//!
625//! Any input dimensions that are constant should not be changed after parsing,
626//! because correctness of the translation may rely on those constants.
627//! Changing a dynamic input dimension, i.e. one that translates to -1 in
628//! TensorRT, to a constant is okay if the constant is consistent with the model.
629//! Each instance of the parser is designed to only parse one ONNX model once.
630//!
631//! \see IParser
632//!
633inline IParser* createParser(nvinfer1::INetworkDefinition& network, nvinfer1::ILogger& logger) noexcept
634{
635    return static_cast<IParser*>(createNvOnnxParser_INTERNAL(&network, &logger, NV_ONNX_PARSER_VERSION));
636}
637
638//!
639//! \brief Create a new ONNX refitter object
640//!
641//! \param refitter The Refitter object used to refit the model
642//! \param logger The logger to use
643//! \return a new ParserRefitter object or NULL if an error occurred
644//!
645//! \see IParserRefitter
646//!
647inline IParserRefitter* createParserRefitter(nvinfer1::IRefitter& refitter, nvinfer1::ILogger& logger) noexcept
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
658 
codekingpro/portable-devtools · Team Ai