Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes16kdownloads
NvInferPluginBase.h292 linesDownload Raw Back to include
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2024-2025 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 NV_INFER_PLUGIN_BASE_H
19#define NV_INFER_PLUGIN_BASE_H
20
21#if !defined(NV_INFER_INTERNAL_INCLUDE)
22static_assert(false, "Do not directly include this file. Include NvInferRuntime.h or NvInferPluginUtils.h");
23#endif
24
25#define NV_INFER_INTERNAL_INCLUDE 1
26#include "NvInferRuntimeBase.h" // IWYU pragma: exports
27#undef NV_INFER_INTERNAL_INCLUDE
28namespace nvinfer1
29{
30
31//!
32//! \enum PluginFieldType
33//!
34//! \brief The possible field types for custom layer.
35//!
36enum class PluginFieldType : int32_t
37{
38    //! FP16 field type.
39    kFLOAT16 = 0,
40    //! FP32 field type.
41    kFLOAT32 = 1,
42    //! FP64 field type.
43    kFLOAT64 = 2,
44    //! INT8 field type.
45    kINT8 = 3,
46    //! INT16 field type.
47    kINT16 = 4,
48    //! INT32 field type.
49    kINT32 = 5,
50    //! char field type.
51    kCHAR = 6,
52    //! nvinfer1::Dims field type.
53    kDIMS = 7,
54    //! Unknown field type.
55    kUNKNOWN = 8,
56    //! BF16 field type.
57    kBF16 = 9,
58    //! INT64 field type.
59    kINT64 = 10,
60    //! FP8 field type.
61    kFP8 = 11,
62    //! INT4 field type.
63    kINT4 = 12,
64    //! FP4 field type.
65    kFP4 = 13,
66};
67
68//!
69//! \class PluginField
70//!
71//! \brief Structure containing plugin attribute field names and associated data
72//! This information can be parsed to decode necessary plugin metadata
73//!
74//!
75class PluginField
76{
77public:
78    //! Plugin field attribute name
79    AsciiChar const* name;
80    //! Plugin field attribute data
81    void const* data;
82    //! Plugin field attribute type
83    PluginFieldType type;
84    //! Number of data entries in the Plugin attribute
85    int32_t length;
86
87    PluginField(AsciiChar const* const name_ = nullptr, void const* const data_ = nullptr,
88        PluginFieldType const type_ = PluginFieldType::kUNKNOWN, int32_t const length_ = 0) noexcept
89        : name(name_)
90        , data(data_)
91        , type(type_)
92        , length(length_)
93    {
94    }
95};
96
97//!
98//! \struct PluginFieldCollection
99//!
100//! \brief Plugin field collection struct.
101//!
102struct PluginFieldCollection
103{
104    //! Number of PluginField entries.
105    int32_t nbFields{};
106    //! Pointer to PluginField entries.
107    PluginField const* fields{};
108};
109
110//!
111//! \enum TensorRTPhase
112//!
113//! \brief Indicates a phase of operation of TensorRT
114//!
115enum class TensorRTPhase : int32_t
116{
117    //! Build phase of TensorRT
118    kBUILD = 0,
119    //! Execution phase of TensorRT
120    kRUNTIME = 1
121};
122
123//!
124//! \enum PluginCapabilityType
125//!
126//! \brief Enumerates the different capability types a IPluginV3 object may have
127//!
128enum class PluginCapabilityType : int32_t
129{
130    //! Core capability. Every IPluginV3 object must have this.
131    kCORE = 0,
132    //! Build capability. IPluginV3 objects provided to TensorRT build phase must have this.
133    kBUILD = 1,
134    //! Runtime capability. IPluginV3 objects provided to TensorRT build and execution phases must have this.
135    kRUNTIME = 2
136};
137
138namespace v_1_0
139{
140class IPluginCapability : public IVersionedInterface
141{
142};
143
144class IPluginResource : public IVersionedInterface
145{
146public:
147    //!
148    //! \brief Return version information associated with this interface. Applications must not override this method.
149    //!
150    InterfaceInfo getInterfaceInfo() const noexcept override
151    {
152        return InterfaceInfo{"IPluginResource", 1, 0};
153    }
154    //!
155    //! \brief Free the underlying resource
156    //!
157    //! This will only be called for IPluginResource objects that were produced from IPluginResource::clone()
158    //!
159    //! The IPluginResource object on which release() is called must still be in a clone-able state
160    //! after release() returns
161    //!
162    //! \return 0 for success, else non-zero
163    //! \usage
164    //! - Allowed context for the API call
165    //!   - Thread-safe: No; this method is not required to be thread-safe
166    //!
167    virtual int32_t release() noexcept = 0;
168
169    //!
170    //! \brief Clone the resource object
171    //!
172    //! \note Resource initialization (if any) may be skipped for non-cloned objects since only clones will be
173    //! registered by TensorRT
174    //!
175    //! \return Pointer to cloned object. nullptr if there was an issue.
176    //!
177    //! \usage
178    //! - Allowed context for the API call
179    //!   - Thread-safe: Yes; this method is required to be thread-safe and may be called from multiple threads.
180    //!
181    virtual IPluginResource* clone() noexcept = 0;
182
183    ~IPluginResource() noexcept override = default;
184
185    IPluginResource() = default;
186    IPluginResource(IPluginResource const&) = default;
187    IPluginResource(IPluginResource&&) = default;
188    IPluginResource& operator=(IPluginResource const&) & = default;
189    IPluginResource& operator=(IPluginResource&&) & = default;
190}; // class IPluginResource
191
192class IPluginCreatorInterface : public IVersionedInterface
193{
194public:
195    ~IPluginCreatorInterface() noexcept override = default;
196
197protected:
198    IPluginCreatorInterface() = default;
199    IPluginCreatorInterface(IPluginCreatorInterface const&) = default;
200    IPluginCreatorInterface(IPluginCreatorInterface&&) = default;
201    IPluginCreatorInterface& operator=(IPluginCreatorInterface const&) & = default;
202    IPluginCreatorInterface& operator=(IPluginCreatorInterface&&) & = default;
203};
204
205class IPluginV3 : public IVersionedInterface
206{
207public:
208    //!
209    //! \brief Return version information associated with this interface. Applications must not override this method.
210    //!
211    InterfaceInfo getInterfaceInfo() const noexcept override
212    {
213        return InterfaceInfo{"PLUGIN", 1, 0};
214    }
215
216    //! \brief Return a pointer to plugin object implementing the specified PluginCapabilityType.
217    //!
218    //! \note IPluginV3 objects added for the build phase (through addPluginV3()) must return valid objects for
219    //! PluginCapabilityType::kCORE, PluginCapabilityType::kBUILD and PluginCapabilityType::kRUNTIME.
220    //!
221    //! \note IPluginV3 objects added for the runtime phase must return valid objects for
222    //! PluginCapabilityType::kCORE and PluginCapabilityType::kRUNTIME.
223    //!
224    //! \see TensorRTPhase
225    //! \see IPluginCreatorV3One::createPlugin()
226    //!
227    virtual IPluginCapability* getCapabilityInterface(PluginCapabilityType type) noexcept = 0;
228
229    //!
230    //! \brief Clone the plugin object. This copies over internal plugin parameters and returns a new plugin object with
231    //! these parameters. The cloned object must be in a fully initialized state.
232    //!
233    //! \note The cloned object must return valid objects through getCapabilityInterface() for at least the same
234    //! PluginCapabilityTypes as the original object.
235    //!
236    //! \return A cloned plugin object in an initialized state with the same parameters as the current object.
237    //!         nullptr must be returned if the cloning fails.
238    //!
239    virtual IPluginV3* clone() noexcept = 0;
240};
241} // namespace v_1_0
242
243//!
244//! \class IPluginResource
245//!
246//! \brief Interface for plugins to define custom resources that could be shared through the plugin registry
247//!
248//! \see IPluginRegistry::acquirePluginResource
249//! \see IPluginRegistry::releasePluginResource
250//!
251using IPluginResource = v_1_0::IPluginResource;
252
253//!
254//! \class IPluginCreatorInterface
255//!
256//! \brief Base class for all plugin creator versions.
257//!
258//! \see IPluginCreator and IPluginRegistry
259//!
260using IPluginCreatorInterface = v_1_0::IPluginCreatorInterface;
261
262//!
263//! \class IPluginV3
264//!
265//! \brief Plugin class for the V3 generation of user-implemented layers.
266//!
267//! IPluginV3 acts as a wrapper around the plugin capability interfaces that define the actual behavior of the plugin.
268//!
269//! \see IPluginCapability
270//! \see IPluginCreatorV3One
271//! \see IPluginRegistry
272//!
273using IPluginV3 = v_1_0::IPluginV3;
274
275//!
276//! \class IPluginCapability
277//!
278//! \brief Base class for plugin capability interfaces
279//!
280//!  IPluginCapability represents a split in TensorRT V3 plugins to sub-objects that expose different types of
281//!  capabilites a plugin may have, as opposed to a single interface which defines all capabilities and behaviors of a
282//!  plugin.
283//!
284//! \warning Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.
285//!
286//! \see PluginCapabilityType
287//!
288using IPluginCapability = v_1_0::IPluginCapability;
289} // namespace nvinfer1
290
291#endif /* NV_INFER_PLUGIN_BASE_H */
292 
codekingpro/portable-devtools · Team Ai