TensorRT 8.5.3
nvinfer1::IPluginV2 Class Referenceabstract

Plugin class for user-implemented layers. More...

#include <NvInferRuntimeCommon.h>

Inheritance diagram for nvinfer1::IPluginV2:
nvinfer1::IPluginV2Ext nvinfer1::IPluginV2DynamicExt nvinfer1::IPluginV2IOExt

Public Member Functions

virtual int32_t getTensorRTVersion () const noexcept
 Return the API version with which this plugin was built. More...
 
virtual AsciiChar const * getPluginType () const noexcept=0
 Return the plugin type. Should match the plugin name returned by the corresponding plugin creator. More...
 
virtual AsciiChar const * getPluginVersion () const noexcept=0
 Return the plugin version. Should match the plugin version returned by the corresponding plugin creator. More...
 
virtual int32_t getNbOutputs () const noexcept=0
 Get the number of outputs from the layer. More...
 
virtual Dims getOutputDimensions (int32_t index, Dims const *inputs, int32_t nbInputDims) noexcept=0
 Get the dimension of an output tensor. More...
 
virtual bool supportsFormat (DataType type, PluginFormat format) const noexcept=0
 Check format support. More...
 
virtual void configureWithFormat (Dims const *inputDims, int32_t nbInputs, Dims const *outputDims, int32_t nbOutputs, DataType type, PluginFormat format, int32_t maxBatchSize) noexcept=0
 Configure the layer. More...
 
virtual int32_t initialize () noexcept=0
 Initialize the layer for execution. This is called when the engine is created. More...
 
virtual void terminate () noexcept=0
 Release resources acquired during plugin layer initialization. This is called when the engine is destroyed. More...
 
virtual size_t getWorkspaceSize (int32_t maxBatchSize) const noexcept=0
 Find the workspace size required by the layer. More...
 
virtual int32_t enqueue (int32_t batchSize, void const *const *inputs, void *const *outputs, void *workspace, cudaStream_t stream) noexcept=0
 Execute the layer. More...
 
virtual size_t getSerializationSize () const noexcept=0
 Find the size of the serialization buffer required. More...
 
virtual void serialize (void *buffer) const noexcept=0
 Serialize the layer. More...
 
virtual void destroy () noexcept=0
 Destroy the plugin object. This will be called when the network, builder or engine is destroyed. More...
 
virtual IPluginV2clone () const noexcept=0
 Clone the plugin object. This copies over internal plugin parameters and returns a new plugin object with these parameters. More...
 
virtual void setPluginNamespace (AsciiChar const *pluginNamespace) noexcept=0
 Set the namespace that this plugin object belongs to. Ideally, all plugin objects from the same plugin library should have the same namespace. More...
 
virtual AsciiChar const * getPluginNamespace () const noexcept=0
 Return the namespace of the plugin object. More...
 

Detailed Description

Plugin class for user-implemented layers.

Plugins are a mechanism for applications to implement custom layers. When combined with IPluginCreator it provides a mechanism to register plugins and look up the Plugin Registry during de-serialization.

See also
IPluginCreator
IPluginRegistry
Deprecated:
Deprecated in TensorRT 8.5. Implement IPluginV2DynamicExt or IPluginV2IOExt depending on your requirement.

Member Function Documentation

◆ clone()

virtual IPluginV2 * nvinfer1::IPluginV2::clone ( ) const
pure virtualnoexcept

Clone the plugin object. This copies over internal plugin parameters and returns a new plugin object with these parameters.

The TensorRT runtime calls clone() to clone the plugin when an execution context is created for an engine, after the engine has been created. The runtime does not call initialize() on the cloned plugin, so the cloned plugin should be created in an initialized state.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin or when creating multiple execution contexts.

Implemented in nvinfer1::IPluginV2DynamicExt, and nvinfer1::IPluginV2Ext.

◆ configureWithFormat()

virtual void nvinfer1::IPluginV2::configureWithFormat ( Dims const *  inputDims,
int32_t  nbInputs,
Dims const *  outputDims,
int32_t  nbOutputs,
DataType  type,
PluginFormat  format,
int32_t  maxBatchSize 
)
pure virtualnoexcept

Configure the layer.

This function is called by the builder prior to initialize(). It provides an opportunity for the layer to make algorithm choices on the basis of its weights, dimensions, and maximum batch size.

Parameters
inputDimsThe input tensor dimensions.
nbInputsThe number of inputs.
outputDimsThe output tensor dimensions.
nbOutputsThe number of outputs.
typeThe data type selected for the engine.
formatThe format selected for the engine.
maxBatchSizeThe maximum batch size.

The dimensions passed here do not include the outermost batch size (i.e. for 2-D image networks, they will be 3-dimensional CHW dimensions).

Warning
for the format field, the values PluginFormat::kCHW4, PluginFormat::kCHW16, and PluginFormat::kCHW32 will not be passed in, this is to keep backward compatibility with TensorRT 5.x series. Use PluginV2IOExt or PluginV2DynamicExt for other PluginFormats.
DataType:kBOOL and DataType::kUINT8 are not supported.
See also
clone()


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin. However, TensorRT will not call this method from two threads simultaneously on a given clone of a plugin.

Implemented in nvinfer1::IPluginV2Ext.

◆ destroy()

virtual void nvinfer1::IPluginV2::destroy ( )
pure virtualnoexcept

Destroy the plugin object. This will be called when the network, builder or engine is destroyed.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin.

◆ enqueue()

virtual int32_t nvinfer1::IPluginV2::enqueue ( int32_t  batchSize,
void const *const *  inputs,
void *const *  outputs,
void *  workspace,
cudaStream_t  stream 
)
pure virtualnoexcept

Execute the layer.

Parameters
batchSizeThe number of inputs in the batch.
inputsThe memory for the input tensors.
outputsThe memory for the output tensors.
workspaceWorkspace for execution.
streamThe stream in which to execute the kernels.
Returns
0 for success, else non-zero (which will cause engine termination).


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when multiple execution contexts are used during runtime.

◆ getNbOutputs()

virtual int32_t nvinfer1::IPluginV2::getNbOutputs ( ) const
pure virtualnoexcept

Get the number of outputs from the layer.

Returns
The number of outputs.

This function is called by the implementations of INetworkDefinition and IBuilder. In particular, it is called prior to any call to initialize().


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin.

◆ getOutputDimensions()

virtual Dims nvinfer1::IPluginV2::getOutputDimensions ( int32_t  index,
Dims const *  inputs,
int32_t  nbInputDims 
)
pure virtualnoexcept

Get the dimension of an output tensor.

Parameters
indexThe index of the output tensor.
inputsThe input tensors.
nbInputDimsThe number of input tensors.

This function is called by the implementations of INetworkDefinition and IBuilder. In particular, it is called prior to any call to initialize().


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin.
Note
In any non-IPluginV2DynamicExt plugin, batch size should not be included in the returned dimensions, even if the plugin is expected to be run in a network with explicit batch mode enabled. Please see the TensorRT Developer Guide for more details on how plugin inputs and outputs behave.

◆ getPluginNamespace()

virtual AsciiChar const * nvinfer1::IPluginV2::getPluginNamespace ( ) const
pure virtualnoexcept

Return the namespace of the plugin object.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin.

◆ getPluginType()

virtual AsciiChar const * nvinfer1::IPluginV2::getPluginType ( ) const
pure virtualnoexcept

Return the plugin type. Should match the plugin name returned by the corresponding plugin creator.

See also
IPluginCreator::getPluginName()
Warning
The string returned must be 1024 bytes or less including the NULL terminator and must be NULL terminated.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin.

◆ getPluginVersion()

virtual AsciiChar const * nvinfer1::IPluginV2::getPluginVersion ( ) const
pure virtualnoexcept

Return the plugin version. Should match the plugin version returned by the corresponding plugin creator.

See also
IPluginCreator::getPluginVersion()
Warning
The string returned must be 1024 bytes or less including the NULL terminator and must be NULL terminated.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin.

◆ getSerializationSize()

virtual size_t nvinfer1::IPluginV2::getSerializationSize ( ) const
pure virtualnoexcept

Find the size of the serialization buffer required.

Returns
The size of the serialization buffer.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin.

◆ getTensorRTVersion()

virtual int32_t nvinfer1::IPluginV2::getTensorRTVersion ( ) const
inlinevirtualnoexcept

Return the API version with which this plugin was built.

Do not override this method as it is used by the TensorRT library to maintain backwards-compatibility with plugins.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, the implementation provided here is safe to call from any thread.

Reimplemented in nvinfer1::IPluginV2DynamicExt, nvinfer1::IPluginV2Ext, and nvinfer1::IPluginV2IOExt.

◆ getWorkspaceSize()

virtual size_t nvinfer1::IPluginV2::getWorkspaceSize ( int32_t  maxBatchSize) const
pure virtualnoexcept

Find the workspace size required by the layer.

This function is called during engine startup, after initialize(). The workspace size returned should be sufficient for any batch size up to the maximum.

Returns
The workspace size.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin. However, TensorRT will not call this method from two threads simultaneously on a given clone of a plugin.

◆ initialize()

virtual int32_t nvinfer1::IPluginV2::initialize ( )
pure virtualnoexcept

Initialize the layer for execution. This is called when the engine is created.

Returns
0 for success, else non-zero (which will cause engine termination).


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin or when using multiple execution contexts using this plugin.

◆ serialize()

virtual void nvinfer1::IPluginV2::serialize ( void *  buffer) const
pure virtualnoexcept

Serialize the layer.

Parameters
bufferA pointer to a buffer to serialize data. Size of buffer must be equal to value returned by getSerializationSize.
See also
getSerializationSize()


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin.

◆ setPluginNamespace()

virtual void nvinfer1::IPluginV2::setPluginNamespace ( AsciiChar const *  pluginNamespace)
pure virtualnoexcept

Set the namespace that this plugin object belongs to. Ideally, all plugin objects from the same plugin library should have the same namespace.

Parameters
pluginNamespaceThe namespace for the plugin object.
Warning
The string pluginNamespace must be 1024 bytes or less including the NULL terminator and must be NULL terminated.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin.

◆ supportsFormat()

virtual bool nvinfer1::IPluginV2::supportsFormat ( DataType  type,
PluginFormat  format 
) const
pure virtualnoexcept

Check format support.

Parameters
typeDataType requested.
formatPluginFormat requested.
Returns
true if the plugin supports the type-format combination.

This function is called by the implementations of INetworkDefinition, IBuilder, and safe::ICudaEngine/ICudaEngine. In particular, it is called when creating an engine and when deserializing an engine.

Warning
for the format field, the values PluginFormat::kCHW4, PluginFormat::kCHW16, and PluginFormat::kCHW32 will not be passed in, this is to keep backward compatibility with TensorRT 5.x series. Use PluginV2IOExt or PluginV2DynamicExt for other PluginFormats.
DataType:kBOOL and DataType::kUINT8 are not supported.


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin.

◆ terminate()

virtual void nvinfer1::IPluginV2::terminate ( )
pure virtualnoexcept

Release resources acquired during plugin layer initialization. This is called when the engine is destroyed.

See also
initialize()


Usage considerations

  • Allowed context for the API call
    • Thread-safe: Yes, this method is required to be thread-safe and may be called from multiple threads when building networks on multiple devices sharing the same plugin or when using multiple execution contexts using this plugin. However, TensorRT will not call this method from two threads simultaneously on a given clone of a plugin.

The documentation for this class was generated from the following file: