TensorRT 8.4.0
NvInferSafeRuntime.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1993-2022, NVIDIA CORPORATION. All rights reserved.
3 *
4 * NOTICE TO LICENSEE:
5 *
6 * This source code and/or documentation ("Licensed Deliverables") are
7 * subject to NVIDIA intellectual property rights under U.S. and
8 * international Copyright laws.
9 *
10 * These Licensed Deliverables contained herein is PROPRIETARY and
11 * CONFIDENTIAL to NVIDIA and is being provided under the terms and
12 * conditions of a form of NVIDIA software license agreement by and
13 * between NVIDIA and Licensee ("License Agreement") or electronically
14 * accepted by Licensee. Notwithstanding any terms or conditions to
15 * the contrary in the License Agreement, reproduction or disclosure
16 * of the Licensed Deliverables to any third party without the express
17 * written consent of NVIDIA is prohibited.
18 *
19 * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
20 * LICENSE AGREEMENT, NVIDIA MAKES NO REPRESENTATION ABOUT THE
21 * SUITABILITY OF THESE LICENSED DELIVERABLES FOR ANY PURPOSE. IT IS
22 * PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND.
23 * NVIDIA DISCLAIMS ALL WARRANTIES WITH REGARD TO THESE LICENSED
24 * DELIVERABLES, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY,
25 * NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
26 * NOTWITHSTANDING ANY TERMS OR CONDITIONS TO THE CONTRARY IN THE
27 * LICENSE AGREEMENT, IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY
28 * SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY
29 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
30 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
31 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32 * OF THESE LICENSED DELIVERABLES.
33 *
34 * U.S. Government End Users. These Licensed Deliverables are a
35 * "commercial item" as that term is defined at 48 C.F.R. 2.101 (OCT
36 * 1995), consisting of "commercial computer software" and "commercial
37 * computer software documentation" as such terms are used in 48
38 * C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Government
39 * only as a commercial end item. Consistent with 48 C.F.R.12.212 and
40 * 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), all
41 * U.S. Government End Users acquire the Licensed Deliverables with
42 * only those rights set forth herein.
43 *
44 * Any use of the Licensed Deliverables in individual and commercial
45 * software must include, in the user documentation and internal
46 * comments to the code, the above Disclaimer and U.S. Government End
47 * Users Notice.
48 */
49
50#ifndef NV_INFER_SAFE_RUNTIME_H
51#define NV_INFER_SAFE_RUNTIME_H
52
54#include <cstddef>
55#include <cstdint>
56
61
67namespace nvinfer1
68{
74namespace safe
75{
77class ICudaEngine;
79class IExecutionContext;
80
92{
93public:
113 virtual ICudaEngine* deserializeCudaEngine(void const* const blob, std::size_t const size) noexcept = 0;
114
128 virtual void setGpuAllocator(IGpuAllocator* const allocator) noexcept = 0;
129
139 //
146 virtual void setErrorRecorder(IErrorRecorder* const recorder) noexcept = 0;
147
162 virtual IErrorRecorder* getErrorRecorder() const noexcept = 0;
163
164 IRuntime() = default;
165 virtual ~IRuntime() noexcept = default;
166 IRuntime(IRuntime const&) = delete;
167 IRuntime(IRuntime&&) = delete;
168 IRuntime& operator=(IRuntime const&) & = delete;
169 IRuntime& operator=(IRuntime&&) & = delete;
170};
171
180{
181public:
191 virtual std::int32_t getNbBindings() const noexcept = 0;
192
213 virtual std::int32_t getBindingIndex(AsciiChar const* const name) const noexcept = 0;
214
229 virtual AsciiChar const* getBindingName(std::int32_t const bindingIndex) const noexcept = 0;
230
243 virtual bool bindingIsInput(std::int32_t const bindingIndex) const noexcept = 0;
244
257 virtual Dims getBindingDimensions(std::int32_t const bindingIndex) const noexcept = 0;
258
271 virtual DataType getBindingDataType(std::int32_t const bindingIndex) const noexcept = 0;
272
284 virtual IExecutionContext* createExecutionContext() noexcept = 0;
285
299 virtual IExecutionContext* createExecutionContextWithoutDeviceMemory() noexcept = 0;
300
310 virtual size_t getDeviceMemorySize() const noexcept = 0;
311
325 virtual std::int32_t getBindingBytesPerComponent(std::int32_t const bindingIndex) const noexcept = 0;
326
340 virtual std::int32_t getBindingComponentsPerElement(std::int32_t const bindingIndex) const noexcept = 0;
341
351 virtual TensorFormat getBindingFormat(std::int32_t const bindingIndex) const noexcept = 0;
352
364 virtual std::int32_t getBindingVectorizedDim(std::int32_t const bindingIndex) const noexcept = 0;
365
380 virtual AsciiChar const* getName() const noexcept = 0;
381
391 //
398 virtual void setErrorRecorder(IErrorRecorder* const recorder) noexcept = 0;
399
415 virtual IErrorRecorder* getErrorRecorder() const noexcept = 0;
416
417 ICudaEngine() = default;
418 virtual ~ICudaEngine() noexcept = default;
419 ICudaEngine(ICudaEngine const&) = delete;
421 ICudaEngine& operator=(ICudaEngine const&) & = delete;
422 ICudaEngine& operator=(ICudaEngine&&) & = delete;
423};
424
432{
434 int32_t nbNanErrors;
436 int32_t nbInfErrors;
437};
438
453{
454public:
464 virtual const ICudaEngine& getEngine() const noexcept = 0;
465
480 virtual void setName(AsciiChar const* const name) noexcept = 0;
481
491 virtual AsciiChar const* getName() const noexcept = 0;
492
508 virtual void setDeviceMemory(void* const memory) noexcept = 0;
509
519 virtual Dims getStrides(std::int32_t const bindingIndex) const noexcept = 0;
520
530 //
537 virtual void setErrorRecorder(IErrorRecorder* const recorder) noexcept = 0;
538
553 virtual IErrorRecorder* getErrorRecorder() const noexcept = 0;
554
574 virtual bool enqueueV2(
575 void* const* const bindings, cudaStream_t const stream, cudaEvent_t* const inputConsumed) noexcept
576 = 0;
577
578 IExecutionContext() = default;
579 virtual ~IExecutionContext() noexcept = default;
582 IExecutionContext& operator=(IExecutionContext const&) & = delete;
583 IExecutionContext& operator=(IExecutionContext&&) & = delete;
584
604 virtual void setErrorBuffer(FloatingPointErrorInformation* const buffer) noexcept = 0;
605
617 virtual FloatingPointErrorInformation* getErrorBuffer() const noexcept = 0;
618};
619
630
639
651template <typename T>
653{
654public:
656 {
657 getSafePluginRegistry()->registerCreator(instance, "");
658 }
659
660private:
662 T instance{};
663};
664
665} // namespace safe
666
667} // namespace nvinfer1
668
669#define REGISTER_SAFE_TENSORRT_PLUGIN(name) \
670 static nvinfer1::safe::PluginRegistrar<name> pluginRegistrar##name {}
671#endif // NV_INFER_SAFE_RUNTIME_H
#define TENSORRTAPI
Definition: NvInferRuntimeCommon.h:91
Definition: NvInferRuntimeCommon.h:190
Reference counted application-implemented error reporting interface for TensorRT objects.
Definition: NvInferRuntimeCommon.h:1699
Application-implemented class for controlling allocation on the GPU.
Definition: NvInferRuntimeCommon.h:1372
Application-implemented logging interface for the builder, refitter and runtime.
Definition: NvInferRuntimeCommon.h:1510
Single registration point for all plugins in an application. It is used to find plugin implementation...
Definition: NvInferRuntimeCommon.h:1244
virtual bool registerCreator(IPluginCreator &creator, AsciiChar const *const pluginNamespace) noexcept=0
Register a plugin creator. Returns false if one with same type is already registered.
A functionally safe engine for executing inference on a built network.
Definition: NvInferSafeRuntime.h:180
virtual std::int32_t getNbBindings() const noexcept=0
Get the number of binding indices.
Functionally safe context for executing inference using an engine.
Definition: NvInferSafeRuntime.h:453
virtual const ICudaEngine & getEngine() const noexcept=0
Get the associated engine.
Allows a serialized functionally safe engine to be deserialized.
Definition: NvInferSafeRuntime.h:92
virtual ICudaEngine * deserializeCudaEngine(void const *const blob, std::size_t const size) noexcept=0
Deserialize an engine from a stream.
virtual IErrorRecorder * getErrorRecorder() const noexcept=0
Get the ErrorRecorder assigned to this interface.
virtual void setGpuAllocator(IGpuAllocator *const allocator) noexcept=0
Set the GPU allocator.
virtual void setErrorRecorder(IErrorRecorder *const recorder) noexcept=0
Set the ErrorRecorder for this interface.
Register the plugin creator to the registry The static registry object will be instantiated when the ...
Definition: NvInferSafeRuntime.h:653
PluginRegistrar()
Definition: NvInferSafeRuntime.h:655
IRuntime * createInferRuntime(ILogger &logger) noexcept
Create an instance of an safe::IRuntime class.
nvinfer1::IPluginRegistry * getSafePluginRegistry() noexcept
Return the safe plugin registry.
The TensorRT API version 1 namespace.
char_t AsciiChar
AsciiChar is the type used by TensorRT to represent valid ASCII characters.
Definition: NvInferRuntimeCommon.h:125
DataType
The type of weights and tensors.
Definition: NvInferRuntimeCommon.h:151
TensorFormat
Format of the input/output tensors.
Definition: NvInferRuntimeCommon.h:221
Space to record information about floating point runtime errors.
Definition: NvInferSafeRuntime.h:432
int32_t nbInfErrors
Total count of errors relating to INF values (0 if none)
Definition: NvInferSafeRuntime.h:436
int32_t nbNanErrors
Total count of errors relating to NAN values (0 if none)
Definition: NvInferSafeRuntime.h:434