TensorRT  7.1.0.16
NvUffParser.h
Go to the documentation of this file.
1 /*
2  * Copyright 1993-2020 NVIDIA Corporation. All rights reserved.
3  *
4  * NOTICE TO LICENSEE:
5  *
6  * This source code and/or documentation ("Licensed Deliverables") are
7  * subject to NVIDIA intellectual property rights under U.S. and
8  * international Copyright laws.
9  *
10  * These Licensed Deliverables contained herein is PROPRIETARY and
11  * CONFIDENTIAL to NVIDIA and is being provided under the terms and
12  * conditions of a form of NVIDIA software license agreement by and
13  * between NVIDIA and Licensee ("License Agreement") or electronically
14  * accepted by Licensee. Notwithstanding any terms or conditions to
15  * the contrary in the License Agreement, reproduction or disclosure
16  * of the Licensed Deliverables to any third party without the express
17  * written consent of NVIDIA is prohibited.
18  *
19  * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
20  * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
21  * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS
22  * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
23  * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
24  * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
25  * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
26  * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
27  * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
28  * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
29  * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
30  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
31  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32  * OF THESE LICENSED DELIVERABLES.
33  *
34  * U.S. Government End Users. These Licensed Deliverables are a
35  * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
36  * 1995), consisting of "commercial computer software" and "commercial
37  * computer software documentation" as such terms are used in 48
38  * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government
39  * only as a commercial end item. Consistent with 48 C.F.R.12.212 and
40  * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
41  * U.S. Government End Users acquire the Licensed Deliverables with
42  * only those rights set forth herein.
43  *
44  * Any use of the Licensed Deliverables in individual and commercial
45  * software must include, in the user documentation and internal
46  * comments to the code, the above Disclaimer and U.S. Government End
47  * Users Notice.
48  */
49 
50 #ifndef NV_UFF_PARSER_H
51 #define NV_UFF_PARSER_H
52 
53 #include "NvInfer.h"
54 
60 
61 // Current supported Universal Framework Format (UFF) version for the parser.
62 #define UFF_REQUIRED_VERSION_MAJOR 0
63 #define UFF_REQUIRED_VERSION_MINOR 6
64 #define UFF_REQUIRED_VERSION_PATCH 7
65 
71 namespace nvuffparser
72 {
73 
78 enum class UffInputOrder : int
79 {
80  kNCHW = 0,
81  kNHWC = 1,
82  kNC = 2
83 };
84 
89 
90 enum class FieldType : int
91 {
92  kFLOAT = 0,
93  kINT32 = 1,
94  kCHAR = 2,
95  kDIMS = 4,
96  kDATATYPE = 5,
97  kUNKNOWN = 6
98 };
99 
109 class TENSORRTAPI FieldMap
110 {
111 public:
112  const char* name;
113  const void* data;
114  FieldType type = FieldType::kUNKNOWN;
115  int length = 1;
116 
117  FieldMap(const char* name, const void* data, const FieldType type, int length = 1) TRTNOEXCEPT;
118 };
119 
121 {
122  int nbFields;
123  const FieldMap* fields;
124 };
125 
132 {
133 public:
139  virtual bool isPlugin(const char* layerName) TRTNOEXCEPT = 0;
140 
151  virtual nvinfer1::IPlugin* createPlugin(const char* layerName, const nvinfer1::Weights* weights, int nbWeights,
152  const FieldCollection fc) TRTNOEXCEPT = 0;
153 
154  virtual ~IPluginFactory() {}
155 };
156 
163 {
164 public:
165  virtual int getVersion() const TRTNOEXCEPT
166  {
167  return NV_TENSORRT_VERSION;
168  }
169 
175  virtual bool isPluginExt(const char* layerName) TRTNOEXCEPT = 0;
176 };
177 
186 {
187 public:
195  virtual bool registerInput(const char* inputName, nvinfer1::Dims inputDims, UffInputOrder inputOrder) TRTNOEXCEPT = 0;
196 
202  virtual bool registerOutput(const char* outputName) TRTNOEXCEPT = 0;
203 
211  virtual bool parse(const char* file,
213  nvinfer1::DataType weightsType=nvinfer1::DataType::kFLOAT) TRTNOEXCEPT = 0;
214 
223  virtual bool parseBuffer(const char* buffer, std::size_t size,
225  nvinfer1::DataType weightsType=nvinfer1::DataType::kFLOAT) TRTNOEXCEPT = 0;
226 
227  virtual void destroy() TRTNOEXCEPT = 0;
228 
232  virtual int getUffRequiredVersionMajor() TRTNOEXCEPT = 0;
233 
237  virtual int getUffRequiredVersionMinor() TRTNOEXCEPT = 0;
238 
242  virtual int getUffRequiredVersionPatch() TRTNOEXCEPT = 0;
243 
249  virtual void setPluginFactory(IPluginFactory* factory) TRTNOEXCEPT = 0;
250 
256  virtual void setPluginFactoryExt(IPluginFactoryExt* factory) TRTNOEXCEPT = 0;
257 
261  virtual void setPluginNamespace(const char* libNamespace) TRTNOEXCEPT = 0;
262 
263 protected:
264  virtual ~IUffParser() {}
265 
266 public:
276  //
279  virtual void setErrorRecorder(nvinfer1::IErrorRecorder* recorder) TRTNOEXCEPT = 0;
280 
291  virtual nvinfer1::IErrorRecorder* getErrorRecorder() const TRTNOEXCEPT = 0;
292 };
293 
301 TENSORRTAPI IUffParser* createUffParser() TRTNOEXCEPT;
302 
308 TENSORRTAPI void shutdownProtobufLibrary(void) TRTNOEXCEPT;
309 
310 } // namespace nvuffparser
311 
312 
317 extern "C" TENSORRTAPI void* createNvUffParser_INTERNAL() TRTNOEXCEPT;
318 
319 #endif /* !NV_UFF_PARSER_H */
nvuffparser::IPluginFactoryExt
Plugin factory used to configure plugins with added support for TRT versioning.
Definition: NvUffParser.h:162
nvuffparser::FieldCollection
Definition: NvUffParser.h:120
nvuffparser::IUffParser::registerOutput
virtual bool registerOutput(const char *outputName)=0
Register an output name of a UFF network.
nvuffparser::IPluginFactoryExt::isPluginExt
virtual bool isPluginExt(const char *layerName)=0
A user implemented function that determines if a layer configuration is provided by an IPluginExt.
nvuffparser::IUffParser::registerInput
virtual bool registerInput(const char *inputName, nvinfer1::Dims inputDims, UffInputOrder inputOrder)=0
Register an input name of a UFF network with the associated Dimensions.
nvuffparser::IUffParser::getUffRequiredVersionMajor
virtual int getUffRequiredVersionMajor()=0
Return Version Major of the UFF.
nvinfer1::INetworkDefinition
A network definition for input to the builder.
Definition: NvInfer.h:4811
nvinfer1::Weights
An array of weights used as a layer parameter.
Definition: NvInferRuntime.h:107
nvuffparser::IUffParser::setErrorRecorder
virtual void setErrorRecorder(nvinfer1::IErrorRecorder *recorder)=0
Set the ErrorRecorder for this interface.
nvinfer1::DataType::kFLOAT
32-bit floating point format.
nvuffparser::IUffParser::setPluginFactoryExt
virtual void setPluginFactoryExt(IPluginFactoryExt *factory)=0
Set the IPluginFactoryExt used to create the user defined pluginExts.
nvuffparser::FieldMap
An array of field params used as a layer parameter for plugin layers.
Definition: NvUffParser.h:109
nvinfer1::Dims
Structure to define the dimensions of a tensor.
Definition: NvInferRuntimeCommon.h:219
nvuffparser
The TensorRT UFF parser API namespace.
nvuffparser::IUffParser::parse
virtual bool parse(const char *file, nvinfer1::INetworkDefinition &network, nvinfer1::DataType weightsType=nvinfer1::DataType::kFLOAT)=0
Parse a UFF file.
nvuffparser::FieldType::kCHAR
char field type. String for length>1.
nvuffparser::createUffParser
IUffParser * createUffParser()
Creates a IUffParser object.
nvuffparser::IUffParser::getUffRequiredVersionPatch
virtual int getUffRequiredVersionPatch()=0
Return Patch Version of the UFF.
nvinfer1::DataType
DataType
The type of weights and tensors.
Definition: NvInferRuntimeCommon.h:163
nvuffparser::IUffParser::parseBuffer
virtual bool parseBuffer(const char *buffer, std::size_t size, nvinfer1::INetworkDefinition &network, nvinfer1::DataType weightsType=nvinfer1::DataType::kFLOAT)=0
Parse a UFF buffer, useful if the file already live in memory.
nvuffparser::IUffParser::setPluginFactory
virtual void setPluginFactory(IPluginFactory *factory)=0
Set the IPluginFactory used to create the user defined plugins.
nvuffparser::IUffParser
Class used for parsing models described using the UFF format.
Definition: NvUffParser.h:185
nvuffparser::IPluginFactory::isPlugin
virtual bool isPlugin(const char *layerName)=0
A user implemented function that determines if a layer configuration is provided by an IPlugin.
nvinfer1::IErrorRecorder
Reference counted application-implemented error reporting interface for TensorRT objects.
Definition: NvInferRuntimeCommon.h:1175
nvuffparser::IUffParser::setPluginNamespace
virtual void setPluginNamespace(const char *libNamespace)=0
Set the namespace used to lookup and create plugins in the network.
nvuffparser::FieldType::kDATATYPE
nvinfer1::DataType field type.
nvuffparser::IPluginFactory
Plugin factory used to configure plugins.
Definition: NvUffParser.h:131
nvuffparser::shutdownProtobufLibrary
void shutdownProtobufLibrary(void)
Shuts down protocol buffers library.
nvuffparser::UffInputOrder::kNCHW
NCHW order.
nvuffparser::FieldType::kINT32
INT32 field type.
NvInfer.h
nvuffparser::IUffParser::getErrorRecorder
virtual nvinfer1::IErrorRecorder * getErrorRecorder() const =0
get the ErrorRecorder assigned to this interface.
nvuffparser::FieldType::kDIMS
nvinfer1::Dims field type.
nvinfer1::IPlugin
Plugin class for user-implemented layers.
Definition: NvInferRuntime.h:143
nvuffparser::UffInputOrder::kNHWC
NHWC order.
nvuffparser::IPluginFactory::createPlugin
virtual nvinfer1::IPlugin * createPlugin(const char *layerName, const nvinfer1::Weights *weights, int nbWeights, const FieldCollection fc)=0
Creates a plugin.
nvuffparser::UffInputOrder::kNC
NC order.
nvuffparser::FieldType
FieldType
The possible field types for custom layer.
Definition: NvUffParser.h:90
nvuffparser::FieldType::kFLOAT
FP32 field type.
nvuffparser::IUffParser::getUffRequiredVersionMinor
virtual int getUffRequiredVersionMinor()=0
Return Version Minor of the UFF.
nvuffparser::UffInputOrder
UffInputOrder
The different possible supported input order.
Definition: NvUffParser.h:78