TensorRT 10.16.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:
69 virtual ISafeMemAllocator* getSafeMemAllocator() const noexcept = 0;
70
77 virtual ISafeRecorder* getSafeRecorder() const noexcept = 0;
78
86
87 virtual ~ISafePluginResourceContext() noexcept = default;
88
89protected:
95};
96
99//
104{
105public:
131 IPluginCreatorInterface& creator, AsciiChar const* const pluginNamespace, ISafeRecorder& recorder) noexcept = 0;
132
155 IPluginCreatorInterface* const*& creators, int32_t& numCreators) const noexcept = 0;
156
182 virtual ErrorCode getCreator(IPluginCreatorInterface*& creator, AsciiChar const* const pluginName,
183 AsciiChar const* const pluginVersion, AsciiChar const* const pluginNamespace = "") noexcept = 0;
184
210 virtual ErrorCode setSafeRecorder(ISafeRecorder& recorder) noexcept = 0;
211
232 virtual ErrorCode getSafeRecorder(ISafeRecorder*& recorder) const noexcept = 0;
233
253 virtual ErrorCode deregisterCreator(IPluginCreatorInterface const& creator) noexcept = 0;
254
255 // @cond SuppressDoxyWarnings
256 ISafePluginRegistry() = default;
259 ISafePluginRegistry& operator=(ISafePluginRegistry const&) & = delete;
260 ISafePluginRegistry& operator=(ISafePluginRegistry&&) & = delete;
261 // @endcond
262
263protected:
264 virtual ~ISafePluginRegistry() noexcept = default;
265};
266
273{
274public:
280 InterfaceInfo getInterfaceInfo() const noexcept override
281 {
282 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_CORE", 1, 0};
283 }
284
287
290
293
296
298 ~IPluginV3OneSafeCore() noexcept override = default;
299
310 virtual AsciiChar const* getPluginName() const noexcept = 0;
311
322 virtual AsciiChar const* getPluginVersion() const noexcept = 0;
323
335 virtual AsciiChar const* getPluginNamespace() const noexcept = 0;
336
337protected:
340};
341
343{
344public:
350 static constexpr int32_t kDEFAULT_FORMAT_COMBINATION_LIMIT = 100;
351
355 InterfaceInfo getInterfaceInfo() const noexcept override
356 {
357 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_BUILD", 1, 0};
358 }
359
364 ~IPluginV3OneSafeBuild() noexcept override = default;
365
383 virtual int32_t configurePlugin(
384 TensorDescriptor const* in, int32_t nbInputs, TensorDescriptor const* out, int32_t nbOutputs) noexcept = 0;
385
402 virtual int32_t getOutputDataTypes(
403 DataType* outputTypes, int32_t nbOutputs, DataType const* inputTypes, int32_t nbInputs) const noexcept
404 = 0;
405
426 virtual int32_t getOutputShapes(
427 Dims const* inputs, int32_t nbInputs, Dims* outputs, int32_t nbOutputs) const noexcept = 0;
428
463 virtual bool supportsFormatCombination(
464 int32_t pos, TensorDescriptor const* inOut, int32_t nbInputs, int32_t nbOutputs) noexcept = 0;
465
471 virtual int32_t getNbOutputs() const noexcept = 0;
472
482 virtual size_t getWorkspaceSize(TensorDescriptor const* /*inputs*/, int32_t /*nbInputs*/,
483 TensorDescriptor const* /*outputs*/, int32_t /*nbOutputs*/) const noexcept
484 {
485 return 0U;
486 }
487
519 virtual int32_t getValidTactics(int32_t* /*tactics*/, int32_t /*nbTactics*/) noexcept
520 {
521 return 0;
522 }
523
527 virtual int32_t getNbTactics() noexcept
528 {
529 return 0;
530 }
531
543 virtual char const* getTimingCacheID() noexcept
544 {
545 return nullptr;
546 }
547
551 virtual int32_t getFormatCombinationLimit() noexcept
552 {
553 return kDEFAULT_FORMAT_COMBINATION_LIMIT;
554 }
555
562 virtual char const* getMetadataString() noexcept
563 {
564 return nullptr;
565 }
566
567protected:
570};
571
579{
580public:
584 InterfaceInfo getInterfaceInfo() const noexcept override
585 {
586 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_BUILDMSS", 1, 0};
587 }
588
590 Dims const* /*inputs*/, int32_t /*nbInputs*/, Dims* /*outputs*/, int32_t /*nbOutputs*/) const noexcept override
591 {
592 // This function will not be used, instead, getSymbolicOutputShapes should be used.
593 return 0;
594 }
595
598
601
604
607
609 ~IPluginV3OneSafeBuildMSS() noexcept override = default;
624 virtual int32_t getSymbolicOutputShapes(nvinfer1::DimsExprs const* inputs, int32_t nbInputs,
625 nvinfer1::DimsExprs* outputs, int32_t nbOutputs, nvinfer1::IExprBuilder& exprBuilder) const noexcept = 0;
626
627protected:
630};
631
634//
639{
640public:
646 InterfaceInfo getInterfaceInfo() const noexcept override
647 {
648 return InterfaceInfo{"PLUGIN_V3ONE_SAFE_RUNTIME", 1, 0};
649 }
650
653
656
659
662
664 ~IPluginV3OneSafeRuntime() noexcept override = default;
665
675 virtual int32_t setTactic(int32_t /*tactic*/) noexcept
676 {
677 return 0;
678 }
679
695 virtual int32_t enqueue(TensorDescriptor const* inputDesc, TensorDescriptor const* outputDesc,
696 void const* const* inputs, void* const* outputs, void* workspace, cudaStream_t stream) noexcept = 0;
697
712 virtual int32_t initResource(ISafePluginResourceContext const* context) noexcept = 0;
713
721 virtual IPluginV3* clone() noexcept = 0;
722
730
734 virtual PluginFieldCollection const* getFieldsToSerialize() noexcept = 0;
735
736protected:
739};
740
743//
747{
748public:
754 InterfaceInfo getInterfaceInfo() const noexcept override
755 {
756 return InterfaceInfo{"PLUGIN SAFE CREATOR_V3ONE", 1, 0};
757 }
758
774 AsciiChar const* name, PluginFieldCollection const* fc, TensorRTPhase phase) noexcept = 0;
775
784 virtual PluginFieldCollection const* getFieldNames() noexcept = 0;
785
794 virtual AsciiChar const* getPluginName() const noexcept = 0;
795
804 virtual AsciiChar const* getPluginVersion() const noexcept = 0;
805
814 virtual AsciiChar const* getPluginNamespace() const noexcept = 0;
815
821 virtual ISafeRecorder* getSafeRecorder() const noexcept = 0;
822
828 virtual void setSafeRecorder(ISafeRecorder&) noexcept = 0;
829
831 ~ISafePluginCreatorV3One() noexcept override = default;
832
833protected:
836 ISafePluginCreatorV3One& operator=(ISafePluginCreatorV3One const&) & = default;
838};
839
856extern "C" nvinfer2::safe::ISafePluginRegistry* getSafePluginRegistry(nvinfer2::safe::ISafeRecorder& recorder) noexcept;
857} // namespace safe
858} // namespace nvinfer2
859
860#endif /* NV_INFER_SAFE_PLUGIN_H */
Definition: NvInferRuntimeBase.h:219
Analog of class Dims with expressions instead of constants for the dimensions.
Definition: NvInferRuntime.h:350
Object for constructing IDimensionExpr.
Definition: NvInferRuntime.h:287
Version information associated with a TRT interface.
Definition: NvInferRuntimeBase.h:244
Definition: NvInferPluginBase.h:141
Definition: NvInferPluginBase.h:193
Definition: NvInferPluginBase.h:206
Definition: NvInferSafePlugin.h:343
~IPluginV3OneSafeBuild() noexcept override=default
Destructor for IPluginV3OneSafeBuild.
IPluginV3OneSafeBuild & operator=(IPluginV3OneSafeBuild &&) &=delete
virtual int32_t getValidTactics(int32_t *, int32_t) noexcept
Query for any custom tactics that the plugin intends to use.
Definition: NvInferSafePlugin.h:519
IPluginV3OneSafeBuild(IPluginV3OneSafeBuild &&)=delete
virtual int32_t getNbTactics() noexcept
Query for the number of custom tactics the plugin intends to use.
Definition: NvInferSafePlugin.h:527
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:543
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:551
IPluginV3OneSafeBuild & operator=(IPluginV3OneSafeBuild const &) &=default
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:562
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferSafePlugin.h:355
This class provides build capability and let output shapes be calculated by symbolic expression to su...
Definition: NvInferSafePlugin.h:579
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:584
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:589
IPluginV3OneSafeBuildMSS & operator=(IPluginV3OneSafeBuildMSS const &) &=default
Copy assignment operator.
IPluginV3OneSafeBuildMSS & operator=(IPluginV3OneSafeBuildMSS &&) &=delete
Move assignment operator.
Interface specifying the base plugin capability.
Definition: NvInferSafePlugin.h:273
~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:280
IPluginV3OneSafeCore & operator=(IPluginV3OneSafeCore const &) &=default
Copy assignment operator.
IPluginV3OneSafeCore(IPluginV3OneSafeCore const &)=default
Copy constructor.
Runtime component of the pluginV3 system, this component needs to be safety certified and is required...
Definition: NvInferSafePlugin.h:639
~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:646
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:747
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:754
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:104
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
Get the error recorder associated with the resource context.
virtual RuntimeErrorInformation * getRuntimeErrorInformation() const noexcept=0
Get the RuntimeErrorInformation associated with the resource context.
virtual ISafeMemAllocator * getSafeMemAllocator() const noexcept=0
Get the GPU allocator associated with the resource context.
Interface for extended recorder which allows error, warn, debug, or info messages to be recorded.
Definition: NvInferSafeRecorder.h:76
The TensorRT API version 1 namespace.
Definition: NvInferSafePlugin.h:33
ErrorCode
Error codes that can be returned by TensorRT during execution.
Definition: NvInferRuntimeBase.h:312
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:146
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:25
Plugin field collection struct.
Definition: NvInferPluginBase.h:103
Holds information about runtime errors that occur during asynchronous kernel execution.
Definition: NvInferSafeRecorder.h:221
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