TensorRT 11.0.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
327 ISafePluginRegistry& operator=(ISafePluginRegistry const&) & = delete;
333 ISafePluginRegistry& operator=(ISafePluginRegistry&&) & = delete;
334
335protected:
337 virtual ~ISafePluginRegistry() noexcept = default;
338};
339
346{
347public:
353 InterfaceInfo getInterfaceInfo() const noexcept override
354 {
355 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_CORE", 1, 0};
356 }
357
360
363
366
369
371 ~IPluginV3OneSafeCore() noexcept override = default;
372
383 virtual AsciiChar const* getPluginName() const noexcept = 0;
384
395 virtual AsciiChar const* getPluginVersion() const noexcept = 0;
396
408 virtual AsciiChar const* getPluginNamespace() const noexcept = 0;
409
410protected:
413};
414
422{
423public:
428 static constexpr int32_t kDEFAULT_FORMAT_COMBINATION_LIMIT = 100;
429
437 InterfaceInfo getInterfaceInfo() const noexcept override
438 {
439 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_BUILD", 1, 0};
440 }
441
465 ~IPluginV3OneSafeBuild() noexcept override = default;
466
484 virtual int32_t configurePlugin(
485 TensorDescriptor const* in, int32_t nbInputs, TensorDescriptor const* out, int32_t nbOutputs) noexcept = 0;
486
503 virtual int32_t getOutputDataTypes(
504 DataType* outputTypes, int32_t nbOutputs, DataType const* inputTypes, int32_t nbInputs) const noexcept
505 = 0;
506
527 virtual int32_t getOutputShapes(
528 Dims const* inputs, int32_t nbInputs, Dims* outputs, int32_t nbOutputs) const noexcept = 0;
529
564 virtual bool supportsFormatCombination(
565 int32_t pos, TensorDescriptor const* inOut, int32_t nbInputs, int32_t nbOutputs) noexcept = 0;
566
572 virtual int32_t getNbOutputs() const noexcept = 0;
573
583 virtual size_t getWorkspaceSize(TensorDescriptor const* /*inputs*/, int32_t /*nbInputs*/,
584 TensorDescriptor const* /*outputs*/, int32_t /*nbOutputs*/) const noexcept
585 {
586 return 0U;
587 }
588
620 virtual int32_t getValidTactics(int32_t* /*tactics*/, int32_t /*nbTactics*/) noexcept
621 {
622 return 0;
623 }
624
628 virtual int32_t getNbTactics() noexcept
629 {
630 return 0;
631 }
632
644 virtual char const* getTimingCacheID() noexcept
645 {
646 return nullptr;
647 }
648
652 virtual int32_t getFormatCombinationLimit() noexcept
653 {
654 return kDEFAULT_FORMAT_COMBINATION_LIMIT;
655 }
656
663 virtual char const* getMetadataString() noexcept
664 {
665 return nullptr;
666 }
667
668protected:
671};
672
680{
681public:
685 InterfaceInfo getInterfaceInfo() const noexcept override
686 {
687 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_BUILDMSS", 1, 0};
688 }
689
691 Dims const* /*inputs*/, int32_t /*nbInputs*/, Dims* /*outputs*/, int32_t /*nbOutputs*/) const noexcept override
692 {
693 // This function will not be used, instead, getSymbolicOutputShapes should be used.
694 return 0;
695 }
696
699
702
705
708
710 ~IPluginV3OneSafeBuildMSS() noexcept override = default;
725 virtual int32_t getSymbolicOutputShapes(nvinfer1::DimsExprs const* inputs, int32_t nbInputs,
726 nvinfer1::DimsExprs* outputs, int32_t nbOutputs, nvinfer1::IExprBuilder& exprBuilder) const noexcept = 0;
727
728protected:
731};
732
735//
739{
740public:
746 InterfaceInfo getInterfaceInfo() const noexcept override
747 {
748 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_RUNTIME", 1, 0};
749 }
750
753
756
759
762
764 ~IPluginV3OneSafeRuntime() noexcept override = default;
765
775 virtual int32_t setTactic(int32_t /*tactic*/) noexcept
776 {
777 return 0;
778 }
779
795 virtual int32_t enqueue(TensorDescriptor const* inputDesc, TensorDescriptor const* outputDesc,
796 void const* const* inputs, void* const* outputs, void* workspace, cudaStream_t stream) noexcept = 0;
797
812 virtual int32_t initResource(ISafePluginResourceContext const* context) noexcept = 0;
813
821 virtual IPluginV3* clone() noexcept = 0;
822
830
834 virtual PluginFieldCollection const* getFieldsToSerialize() noexcept = 0;
835
836protected:
839};
840
843//
847{
848public:
854 InterfaceInfo getInterfaceInfo() const noexcept override
855 {
856 return InterfaceInfo{"PLUGIN SAFE CREATOR_V3ONE", 1, 0};
857 }
858
874 AsciiChar const* name, PluginFieldCollection const* fc, TensorRTPhase phase) noexcept = 0;
875
884 virtual PluginFieldCollection const* getFieldNames() noexcept = 0;
885
894 virtual AsciiChar const* getPluginName() const noexcept = 0;
895
904 virtual AsciiChar const* getPluginVersion() const noexcept = 0;
905
914 virtual AsciiChar const* getPluginNamespace() const noexcept = 0;
915
921 virtual ISafeRecorder* getSafeRecorder() const noexcept = 0;
922
928 virtual void setSafeRecorder(ISafeRecorder&) noexcept = 0;
929
931 ~ISafePluginCreatorV3One() noexcept override = default;
932
933protected:
936 ISafePluginCreatorV3One& operator=(ISafePluginCreatorV3One const&) & = default;
938};
939
956extern "C" nvinfer2::safe::ISafePluginRegistry* getSafePluginRegistry(nvinfer2::safe::ISafeRecorder& recorder) noexcept;
957} // namespace safe
958} // namespace nvinfer2
959
960#endif /* NV_INFER_SAFE_PLUGIN_H */
Definition: NvInferRuntimeBase.h:222
Analog of class Dims with expressions instead of constants for the dimensions.
Definition: NvInferRuntime.h:350
Object for constructing IDimensionExpr.
Definition: NvInferRuntime.h:285
Version information associated with a TRT interface.
Definition: NvInferRuntimeBase.h:247
Definition: NvInferPluginBase.h:141
Definition: NvInferPluginBase.h:193
Definition: NvInferPluginBase.h:206
Interface for plugins used during the TensorRT build phase.
Definition: NvInferSafePlugin.h:422
~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:620
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:628
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:644
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:652
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:663
InterfaceInfo getInterfaceInfo() const noexcept override
Returns version information associated with this interface.
Definition: NvInferSafePlugin.h:437
This class provides build capability and let output shapes be calculated by symbolic expression to su...
Definition: NvInferSafePlugin.h:680
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:685
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:690
IPluginV3OneSafeBuildMSS & operator=(IPluginV3OneSafeBuildMSS const &) &=default
Copy assignment operator.
IPluginV3OneSafeBuildMSS & operator=(IPluginV3OneSafeBuildMSS &&) &=delete
Move assignment operator.
Interface specifying the base plugin capability.
Definition: NvInferSafePlugin.h:346
~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:353
IPluginV3OneSafeCore & operator=(IPluginV3OneSafeCore const &) &=default
Copy assignment operator.
IPluginV3OneSafeCore(IPluginV3OneSafeCore const &)=default
Copy constructor.
Runtime component of the pluginV3 system.
Definition: NvInferSafePlugin.h:739
~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:746
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:86
The main interface to be implemented by all plugin creator classes.
Definition: NvInferSafePlugin.h:847
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:854
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:315
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:149
nvinfer1::AsciiChar AsciiChar
Definition: NvInferForwardDecl.h:37
nvinfer2::safe::ISafePluginRegistry * getSafePluginRegistry(nvinfer2::safe::ISafeRecorder &recorder) noexcept
Get the SafePluginRegistry singleton instance and set the SafeRecorder of the safePluginRegistry.
Definition: NvInferConsistency.h:30
Plugin field collection struct.
Definition: NvInferPluginBase.h:103
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:285

  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