TensorRT 11.3.0
NvInferPythonPlugin.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2024-2026 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 TRT_PYTHON_IMPL_PLUGIN_H
19#define TRT_PYTHON_IMPL_PLUGIN_H
20
21#include "NvInfer.h"
22
31
32namespace nvinfer1
33{
34
37enum class PluginArgType : int32_t
38{
40 kINT = 0,
41};
42
45enum class PluginArgDataType : int32_t
46{
48 kINT8 = 0,
50 kINT16 = 1,
52 kINT32 = 2,
53};
57{
58public:
60 virtual PluginArgType getType() const noexcept = 0;
62 virtual PluginArgDataType getDataType() const noexcept = 0;
64 virtual void* getExpr() noexcept = 0;
65};
66
69{
70public:
71 virtual ISymExpr* getSymExpr(int32_t index) const noexcept = 0;
72 virtual bool setSymExpr(int32_t index, ISymExpr* symExpr) noexcept = 0;
73 virtual int32_t getNbSymExprs() const noexcept = 0;
74 virtual bool setNbSymExprs(int32_t count) noexcept = 0;
75
76 virtual ~ISymExprsImpl() noexcept = 0;
77};
78
79inline ISymExprsImpl::~ISymExprsImpl() noexcept = default;
80
86{
87public:
90 ISymExpr* getSymExpr(int32_t index) const noexcept
91 {
92 return mImpl->getSymExpr(index);
93 }
94
97 bool setSymExpr(int32_t index, ISymExpr* symExpr) noexcept
98 {
99 return mImpl->setSymExpr(index, symExpr);
100 }
101
103 int32_t getNbSymExprs() const noexcept
104 {
105 return mImpl->getNbSymExprs();
106 }
107
110 bool setNbSymExprs(int32_t count) noexcept
111 {
112 return mImpl->setNbSymExprs(count);
113 }
114
115protected:
116 ISymExprsImpl* mImpl{nullptr};
117 virtual ~ISymExprs() noexcept = 0;
118};
119
120inline ISymExprs::~ISymExprs() noexcept = default;
121
124enum class QuickPluginCreationRequest : int32_t
125{
127 kUNKNOWN = 0,
129 kPREFER_JIT = 1,
131 kPREFER_AOT = 2,
133 kSTRICT_JIT = 3,
135 kSTRICT_AOT = 4,
136};
137
140{
141public:
142 virtual ISymExpr* getGridX() noexcept = 0;
143 virtual bool setGridX(ISymExpr* gridX) noexcept = 0;
144
145 virtual ISymExpr* getGridY() noexcept = 0;
146 virtual bool setGridY(ISymExpr* gridY) noexcept = 0;
147
148 virtual ISymExpr* getGridZ() noexcept = 0;
149 virtual bool setGridZ(ISymExpr* gridZ) noexcept = 0;
150
151 virtual ISymExpr* getBlockX() noexcept = 0;
152 virtual bool setBlockX(ISymExpr* blockX) noexcept = 0;
153
154 virtual ISymExpr* getBlockY() noexcept = 0;
155 virtual bool setBlockY(ISymExpr* blockY) noexcept = 0;
156
157 virtual ISymExpr* getBlockZ() noexcept = 0;
158 virtual bool setBlockZ(ISymExpr* blockZ) noexcept = 0;
159
160 virtual ISymExpr* getSharedMem() noexcept = 0;
161 virtual bool setSharedMem(ISymExpr* sharedMem) noexcept = 0;
162
163 virtual ~IKernelLaunchParamsImpl() noexcept = 0;
164};
165
166inline IKernelLaunchParamsImpl::~IKernelLaunchParamsImpl() noexcept = default;
167
172{
173public:
175 ISymExpr* getGridX() noexcept
176 {
177 return mImpl->getGridX();
178 }
179
182 bool setGridX(ISymExpr* gridX) noexcept
183 {
184 return mImpl->setGridX(gridX);
185 }
186
188 ISymExpr* getGridY() noexcept
189 {
190 return mImpl->getGridY();
191 }
192
195 bool setGridY(ISymExpr* gridY) noexcept
196 {
197 return mImpl->setGridY(gridY);
198 }
199
201 ISymExpr* getGridZ() noexcept
202 {
203 return mImpl->getGridZ();
204 }
205
208 bool setGridZ(ISymExpr* gridZ) noexcept
209 {
210 return mImpl->setGridZ(gridZ);
211 }
212
214 ISymExpr* getBlockX() noexcept
215 {
216 return mImpl->getBlockX();
217 }
218
221 bool setBlockX(ISymExpr* blockX) noexcept
222 {
223 return mImpl->setBlockX(blockX);
224 }
225
227 ISymExpr* getBlockY() noexcept
228 {
229 return mImpl->getBlockY();
230 }
231
234 bool setBlockY(ISymExpr* blockY) noexcept
235 {
236 return mImpl->setBlockY(blockY);
237 }
238
240 ISymExpr* getBlockZ() noexcept
241 {
242 return mImpl->getBlockZ();
243 }
244
247 bool setBlockZ(ISymExpr* blockZ) noexcept
248 {
249 return mImpl->setBlockZ(blockZ);
250 }
251
254 {
255 return mImpl->getSharedMem();
256 }
257
260 bool setSharedMem(ISymExpr* sharedMem) noexcept
261 {
262 return mImpl->setSharedMem(sharedMem);
263 }
264
265protected:
266 IKernelLaunchParamsImpl* mImpl{nullptr};
267 virtual ~IKernelLaunchParams() noexcept = 0;
268};
269
270inline IKernelLaunchParams::~IKernelLaunchParams() noexcept = default;
271
272
273namespace v_1_0
274{
275
277{
278public:
279 InterfaceInfo getInterfaceInfo() const noexcept override
280 {
281 return InterfaceInfo{"PLUGIN_V3QUICK_CORE", 1, 0};
282 }
283
284 virtual AsciiChar const* getPluginName() const noexcept = 0;
285
286 virtual AsciiChar const* getPluginVersion() const noexcept = 0;
287
288 virtual AsciiChar const* getPluginNamespace() const noexcept = 0;
289};
290
292{
293public:
294 InterfaceInfo getInterfaceInfo() const noexcept override
295 {
296 return InterfaceInfo{"PLUGIN_V3QUICK_BUILD", 1, 0};
297 }
298
310 virtual int32_t getOutputDataTypes(DataType* outputTypes, int32_t nbOutputs, DataType const* inputTypes,
311 int32_t const* inputRanks, int32_t nbInputs) const noexcept = 0;
312
325 virtual int32_t getOutputShapes(DimsExprs const* inputs, int32_t nbInputs, DimsExprs const* shapeInputs,
326 int32_t nbShapeInputs, DimsExprs* outputs, int32_t nbOutputs, IExprBuilder& exprBuilder) noexcept = 0;
327
333 virtual int32_t configurePlugin(DynamicPluginTensorDesc const* in, int32_t nbInputs,
334 DynamicPluginTensorDesc const* out, int32_t nbOutputs) noexcept = 0;
335
341 DynamicPluginTensorDesc const* inOut, int32_t nbInputs, int32_t nbOutputs) noexcept = 0;
342
350 virtual int32_t getSupportedFormatCombinations(DynamicPluginTensorDesc const* inOut, int32_t nbInputs,
351 int32_t nbOutputs, PluginTensorDesc* supportedCombinations, int32_t nbFormatCombinations) noexcept = 0;
352
356 virtual int32_t getNbOutputs() const noexcept = 0;
357
362 virtual int32_t getAliasedInput(int32_t outputIndex) noexcept
363 {
364 return -1;
365 }
366
373 virtual int32_t getValidTactics(int32_t* tactics, int32_t nbTactics) noexcept
374 {
375 return 0;
376 }
377
381 virtual int32_t getNbTactics() noexcept
382 {
383 return 0;
384 }
385
389 virtual char const* getTimingCacheID() noexcept
390 {
391 return nullptr;
392 }
393
398 virtual char const* getMetadataString() noexcept
399 {
400 return nullptr;
401 }
402};
403
405{
406public:
407 InterfaceInfo getInterfaceInfo() const noexcept override
408 {
409 return InterfaceInfo{"PLUGIN_V3QUICKAOT_BUILD", 1, 0};
410 }
411
429 virtual int32_t getLaunchParams(DimsExprs const* inputs, DynamicPluginTensorDesc const* inOut, int32_t nbInputs,
430 int32_t nbOutputs, IKernelLaunchParams* launchParams, ISymExprs* extraArgs,
431 IExprBuilder& exprBuilder) noexcept = 0;
432
449 virtual int32_t getKernel(PluginTensorDesc const* in, int32_t nbInputs, PluginTensorDesc const* out,
450 int32_t nbOutputs, const char** kernelName, char** compiledKernel, int32_t* compiledKernelSize) noexcept = 0;
451
458 virtual int32_t setTactic(int32_t tactic) noexcept
459 {
460 return 0;
461 }
462};
463
465{
466public:
467 InterfaceInfo getInterfaceInfo() const noexcept override
468 {
469 return InterfaceInfo{"PLUGIN_V3QUICK_RUNTIME", 1, 0};
470 }
471
478 virtual int32_t setTactic(int32_t tactic) noexcept
479 {
480 return 0;
481 }
482
498 virtual int32_t enqueue(PluginTensorDesc const* inputDesc, PluginTensorDesc const* outputDesc,
499 void const* const* inputs, void* const* outputs, Dims const* inputStrides, Dims const* outputStrides,
500 int32_t nbInputs, int32_t nbOutputs, cudaStream_t stream) noexcept = 0;
501
505 virtual PluginFieldCollection const* getFieldsToSerialize() noexcept = 0;
506};
507
509{
510public:
511 InterfaceInfo getInterfaceInfo() const noexcept override
512 {
513 return InterfaceInfo{"PLUGIN CREATOR_V3QUICK", 1, 0};
514 }
515
525 virtual IPluginV3* createPlugin(AsciiChar const* name, AsciiChar const* nspace, PluginFieldCollection const* fc,
526 TensorRTPhase phase, QuickPluginCreationRequest quickPluginCreationRequest) noexcept = 0;
527
532 virtual PluginFieldCollection const* getFieldNames() noexcept = 0;
533
534 virtual AsciiChar const* getPluginName() const noexcept = 0;
535
536 virtual AsciiChar const* getPluginVersion() const noexcept = 0;
537
538 virtual AsciiChar const* getPluginNamespace() const noexcept = 0;
539
541 virtual ~IPluginCreatorV3Quick() = default;
542
543protected:
546 IPluginCreatorV3Quick& operator=(IPluginCreatorV3Quick const&) & = default;
548};
549
550} // namespace v_1_0
551
561
571
582
592
600
601} // namespace nvinfer1
602
603#endif // TRT_PYTHON_IMPL_PLUGIN_H
Definition: NvInferRuntimeBase.h:224
Analog of class Dims with expressions instead of constants for the dimensions.
Definition: NvInferRuntime.h:361
Object for constructing IDimensionExpr.
Definition: NvInferRuntime.h:296
Allows for kernel launch parameters to be communicated to the TensorRT backend.
Definition: NvInferPythonPlugin.h:172
virtual ~IKernelLaunchParams() noexcept=0
ISymExpr * getBlockZ() noexcept
Get the Z dimension of each thread block.
Definition: NvInferPythonPlugin.h:240
bool setBlockX(ISymExpr *blockX) noexcept
Set the X dimension of each thread block.
Definition: NvInferPythonPlugin.h:221
ISymExpr * getBlockY() noexcept
Get the Y dimension of each thread block.
Definition: NvInferPythonPlugin.h:227
ISymExpr * getGridY() noexcept
Get the Y dimension of the grid.
Definition: NvInferPythonPlugin.h:188
bool setGridY(ISymExpr *gridY) noexcept
Set the Y dimension of the grid.
Definition: NvInferPythonPlugin.h:195
bool setGridZ(ISymExpr *gridZ) noexcept
Set the Z dimension of the grid.
Definition: NvInferPythonPlugin.h:208
bool setBlockZ(ISymExpr *blockZ) noexcept
Set the Z dimension of each thread block.
Definition: NvInferPythonPlugin.h:247
ISymExpr * getBlockX() noexcept
Get the X dimension of each thread block.
Definition: NvInferPythonPlugin.h:214
ISymExpr * getGridX() noexcept
Get the X dimension of the grid.
Definition: NvInferPythonPlugin.h:175
ISymExpr * getSharedMem() noexcept
Get the dynamic shared-memory per thread block in bytes.
Definition: NvInferPythonPlugin.h:253
bool setBlockY(ISymExpr *blockY) noexcept
Set the Y dimension of each thread block.
Definition: NvInferPythonPlugin.h:234
ISymExpr * getGridZ() noexcept
Get the Z dimension of the grid.
Definition: NvInferPythonPlugin.h:201
bool setGridX(ISymExpr *gridX) noexcept
Set the X dimension of the grid.
Definition: NvInferPythonPlugin.h:182
bool setSharedMem(ISymExpr *sharedMem) noexcept
Set the dynamic shared-memory per thread block in bytes.
Definition: NvInferPythonPlugin.h:260
Impl class for IKernelLaunchParams.
Definition: NvInferPythonPlugin.h:140
virtual ISymExpr * getGridX() noexcept=0
Generic interface for a scalar symbolic expression implementable by a Python plugin / TensorRT Python...
Definition: NvInferPythonPlugin.h:57
virtual PluginArgType getType() const noexcept=0
Get the type of the symbolic expression.
virtual void * getExpr() noexcept=0
Underlying symbolic expression.
virtual PluginArgDataType getDataType() const noexcept=0
Get the data type of the symbolic expression.
Allows for a sequence of symbolic expressions to be communicated to the TensorRT backend.
Definition: NvInferPythonPlugin.h:86
virtual ~ISymExprs() noexcept=0
bool setNbSymExprs(int32_t count) noexcept
Set the number of symbolic expressions.
Definition: NvInferPythonPlugin.h:110
bool setSymExpr(int32_t index, ISymExpr *symExpr) noexcept
Set the symbolic expression at the given index.
Definition: NvInferPythonPlugin.h:97
int32_t getNbSymExprs() const noexcept
Get the number of symbolic expressions.
Definition: NvInferPythonPlugin.h:103
ISymExpr * getSymExpr(int32_t index) const noexcept
Get the symbolic expression at the given index.
Definition: NvInferPythonPlugin.h:90
Impl class for ISymExprs.
Definition: NvInferPythonPlugin.h:69
virtual ISymExpr * getSymExpr(int32_t index) const noexcept=0
virtual bool setSymExpr(int32_t index, ISymExpr *symExpr) noexcept=0
virtual int32_t getNbSymExprs() const noexcept=0
Version information associated with a TRT interface.
Definition: NvInferRuntimeBase.h:249
Definition: NvInferPluginBase.h:141
Definition: NvInferPluginBase.h:193
Definition: NvInferPythonPlugin.h:509
virtual IPluginV3 * createPlugin(AsciiChar const *name, AsciiChar const *nspace, PluginFieldCollection const *fc, TensorRTPhase phase, QuickPluginCreationRequest quickPluginCreationRequest) noexcept=0
Return a plugin object. Return nullptr in case of error.
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferPythonPlugin.h:511
virtual PluginFieldCollection const * getFieldNames() noexcept=0
Return a list of fields that need to be passed to createPlugin() when creating a plugin for use in th...
Definition: NvInferPluginBase.h:206
Definition: NvInferPythonPlugin.h:405
virtual int32_t setTactic(int32_t tactic) noexcept
Set the tactic to be used in the subsequent call to enqueue(). Behaves similar to IPluginV3OneRuntime...
Definition: NvInferPythonPlugin.h:458
virtual int32_t getKernel(PluginTensorDesc const *in, int32_t nbInputs, PluginTensorDesc const *out, int32_t nbOutputs, const char **kernelName, char **compiledKernel, int32_t *compiledKernelSize) noexcept=0
Get the compiled form for the kernel to be used for the specified input and output types/formats and ...
virtual int32_t getLaunchParams(DimsExprs const *inputs, DynamicPluginTensorDesc const *inOut, int32_t nbInputs, int32_t nbOutputs, IKernelLaunchParams *launchParams, ISymExprs *extraArgs, IExprBuilder &exprBuilder) noexcept=0
Get the launch parameters for the kernel to be used for the specified input and output types/formats ...
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferPythonPlugin.h:407
Definition: NvInferPythonPlugin.h:292
virtual int32_t getOutputDataTypes(DataType *outputTypes, int32_t nbOutputs, DataType const *inputTypes, int32_t const *inputRanks, int32_t nbInputs) const noexcept=0
Provide the data types of the plugin outputs if the input tensors have the data types provided.
virtual char const * getTimingCacheID() noexcept
Called to query the suffix to use for the timing cache ID. May be called anytime after plugin creatio...
Definition: NvInferPythonPlugin.h:389
virtual int32_t getValidTactics(int32_t *tactics, int32_t nbTactics) noexcept
Query for any custom tactics that the plugin intends to use specific to the I/O characteristics indic...
Definition: NvInferPythonPlugin.h:373
virtual int32_t getNbSupportedFormatCombinations(DynamicPluginTensorDesc const *inOut, int32_t nbInputs, int32_t nbOutputs) noexcept=0
Get number of format combinations supported by the plugin for the I/O characteristics indicated by in...
virtual int32_t getSupportedFormatCombinations(DynamicPluginTensorDesc const *inOut, int32_t nbInputs, int32_t nbOutputs, PluginTensorDesc *supportedCombinations, int32_t nbFormatCombinations) noexcept=0
Write all format combinations supported by the plugin for the I/O characteristics indicated by inOut ...
virtual int32_t getNbTactics() noexcept
Query for number of custom tactics related to the getValidTactics() call.
Definition: NvInferPythonPlugin.h:381
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferPythonPlugin.h:294
virtual int32_t configurePlugin(DynamicPluginTensorDesc const *in, int32_t nbInputs, DynamicPluginTensorDesc const *out, int32_t nbOutputs) noexcept=0
Configure the plugin. Behaves similarly to IPluginV3OneBuild::configurePlugin()
virtual char const * getMetadataString() noexcept
Query for a string representing the configuration of the plugin. May be called anytime after plugin c...
Definition: NvInferPythonPlugin.h:398
virtual int32_t getNbOutputs() const noexcept=0
Get the number of outputs from the plugin.
virtual int32_t getOutputShapes(DimsExprs const *inputs, int32_t nbInputs, DimsExprs const *shapeInputs, int32_t nbShapeInputs, DimsExprs *outputs, int32_t nbOutputs, IExprBuilder &exprBuilder) noexcept=0
Provide expressions for computing dimensions of the output tensors from dimensions of the input tenso...
Definition: NvInferPythonPlugin.h:277
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferPythonPlugin.h:279
virtual AsciiChar const * getPluginName() const noexcept=0
Definition: NvInferPythonPlugin.h:465
virtual int32_t enqueue(PluginTensorDesc const *inputDesc, PluginTensorDesc const *outputDesc, void const *const *inputs, void *const *outputs, Dims const *inputStrides, Dims const *outputStrides, int32_t nbInputs, int32_t nbOutputs, cudaStream_t stream) noexcept=0
Execute the plugin.
virtual int32_t setTactic(int32_t tactic) noexcept
Set the tactic to be used in the subsequent call to enqueue(). Behaves similar to IPluginV3OneRuntime...
Definition: NvInferPythonPlugin.h:478
virtual PluginFieldCollection const * getFieldsToSerialize() noexcept=0
Get the plugin fields which should be serialized.
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferPythonPlugin.h:467
The TensorRT API version 1 namespace.
Definition: NvInferSafePlugin.h:33
@ kUNKNOWN
Unknown field type.
char_t AsciiChar
Definition: NvInferRuntimeBase.h:116
TensorRTPhase
Indicates a phase of operation of TensorRT.
Definition: NvInferPluginBase.h:116
DataType
The type of weights and tensors. The datatypes other than kBOOL, kINT32, and kINT64 are "activation d...
Definition: NvInferRuntimeBase.h:151
PluginArgDataType
Data type of an extra kernel input argument in an AOT Python plugin.
Definition: NvInferPythonPlugin.h:46
@ kINT16
16-bit signed integer
@ kINT8
8-bit signed integer
@ kINT32
32-bit signed integer
PluginArgType
Numeric type of an extra kernel input argument in an AOT Python plugin.
Definition: NvInferPythonPlugin.h:38
@ kINT
Integer argument.
QuickPluginCreationRequest
Communicates preference when a quickly deployable plugin is to be added to the network.
Definition: NvInferPythonPlugin.h:125
@ kSTRICT_JIT
JIT plugin must be used. TensorRT should fail if a JIT implementation cannot be found.
@ kSTRICT_AOT
AOT plugin must be used. TensorRT should fail if an AOT implementation cannot be found.
@ kPREFER_JIT
JIT plugin is preferred.
@ kPREFER_AOT
AOT plugin is preferred.
Summarizes tensors that a plugin might see for an input or output.
Definition: NvInferRuntime.h:373
Plugin field collection struct.
Definition: NvInferPluginBase.h:103
Fields that a plugin might see for an input or output.
Definition: NvInferRuntimePlugin.h:73

  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