TensorRT 11.5.0
NvInferSafePlugin.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 1993-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// Header file for the NVIDIA Safe Runtime PluginV3 interface.
19// This file provides the user-implementable interface for the PluginV3 feature in the NVIDIA Safe Runtime.
20// It includes the necessary classes, functions, and definitions for creating and managing safe plugins,
21// including the ISafePluginResourceContext, ISafePluginRegistry, IPluginV3OneSafeCore, IPluginV3OneSafeBuild,
22// IPluginV3OneSafeRuntime, and ISafePluginCreatorV3One interfaces.
23// Users should implement these interfaces to create custom plugins that can be used with in the Safe Runtime.
24
25#ifndef NV_INFER_SAFE_PLUGIN_H
26#define NV_INFER_SAFE_PLUGIN_H
27#include "NvInferForwardDecl.h"
28#include "NvInferPluginBase.h"
30#include "NvInferSafeRecorder.h"
31
32namespace nvinfer1
33{
34class DimsExprs;
35class IExprBuilder;
36} // namespace nvinfer1
37
38namespace nvinfer2
39{
40namespace safe
41{
42// Forward declaration of TensorDescriptor and RuntimeErrorInformation for the plugin interface classes
43struct RuntimeErrorInformation;
44struct TensorDescriptor;
45
61{
62public:
73 virtual ISafeMemAllocator* getSafeMemAllocator() const noexcept = 0;
74
85 virtual ISafeRecorder* getSafeRecorder() const noexcept = 0;
86
98
105 virtual ~ISafePluginResourceContext() noexcept = default;
106
107protected:
143};
144
147//
152{
153public:
179 IPluginCreatorInterface& creator, AsciiChar const* const pluginNamespace, ISafeRecorder& recorder) noexcept = 0;
180
203 IPluginCreatorInterface* const*& creators, int32_t& numCreators) const noexcept = 0;
204
230 virtual ErrorCode getCreator(IPluginCreatorInterface*& creator, AsciiChar const* const pluginName,
231 AsciiChar const* const pluginVersion, AsciiChar const* const pluginNamespace = "") noexcept = 0;
232
258 virtual ErrorCode setSafeRecorder(ISafeRecorder& recorder) noexcept = 0;
259
280 virtual ErrorCode getSafeRecorder(ISafeRecorder*& recorder) const noexcept = 0;
281
301 virtual ErrorCode deregisterCreator(IPluginCreatorInterface const& creator) noexcept = 0;
302
304 virtual ~ISafePluginRegistry() noexcept = default;
305
306 // Polymorphic base classes should not support value semantics.
309 ISafePluginRegistry& operator=(ISafePluginRegistry const&) & = delete;
310 ISafePluginRegistry& operator=(ISafePluginRegistry&&) & = delete;
311};
312
319{
320public:
326 InterfaceInfo getInterfaceInfo() const noexcept override
327 {
328 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_CORE", 1, 0};
329 }
330
333
336
339
342
344 ~IPluginV3OneSafeCore() noexcept override = default;
345
356 virtual AsciiChar const* getPluginName() const noexcept = 0;
357
368 virtual AsciiChar const* getPluginVersion() const noexcept = 0;
369
381 virtual AsciiChar const* getPluginNamespace() const noexcept = 0;
382
383protected:
386};
387
395{
396public:
401 static constexpr int32_t kDEFAULT_FORMAT_COMBINATION_LIMIT = 100;
402
410 InterfaceInfo getInterfaceInfo() const noexcept override
411 {
412 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_BUILD", 1, 0};
413 }
414
438 ~IPluginV3OneSafeBuild() noexcept override = default;
439
457 virtual int32_t configurePlugin(
458 TensorDescriptor const* in, int32_t nbInputs, TensorDescriptor const* out, int32_t nbOutputs) noexcept = 0;
459
476 virtual int32_t getOutputDataTypes(
477 DataType* outputTypes, int32_t nbOutputs, DataType const* inputTypes, int32_t nbInputs) const noexcept
478 = 0;
479
500 virtual int32_t getOutputShapes(
501 Dims const* inputs, int32_t nbInputs, Dims* outputs, int32_t nbOutputs) const noexcept = 0;
502
537 virtual bool supportsFormatCombination(
538 int32_t pos, TensorDescriptor const* inOut, int32_t nbInputs, int32_t nbOutputs) noexcept = 0;
539
545 virtual int32_t getNbOutputs() const noexcept = 0;
546
556 virtual size_t getWorkspaceSize(TensorDescriptor const* /*inputs*/, int32_t /*nbInputs*/,
557 TensorDescriptor const* /*outputs*/, int32_t /*nbOutputs*/) const noexcept
558 {
559 return 0U;
560 }
561
594 virtual int32_t getValidTactics(int32_t* /*tactics*/, int32_t /*nbTactics*/) noexcept
595 {
596 return 0;
597 }
598
602 virtual int32_t getNbTactics() noexcept
603 {
604 return 0;
605 }
606
618 virtual char const* getTimingCacheID() noexcept
619 {
620 return nullptr;
621 }
622
626 virtual int32_t getFormatCombinationLimit() noexcept
627 {
628 return kDEFAULT_FORMAT_COMBINATION_LIMIT;
629 }
630
637 virtual char const* getMetadataString() noexcept
638 {
639 return nullptr;
640 }
641
642protected:
645};
646
654{
655public:
659 InterfaceInfo getInterfaceInfo() const noexcept override
660 {
661 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_BUILDMSS", 1, 0};
662 }
663
665 Dims const* /*inputs*/, int32_t /*nbInputs*/, Dims* /*outputs*/, int32_t /*nbOutputs*/) const noexcept override
666 {
667 // This function will not be used, instead, getSymbolicOutputShapes should be used.
668 return 0;
669 }
670
673
676
679
682
684 ~IPluginV3OneSafeBuildMSS() noexcept override = default;
699 virtual int32_t getSymbolicOutputShapes(nvinfer1::DimsExprs const* inputs, int32_t nbInputs,
700 nvinfer1::DimsExprs* outputs, int32_t nbOutputs, nvinfer1::IExprBuilder& exprBuilder) const noexcept = 0;
701
702protected:
705};
706
709//
713{
714public:
720 InterfaceInfo getInterfaceInfo() const noexcept override
721 {
722 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_RUNTIME", 1, 0};
723 }
724
727
730
733
736
738 ~IPluginV3OneSafeRuntime() noexcept override = default;
739
749 virtual int32_t setTactic(int32_t /*tactic*/) noexcept
750 {
751 return 0;
752 }
753
769 virtual int32_t enqueue(TensorDescriptor const* inputDesc, TensorDescriptor const* outputDesc,
770 void const* const* inputs, void* const* outputs, void* workspace, cudaStream_t stream) noexcept = 0;
771
786 virtual int32_t initResource(ISafePluginResourceContext const* context) noexcept = 0;
787
795 virtual IPluginV3* clone() noexcept = 0;
796
804
808 virtual PluginFieldCollection const* getFieldsToSerialize() noexcept = 0;
809
810protected:
813};
814
817//
821{
822public:
828 InterfaceInfo getInterfaceInfo() const noexcept override
829 {
830 return InterfaceInfo{"PLUGIN SAFE CREATOR_V3ONE", 1, 0};
831 }
832
848 AsciiChar const* name, PluginFieldCollection const* fc, TensorRTPhase phase) noexcept = 0;
849
858 virtual PluginFieldCollection const* getFieldNames() noexcept = 0;
859
868 virtual AsciiChar const* getPluginName() const noexcept = 0;
869
878 virtual AsciiChar const* getPluginVersion() const noexcept = 0;
879
888 virtual AsciiChar const* getPluginNamespace() const noexcept = 0;
889
895 virtual ISafeRecorder* getSafeRecorder() const noexcept = 0;
896
902 virtual void setSafeRecorder(ISafeRecorder&) noexcept = 0;
903
905 ~ISafePluginCreatorV3One() noexcept override = default;
906
907protected:
910 ISafePluginCreatorV3One& operator=(ISafePluginCreatorV3One const&) & = default;
912};
913
930extern "C" nvinfer2::safe::ISafePluginRegistry* getSafePluginRegistry(nvinfer2::safe::ISafeRecorder& recorder) noexcept;
931} // namespace safe
932} // namespace nvinfer2
933
934#endif /* NV_INFER_SAFE_PLUGIN_H */
Structure to define the dimensions of a tensor.
Analog of class Dims with expressions instead of constants for the dimensions.
Definition: NvInferRuntime.h:361
Object for constructing IDimensionExpr.
Definition: NvInferRuntime.h:296
Holds version and kind information for a TensorRT interface.
Definition: NvInferRuntimeBase.h:258
Definition: NvInferPluginBase.h:149
Definition: NvInferPluginBase.h:201
Plugin class for the V3 generation of user-implemented layers.
Definition: NvInferPluginBase.h:223
Interface for plugins used during the TensorRT build phase.
Definition: NvInferSafePlugin.h:395
~IPluginV3OneSafeBuild() noexcept override=default
Destructor for IPluginV3OneSafeBuild.
IPluginV3OneSafeBuild & operator=(IPluginV3OneSafeBuild &&) &=delete
Deleted move assignment operator to maintain non-movability.
virtual int32_t getValidTactics(int32_t *, int32_t) noexcept
Query for any custom tactics that the plugin intends to use.
Definition: NvInferSafePlugin.h:594
IPluginV3OneSafeBuild(IPluginV3OneSafeBuild &&)=delete
Deleted move constructor to maintain non-movability.
virtual int32_t getNbTactics() noexcept
Query for the number of custom tactics the plugin intends to use.
Definition: NvInferSafePlugin.h:602
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: NvInferSafePlugin.h:618
virtual int32_t getFormatCombinationLimit() noexcept
Return the maximum number of format combinations that will be timed by TensorRT during the build phas...
Definition: NvInferSafePlugin.h:626
IPluginV3OneSafeBuild & operator=(IPluginV3OneSafeBuild const &) &=default
IPluginV3OneSafeBuild()=default
Default constructor.
IPluginV3OneSafeBuild(IPluginV3OneSafeBuild const &)=default
virtual char const * getMetadataString() noexcept
Query for a string representing the configuration of the plugin. May be called anytime after plugin c...
Definition: NvInferSafePlugin.h:637
InterfaceInfo getInterfaceInfo() const noexcept override
Returns version information associated with this interface.
Definition: NvInferSafePlugin.h:410
This class provides build capability and let output shapes be calculated by symbolic expression to su...
Definition: NvInferSafePlugin.h:654
IPluginV3OneSafeBuildMSS(IPluginV3OneSafeBuildMSS const &)=default
Copy constructor.
~IPluginV3OneSafeBuildMSS() noexcept override=default
Destructor for IPluginV3OneSafeBuildMSS.
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferSafePlugin.h:659
IPluginV3OneSafeBuildMSS(IPluginV3OneSafeBuildMSS &&)=delete
Move constructor.
int32_t getOutputShapes(Dims const *, int32_t, Dims *, int32_t) const noexcept override
Provide expressions for computing dimensions of the output tensors from dimensions of the input tenso...
Definition: NvInferSafePlugin.h:664
IPluginV3OneSafeBuildMSS & operator=(IPluginV3OneSafeBuildMSS const &) &=default
Copy assignment operator.
IPluginV3OneSafeBuildMSS & operator=(IPluginV3OneSafeBuildMSS &&) &=delete
Move assignment operator.
Interface specifying the base plugin capability.
Definition: NvInferSafePlugin.h:319
~IPluginV3OneSafeCore() noexcept override=default
Destructor for IPluginV3OneSafeCore.
IPluginV3OneSafeCore(IPluginV3OneSafeCore &&)=default
Move constructor.
IPluginV3OneSafeCore & operator=(IPluginV3OneSafeCore &&) &=default
Move assignment operator.
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferSafePlugin.h:326
IPluginV3OneSafeCore & operator=(IPluginV3OneSafeCore const &) &=default
Copy assignment operator.
IPluginV3OneSafeCore(IPluginV3OneSafeCore const &)=default
Copy constructor.
Runtime component of the pluginV3 system.
Definition: NvInferSafePlugin.h:713
~IPluginV3OneSafeRuntime() noexcept override=default
Destructor for IPluginV3OneSafeRuntime.
virtual int32_t enqueue(TensorDescriptor const *inputDesc, TensorDescriptor const *outputDesc, void const *const *inputs, void *const *outputs, void *workspace, cudaStream_t stream) noexcept=0
Execute the layer.
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferSafePlugin.h:720
IPluginV3OneSafeRuntime(IPluginV3OneSafeRuntime &&)=default
Move constructor.
IPluginV3OneSafeRuntime(IPluginV3OneSafeRuntime const &)=default
Copy constructor.
IPluginV3OneSafeRuntime & operator=(IPluginV3OneSafeRuntime &&) &=default
Move assignment operator.
IPluginV3OneSafeRuntime & operator=(IPluginV3OneSafeRuntime const &) &=default
Copy assignment operator.
virtual int32_t initResource(ISafePluginResourceContext const *context) noexcept=0
This function will be called to initialize a plugin object after it is created (before execution phas...
virtual IPluginV3 * clone() noexcept=0
Clone the plugin object. This copies over internal plugin parameters and returns a new plugin object ...
Application-implemented class for controlling memory allocation on the GPU/CPU.
Definition: NvInferSafeMemAllocator.h:87
The main interface to be implemented by all plugin creator classes.
Definition: NvInferSafePlugin.h:821
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...
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferSafePlugin.h:828
virtual IPluginV3 * createPlugin(AsciiChar const *name, PluginFieldCollection const *fc, TensorRTPhase phase) noexcept=0
Return a plugin object. Return nullptr in case of error.
PluginRegistry interface class that contains all the methods user can use to interface with the regis...
Definition: NvInferSafePlugin.h:152
virtual ErrorCode registerCreator(IPluginCreatorInterface &creator, AsciiChar const *const pluginNamespace, ISafeRecorder &recorder) noexcept=0
Register a plugin creator.
virtual ErrorCode getAllCreators(IPluginCreatorInterface *const *&creators, int32_t &numCreators) const noexcept=0
Return all the registered plugin creators and the number of registered plugin creators.
virtual ErrorCode getCreator(IPluginCreatorInterface *&creator, AsciiChar const *const pluginName, AsciiChar const *const pluginVersion, AsciiChar const *const pluginNamespace="") noexcept=0
Return plugin creator based on plugin name, version, and namespace associated with plugin during netw...
Interface for plugins to access per context resources provided by TensorRT.
Definition: NvInferSafePlugin.h:61
virtual ISafeRecorder * getSafeRecorder() const noexcept=0
Returns the error recorder associated with this resource context.
virtual RuntimeErrorInformation * getRuntimeErrorInformation() const noexcept=0
Returns the RuntimeErrorInformation buffer associated with this resource context.
virtual ISafeMemAllocator * getSafeMemAllocator() const noexcept=0
Returns the GPU memory allocator associated with this resource context.
Interface for extended recorder which allows error, warn, debug, or info messages to be recorded.
Definition: NvInferSafeRecorder.h:82
The TensorRT API version 1 namespace.
Definition: NvInferSafePlugin.h:33
ErrorCode
Error codes that can be returned by TensorRT during execution.
Definition: NvInferRuntimeBase.h:326
char_t AsciiChar
Definition: NvInferRuntimeBase.h:126
TensorRTPhase
Indicates a phase of operation of TensorRT.
Definition: NvInferPluginBase.h:124
DataType
The type of weights and tensors. The datatypes other than kBOOL, kINT32, and kINT64 are "activation d...
Definition: NvInferRuntimeBase.h:161
nvinfer2::safe::ISafePluginRegistry * getSafePluginRegistry(nvinfer2::safe::ISafeRecorder &recorder) noexcept
Get the SafePluginRegistry singleton instance and set the SafeRecorder of the safePluginRegistry.
Definition: NvInferConsistency.h:31
Plugin field collection struct.
Definition: NvInferPluginBase.h:111
Holds information about runtime errors that occur during asynchronous kernel execution.
Definition: NvInferSafeRecorder.h:253
A simple record summarizing various properties of a network IO Tensor.
Definition: NvInferSafeRuntime.h:281

  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