TensorRT 10.0.1
NvInferSafeRuntime.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 1993-2024 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_SAFE_RUNTIME_H
19#define NV_INFER_SAFE_RUNTIME_H
20
21#define NV_INFER_INTERNAL_INCLUDE_RUNTIME_BASE 1
22#include "NvInferRuntimeBase.h"
23#undef NV_INFER_INTERNAL_INCLUDE_RUNTIME_BASE
25#include <cstddef>
26#include <cstdint>
27
32
38namespace nvinfer1
39{
45namespace safe
46{
48class ICudaEngine;
50class IExecutionContext;
51
63{
64public:
88 virtual ICudaEngine* deserializeCudaEngine(void const* const blob, std::size_t const size) noexcept = 0;
89
100 virtual void setGpuAllocator(IGpuAllocator* const allocator) noexcept = 0;
101
119 virtual void setErrorRecorder(IErrorRecorder* const recorder) noexcept = 0;
120
136 virtual IErrorRecorder* getErrorRecorder() const noexcept = 0;
137
138 IRuntime() = default;
139 virtual ~IRuntime() noexcept = default;
140 IRuntime(IRuntime const&) = delete;
141 IRuntime(IRuntime&&) = delete;
142 IRuntime& operator=(IRuntime const&) & = delete;
143 IRuntime& operator=(IRuntime&&) & = delete;
144};
145
154{
155public:
174
193 virtual IExecutionContext* createExecutionContextWithoutDeviceMemory() noexcept = 0;
194
208 virtual size_t getDeviceMemorySize() const noexcept = 0;
209
225 virtual AsciiChar const* getName() const noexcept = 0;
226
243 virtual void setErrorRecorder(IErrorRecorder* const recorder) noexcept = 0;
244
261 virtual IErrorRecorder* getErrorRecorder() const noexcept = 0;
262
263 ICudaEngine() = default;
264 virtual ~ICudaEngine() noexcept = default;
265 ICudaEngine(ICudaEngine const&) = delete;
267 ICudaEngine& operator=(ICudaEngine const&) & = delete;
268 ICudaEngine& operator=(ICudaEngine&&) & = delete;
269
287 virtual Dims getTensorShape(AsciiChar const* const tensorName) const noexcept = 0;
288
306 virtual DataType getTensorDataType(AsciiChar const* const tensorName) const noexcept = 0;
307
326 virtual TensorIOMode getTensorIOMode(AsciiChar const* const tensorName) const noexcept = 0;
327
349 virtual std::int32_t getTensorBytesPerComponent(AsciiChar const* const tensorName) const noexcept = 0;
350
371 virtual std::int32_t getTensorComponentsPerElement(AsciiChar const* const tensorName) const noexcept = 0;
372
390 virtual TensorFormat getTensorFormat(AsciiChar const* const tensorName) const noexcept = 0;
391
412 virtual std::int32_t getTensorVectorizedDim(AsciiChar const* const tensorName) const noexcept = 0;
413
425 virtual std::int32_t getNbIOTensors() const noexcept = 0;
426
445 virtual AsciiChar const* getIOTensorName(std::int32_t const index) const noexcept = 0;
446};
447
458{
460 uint64_t bitMask;
461};
462
466enum class RuntimeErrorType : uint64_t
467{
469 kNAN_CONSUMED = 1ULL << 0,
471 kINF_CONSUMED = 1ULL << 1,
473 kGATHER_OOB = 1ULL << 2,
475 kSCATTER_OOB = 1ULL << 3,
477 kSCATTER_RACE = 1ULL << 4,
478};
479
494{
495public:
505 virtual ICudaEngine const& getEngine() const noexcept = 0;
506
522 virtual void setName(AsciiChar const* const name) noexcept = 0;
523
536 virtual AsciiChar const* getName() const noexcept = 0;
537
559 virtual void setDeviceMemory(void* const memory) noexcept = 0;
560
578 virtual void setErrorRecorder(IErrorRecorder* const recorder) noexcept = 0;
579
595 virtual IErrorRecorder* getErrorRecorder() const noexcept = 0;
596
597 IExecutionContext() = default;
598 virtual ~IExecutionContext() noexcept = default;
601 IExecutionContext& operator=(IExecutionContext const&) & = delete;
602 IExecutionContext& operator=(IExecutionContext&&) & = delete;
603
624 virtual void setErrorBuffer(RuntimeErrorInformation* const buffer) noexcept = 0;
625
637 virtual RuntimeErrorInformation* getErrorBuffer() const noexcept = 0;
638
660 virtual Dims getTensorStrides(AsciiChar const* const tensorName) const noexcept = 0;
661
690 virtual bool setInputTensorAddress(AsciiChar const* const tensorName, void const* const data) noexcept = 0;
691
719 virtual bool setOutputTensorAddress(AsciiChar const* const tensorName, void* const data) noexcept = 0;
720
735 virtual bool setInputConsumedEvent(cudaEvent_t const event) noexcept = 0;
736
747 virtual cudaEvent_t getInputConsumedEvent() const noexcept = 0;
748
767 virtual void const* getInputTensorAddress(AsciiChar const* const tensorName) const noexcept = 0;
768
787 virtual void* getOutputTensorAddress(AsciiChar const* const tensorName) const noexcept = 0;
788
808 virtual bool enqueueV3(cudaStream_t const stream) noexcept = 0;
809};
810
828
830{
831public:
855 virtual bool registerCreator(IPluginCreator& creator, AsciiChar const* const pluginNamespace) noexcept = 0;
856
870 virtual IPluginCreator* const* getPluginCreatorList(int32_t* const numCreators) const noexcept = 0;
871
894 virtual IPluginCreator* getPluginCreator(AsciiChar const* const pluginName, AsciiChar const* const pluginVersion,
895 AsciiChar const* const pluginNamespace = "") noexcept = 0;
896
913 virtual void setErrorRecorder(IErrorRecorder* const recorder) noexcept = 0;
914
932 virtual IErrorRecorder* getErrorRecorder() const noexcept = 0;
933
951 virtual bool deregisterCreator(IPluginCreator const& creator) noexcept = 0;
952
953 // @cond SuppressDoxyWarnings
954 IPluginRegistry() = default;
955 IPluginRegistry(IPluginRegistry const&) = delete;
957 IPluginRegistry& operator=(IPluginRegistry const&) & = delete;
958 IPluginRegistry& operator=(IPluginRegistry&&) & = delete;
959 // @endcond
960
961protected:
962 virtual ~IPluginRegistry() noexcept = default;
963};
964
980
989
1001template <typename T>
1003{
1004public:
1006 {
1007 getSafePluginRegistry()->registerCreator(instance, "");
1008 }
1009
1010private:
1012 T instance{};
1013};
1014
1015} // namespace safe
1016
1017} // namespace nvinfer1
1018
1019#define REGISTER_SAFE_TENSORRT_PLUGIN(name) \
1020 static nvinfer1::safe::PluginRegistrar<name> pluginRegistrar##name {}
1021#endif // NV_INFER_SAFE_RUNTIME_H
#define TENSORRTAPI
Definition: NvInferRuntimeBase.h:59
Definition: NvInferRuntimeBase.h:201
Application-implemented logging interface for the builder, refitter and runtime.
Definition: NvInferRuntimeBase.h:682
A functionally safe engine for executing inference on a built network.
Definition: NvInferSafeRuntime.h:154
virtual IExecutionContext * createExecutionContext() noexcept=0
Create an execution context.
Functionally safe context for executing inference using an engine.
Definition: NvInferSafeRuntime.h:494
virtual ICudaEngine const & getEngine() const noexcept=0
Get the associated engine.
Single registration point for all plugins in an application. It is used to find plugin implementation...
Definition: NvInferSafeRuntime.h:830
virtual IPluginCreator * getPluginCreator(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...
virtual IPluginCreator *const * getPluginCreatorList(int32_t *const numCreators) const noexcept=0
Return all the registered plugin creators and the number of registered plugin creators....
virtual bool registerCreator(IPluginCreator &creator, AsciiChar const *const pluginNamespace) noexcept=0
Register a plugin creator.
Allows a serialized functionally safe engine to be deserialized.
Definition: NvInferSafeRuntime.h:63
virtual ICudaEngine * deserializeCudaEngine(void const *const blob, std::size_t const size) noexcept=0
Deserialize an engine from a byte array.
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:1003
PluginRegistrar()
Definition: NvInferSafeRuntime.h:1005
Definition: NvInferRuntimeBase.h:856
Definition: NvInferRuntimeBase.h:468
Definition: NvInferRuntimePlugin.h:946
IPluginRegistry * getSafePluginRegistry() noexcept
Return the safe plugin registry.
RuntimeErrorType
Enum to represent runtime error types.
Definition: NvInferSafeRuntime.h:467
@ kNAN_CONSUMED
NaN floating-point value was silently consumed.
@ kSCATTER_OOB
Out-of-bounds access in scatter operation.
@ kGATHER_OOB
Out-of-bounds access in gather operation.
@ kINF_CONSUMED
Inf floating-point value was silently consumed.
@ kSCATTER_RACE
Race condition in scatter operation.
IRuntime * createInferRuntime(ILogger &logger) noexcept
Create an instance of a safe::IRuntime class.
The TensorRT API version 1 namespace.
TensorIOMode
Definition of tensor IO Mode.
Definition: NvInferRuntimeBase.h:1099
char_t AsciiChar
Definition: NvInferRuntimeBase.h:107
DataType
The type of weights and tensors.
Definition: NvInferRuntimeBase.h:135
TensorFormat
Format of the input/output tensors.
Definition: NvInferRuntimeBase.h:249
Space to record information about runtime errors.
Definition: NvInferSafeRuntime.h:458
uint64_t bitMask
Each bit represents a RuntimeErrorType that has occurred during kernel execution.
Definition: NvInferSafeRuntime.h:460

  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