Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
NvInferRuntimeCommon.h323 linesDownload Raw Back to include
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 1993-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_RUNTIME_COMMON_H
19#define NV_INFER_RUNTIME_COMMON_H
20
21//!
22//! \file NvInferRuntimeCommon.h
23//!
24//! This file provides the nvinfer1::IPluginRegistry interface, which will be moved to the NvInferRuntime.h header
25//! in a future release.
26//!
27//! \warning This file will be removed in a future release.
28//!
29//! \warning Do not directly include this file. Instead include NvInferRuntime.h
30//!
31#define NV_INFER_INTERNAL_INCLUDE 1
32#include "NvInferPluginBase.h"
33#undef NV_INFER_INTERNAL_INCLUDE
34#include "NvInferRuntimePlugin.h"
35
36namespace nvinfer1
37{
38//!
39//! \class IPluginRegistry
40//!
41//! \brief Single registration point for all plugins in an application. It is
42//! used to find plugin implementations during engine deserialization.
43//! Internally, the plugin registry is considered to be a singleton so all
44//! plugins in an application are part of the same global registry.
45//! Note that the plugin registry is only supported for plugins of type
46//! IPluginV2 and should also have a corresponding IPluginCreator implementation.
47//!
48//! \see IPluginV2 and IPluginCreator
49//!
50//! \warning Do not inherit from this class, as doing so will break forward-compatibility of the API and ABI.
51//!
52//! \warning In the automotive safety context, be sure to call IPluginRegistry::setErrorRecorder() to register
53//! an error recorder with the registry before using other methods in the registry.
54//!
55class IPluginRegistry
56{
57public:
58    //!
59    //! \brief Pointer for plugin library handle.
60    //!
61    using PluginLibraryHandle = void*;
62
63    //!
64    //! \brief Register a plugin creator implementing IPluginCreator. Returns false if any plugin creator with the same
65    //! name, version or namespace is already registered.
66    //!
67    //! \warning The string pluginNamespace must be 1024 bytes or less including the NULL terminator and must be NULL
68    //! terminated.
69    //!
70    //! \usage
71    //! - Allowed context for the API call
72    //!   - Thread-safe: Yes; calls to this method will be synchronized by a mutex.
73    //!
74    //! \deprecated Deprecated in TensorRT 10.0. Superseded by
75    //! IPluginRegistry::registerCreator(IPluginCreatorInterface&, AsciiChar const* const).
76    //!
77    TRT_DEPRECATED virtual bool registerCreator(
78        IPluginCreator& creator, AsciiChar const* const pluginNamespace) noexcept = 0;
79
80    //!
81    //! \brief Return all the registered plugin creators and the number of
82    //! registered plugin creators. Returns nullptr if none found.
83    //!
84    //! \warning If any plugin creators are registered or deregistered after calling this function, the returned pointer
85    //! is not guaranteed to be valid thereafter.
86    //!
87    //! \usage
88    //! - Allowed context for the API call
89    //!   - Thread-safe: No
90    //!
91    //! \deprecated Deprecated in TensorRT 10.0. Superseded by IPluginRegistry::getAllCreators(int32_t* const).
92    //!
93    TRT_DEPRECATED virtual IPluginCreator* const* getPluginCreatorList(int32_t* const numCreators) const noexcept = 0;
94
95    //!
96    //! \brief Return plugin creator based on plugin name, version, and
97    //! namespace associated with plugin during network creation.
98    //!
99    //! \warning The strings pluginName, pluginVersion, and pluginNamespace must be 1024 bytes or less including the
100    //! NULL terminator and must be NULL terminated.
101    //!
102    //! \warning Returns nullptr if a plugin creator with matching name, version, and namespace is found, but is not a
103    //! descendent of IPluginCreator
104    //!
105    //! \usage
106    //! - Allowed context for the API call
107    //!   - Thread-safe: Yes
108    //!
109    //! \deprecated Deprecated in TensorRT 10.0. Superseded by IPluginRegistry::getCreator(AsciiChar const* const,
110    //! AsciiChar const* const, AsciiChar const* const).
111    //!
112    TRT_DEPRECATED virtual IPluginCreator* getPluginCreator(AsciiChar const* const pluginName,
113        AsciiChar const* const pluginVersion, AsciiChar const* const pluginNamespace = "") noexcept = 0;
114
115    // @cond SuppressDoxyWarnings
116    IPluginRegistry() = default;
117    IPluginRegistry(IPluginRegistry const&) = delete;
118    IPluginRegistry(IPluginRegistry&&) = delete;
119    IPluginRegistry& operator=(IPluginRegistry const&) & = delete;
120    IPluginRegistry& operator=(IPluginRegistry&&) & = delete;
121    // @endcond
122
123protected:
124    virtual ~IPluginRegistry() noexcept = default;
125
126public:
127    //!
128    //! \brief Set the ErrorRecorder for this interface
129    //!
130    //! Assigns the ErrorRecorder to this interface. The ErrorRecorder will track all errors during execution.
131    //! This function will call incRefCount of the registered ErrorRecorder at least once. Setting
132    //! recorder to nullptr unregisters the recorder with the interface, resulting in a call to decRefCount if
133    //! a recorder has been registered.
134    //!
135    //! \param recorder The error recorder to register with this interface.
136    //!
137    //! \see getErrorRecorder()
138    //!
139    //! \usage
140    //! - Allowed context for the API call
141    //!   - Thread-safe: No
142    //!
143    virtual void setErrorRecorder(IErrorRecorder* const recorder) noexcept = 0;
144
145    //!
146    //! \brief Get the ErrorRecorder assigned to this interface.
147    //!
148    //! Retrieves the assigned error recorder object for the given class. A default error recorder does not exist,
149    //! so a nullptr will be returned if setErrorRecorder has not been called, or an ErrorRecorder has not been
150    //! inherited.
151    //!
152    //! \return A pointer to the IErrorRecorder object that has been registered.
153    //!
154    //! \see setErrorRecorder()
155    //!
156    //! \usage
157    //! - Allowed context for the API call
158    //!   - Thread-safe: Yes
159    //!
160    virtual IErrorRecorder* getErrorRecorder() const noexcept = 0;
161
162    //!
163    //! \brief Deregister a previously registered plugin creator implementing IPluginCreator.
164    //!
165    //! Since there may be a desire to limit the number of plugins,
166    //! this function provides a mechanism for removing plugin creators registered in TensorRT.
167    //! The plugin creator that is specified by \p creator is removed from TensorRT and no longer tracked.
168    //!
169    //! \return True if the plugin creator was deregistered, false if it was not found in the registry or otherwise
170    //! could not be deregistered.
171    //!
172    //! \usage
173    //! - Allowed context for the API call
174    //!   - Thread-safe: Yes
175    //!
176    //! \deprecated Deprecated in TensorRT 10.0. Superseded by
177    //! IPluginRegistry::deregisterCreator(IPluginCreatorInterface const&).
178    //!
179    TRT_DEPRECATED virtual bool deregisterCreator(IPluginCreator const& creator) noexcept = 0;
180
181    //!
182    //! \brief Return whether the parent registry will be searched if a plugin is not found in this registry
183    //! default: true
184    //!
185    //! \return bool variable indicating whether parent search is enabled.
186    //!
187    //! \see setParentSearchEnabled
188    //!
189    virtual bool isParentSearchEnabled() const = 0;
190
191    //!
192    //! \brief Set whether the parent registry will be searched if a plugin is not found in this registry.
193    //!
194    //! \param enabled The bool variable indicating whether parent search is enabled.
195    //!
196    //! \see isParentSearchEnabled
197    //!
198    virtual void setParentSearchEnabled(bool const enabled) = 0;
199
200    //!
201    //! \brief Load and register a shared library of plugins.
202    //!
203    //! \param pluginPath the plugin library path.
204    //!
205    //! \return The loaded plugin library handle. The call will fail and return
206    //! nullptr if any of the plugins are already registered.
207    //!
208    virtual PluginLibraryHandle loadLibrary(AsciiChar const* pluginPath) noexcept = 0;
209
210    //!
211    //! \brief Deregister plugins associated with a library. Any resources acquired when the library
212    //! was loaded will be released.
213    //!
214    //! \param handle the plugin library handle to deregister.
215    //!
216    virtual void deregisterLibrary(PluginLibraryHandle handle) noexcept = 0;
217
218    //!
219    //! \brief Register a plugin creator. Returns false if a plugin creator with the same type
220    //! is already registered.
221    //!
222    //! \warning The string pluginNamespace must be 1024 bytes or less including the NULL terminator and must be NULL
223    //! terminated.
224    //!
225    //! \usage
226    //! - Allowed context for the API call
227    //!   - Thread-safe: Yes; calls to this method will be synchronized by a mutex.
228    //!
229    virtual bool registerCreator(IPluginCreatorInterface& creator, AsciiChar const* const pluginNamespace) noexcept = 0;
230
231    //!
232    //! \brief Return all registered plugin creators. Returns nullptr if none found.
233    //!
234    //! \warning If any plugin creators are registered or deregistered after calling this function, the returned pointer
235    //! is not guaranteed to be valid thereafter.
236    //!
237    //! \usage
238    //! - Allowed context for the API call
239    //!   - Thread-safe: No
240    //!
241    virtual IPluginCreatorInterface* const* getAllCreators(int32_t* const numCreators) const noexcept = 0;
242
243    //!
244    //! \brief Return a registered plugin creator based on plugin name, version, and namespace associated with the
245    //! plugin during network creation.
246    //!
247    //! \warning The strings pluginName, pluginVersion, and pluginNamespace must be 1024 bytes or less including the
248    //! NULL terminator and must be NULL terminated.
249    //!
250    //! \usage
251    //! - Allowed context for the API call
252    //!   - Thread-safe: Yes
253    //!
254    virtual IPluginCreatorInterface* getCreator(AsciiChar const* const pluginName, AsciiChar const* const pluginVersion,
255        AsciiChar const* const pluginNamespace = "") noexcept = 0;
256
257    //!
258    //! \brief Deregister a previously registered plugin creator.
259    //!
260    //! Since there may be a desire to limit the number of plugins,
261    //! this function provides a mechanism for removing plugin creators registered in TensorRT.
262    //! The plugin creator that is specified by \p creator is removed from TensorRT and no longer tracked.
263    //!
264    //! \return True if the plugin creator was deregistered, false if it was not found in the registry or otherwise
265    //! could not be deregistered.
266    //!
267    //! \usage
268    //! - Allowed context for the API call
269    //!   - Thread-safe: Yes
270    //!
271    virtual bool deregisterCreator(IPluginCreatorInterface const& creator) noexcept = 0;
272
273    //!
274    //! \brief Get a plugin resource
275    //! \param key Key for identifying the resource. Cannot be null.
276    //! \param resource A plugin resource object. The object will only need to be valid until this method returns, as
277    //! only a clone of this object will be registered by TRT. Cannot be null.
278    //!
279    //! \return Registered plugin resource object
280    //!
281    //! \usage
282    //! - Allowed context for the API call
283    //!   - Thread-safe: Yes; calls to this method will be synchronized by a mutex.
284    //!
285    virtual IPluginResource* acquirePluginResource(AsciiChar const* key, IPluginResource* resource) noexcept = 0;
286
287    //!
288    //! \brief Decrement reference count for the resource with this key
289    //!        If reference count goes to zero after decrement, release() will be invoked on the resource, the key will
290    //!        be deregistered and the resource object will be deleted
291    //!
292    //! \param key Key that was used to register the resource. Cannot be null.
293    //!
294    //! \return 0 for success, else non-zero
295    //!
296    //! \usage
297    //! - Allowed context for the API call
298    //!   - Thread-safe: Yes; calls to this method will be synchronized by a mutex.
299    //!
300    virtual int32_t releasePluginResource(AsciiChar const* key) noexcept = 0;
301
302    //!
303    //! \brief Return all registered plugin creators by searching starting from the current registry and following
304    //! parent registries recursively as long as isParentSearchEnabled() returns true.
305    //!
306    //! \param[out] numCreators Pointer to an integer where the number of registered plugin creators will be stored.
307    //!
308    //! \return A pointer to an array of IPluginCreatorInterface pointers. Returns nullptr if no creators are found.
309    //!
310    //! \warning If any plugin creators are registered or deregistered after calling this function, the returned pointer
311    //! is not guaranteed to remain valid.
312    //!
313    //! \usage
314    //! - Allowed context for the API call
315    //!   - Thread-safe: No
316    //!
317    virtual IPluginCreatorInterface* const* getAllCreatorsRecursive(int32_t* const numCreators) noexcept = 0;
318};
319
320} // namespace nvinfer1
321
322#endif /* NV_INFER_RUNTIME_COMMON_H */
323 
codekingpro/portable-devtools · Team Ai