TensorRT 10.2.0
NvInferRuntimeBase.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_RUNTIME_BASE_H
19#define NV_INFER_RUNTIME_BASE_H
20
21#include "NvInferVersion.h"
22#include <cstddef>
23#include <cstdint>
24#include <cuda_runtime_api.h>
25
26// Items that are marked as deprecated will be removed in a future release.
27#if __cplusplus >= 201402L
28#define TRT_DEPRECATED [[deprecated]]
29#if __GNUC__ < 6
30#define TRT_DEPRECATED_ENUM
31#else
32#define TRT_DEPRECATED_ENUM TRT_DEPRECATED
33#endif
34#ifdef _MSC_VER
35#define TRT_DEPRECATED_API __declspec(dllexport)
36#else
37#define TRT_DEPRECATED_API [[deprecated]] __attribute__((visibility("default")))
38#endif
39#else
40#ifdef _MSC_VER
41#define TRT_DEPRECATED
42#define TRT_DEPRECATED_ENUM
43#define TRT_DEPRECATED_API __declspec(dllexport)
44#else
45#define TRT_DEPRECATED __attribute__((deprecated))
46#define TRT_DEPRECATED_ENUM
47#define TRT_DEPRECATED_API __attribute__((deprecated, visibility("default")))
48#endif
49#endif
50
51// Defines which symbols are exported
52#ifdef TENSORRT_BUILD_LIB
53#ifdef _MSC_VER
54#define TENSORRTAPI __declspec(dllexport)
55#else
56#define TENSORRTAPI __attribute__((visibility("default")))
57#endif
58#else
59#define TENSORRTAPI
60#endif
61#define TRTNOEXCEPT
73#if !defined(NV_INFER_INTERNAL_INCLUDE_RUNTIME_BASE)
74static_assert(false, "Do not directly include this file. Include NvInferRuntime.h or NvInferSafeRuntime.h or NvInferConsistency.h or NvInferPluginUtils.h");
75#endif
76
78
79extern "C"
80{
82 struct cublasContext;
84 struct cudnnContext;
85}
86
89#define NV_TENSORRT_VERSION_INT(major, minor, patch) ((major) *10000L + (minor) *100L + (patch) *1L)
90
93#define NV_TENSORRT_VERSION NV_TENSORRT_VERSION_INT(NV_TENSORRT_MAJOR, NV_TENSORRT_MINOR, NV_TENSORRT_PATCH)
94
100namespace nvinfer1
101{
103using char_t = char;
104
108
110namespace v_1_0
111{
112class IErrorRecorder;
113}
115
116namespace impl
117{
119template <typename T>
121} // namespace impl
122
124template <typename T>
125constexpr int32_t EnumMax() noexcept
126{
128}
129
134enum class DataType : int32_t
135{
137 kFLOAT = 0,
138
140 kHALF = 1,
141
143 kINT8 = 2,
144
146 kINT32 = 3,
147
149 kBOOL = 4,
150
163 kUINT8 = 5,
164
167 kFP8 = 6,
168
170 kBF16 = 7,
171
173 kINT64 = 8,
174
176 kINT4 = 9,
177
178};
179
180namespace impl
181{
183template <>
185{
187 static constexpr int32_t kVALUE = 10;
188};
189} // namespace impl
190
202{
203public:
205 static constexpr int32_t MAX_DIMS{8};
206
208 int32_t nbDims;
209
211 int64_t d[MAX_DIMS];
212};
213
217using Dims = Dims64;
218
249enum class TensorFormat : int32_t
250{
256 kLINEAR = 0,
257
262 kCHW2 = 1,
263
267 kHWC8 = 2,
268
282 kCHW4 = 3,
283
291 kCHW16 = 4,
292
300 kCHW32 = 5,
301
306 kDHWC8 = 6,
307
312 kCDHW32 = 7,
313
317 kHWC = 8,
318
327 kDLA_LINEAR = 9,
328
342 kDLA_HWC4 = 10,
343
348 kHWC16 = 11,
349
354 kDHWC = 12
355};
356
357using InterfaceKind = char const*;
358
365{
366public:
368 int32_t major;
369 int32_t minor;
370};
371
377enum class APILanguage : int32_t
378{
379 kCPP = 0,
380 kPYTHON = 1
381};
382
383namespace impl
384{
386template <>
388{
390 static constexpr int32_t kVALUE = 2;
391};
392} // namespace impl
393
400{
401public:
407 virtual APILanguage getAPILanguage() const noexcept
408 {
409 return APILanguage::kCPP;
410 }
411
415 virtual InterfaceInfo getInterfaceInfo() const noexcept = 0;
416
417 virtual ~IVersionedInterface() noexcept = default;
418
419protected:
423 IVersionedInterface& operator=(IVersionedInterface const&) & = default;
424 IVersionedInterface& operator=(IVersionedInterface&&) & = default;
425};
426
427namespace impl
428{
430template <>
432{
434 static constexpr int32_t kVALUE = 13;
435};
436} // namespace impl
437
438
444enum class AllocatorFlag : int32_t
445{
447 kRESIZABLE = 0,
448};
449
450namespace impl
451{
453template <>
455{
457 static constexpr int32_t kVALUE = 1;
458};
459} // namespace impl
460
461using AllocatorFlags = uint32_t;
462
465namespace v_1_0
466{
467
469{
470public:
496 uint64_t const size, uint64_t const alignment, AllocatorFlags const flags) noexcept = 0;
497
498 ~IGpuAllocator() override = default;
499 IGpuAllocator() = default;
500
538 virtual void* reallocate(void* const /*baseAddr*/, uint64_t /*alignment*/, uint64_t /*newSize*/) noexcept
539 {
540 return nullptr;
541 }
542
561 TRT_DEPRECATED virtual bool deallocate(void* const memory) noexcept = 0;
562
591 virtual void* allocateAsync(
592 uint64_t const size, uint64_t const alignment, AllocatorFlags const flags, cudaStream_t /*stream*/) noexcept
593 {
594 return allocate(size, alignment, flags);
595 }
624 virtual bool deallocateAsync(void* const memory, cudaStream_t /*stream*/) noexcept
625 {
626 return deallocate(memory);
627 }
628
632 InterfaceInfo getInterfaceInfo() const noexcept override
633 {
634 return {"IGpuAllocator", 1, 0};
635 }
636
637protected:
638 // @cond SuppressDoxyWarnings
639 IGpuAllocator(IGpuAllocator const&) = default;
640 IGpuAllocator(IGpuAllocator&&) = default;
641 IGpuAllocator& operator=(IGpuAllocator const&) & = default;
642 IGpuAllocator& operator=(IGpuAllocator&&) & = default;
643 // @endcond
644};
645
646} // namespace v_1_0
647
669
683{
684public:
690 enum class Severity : int32_t
691 {
693 kINTERNAL_ERROR = 0,
695 kERROR = 1,
697 kWARNING = 2,
699 kINFO = 3,
701 kVERBOSE = 4,
702 };
703
722 virtual void log(Severity severity, AsciiChar const* msg) noexcept = 0;
723
724 ILogger() = default;
725 virtual ~ILogger() = default;
726
727protected:
728// @cond SuppressDoxyWarnings
729 ILogger(ILogger const&) = default;
730 ILogger(ILogger&&) = default;
731 ILogger& operator=(ILogger const&) & = default;
732 ILogger& operator=(ILogger&&) & = default;
733// @endcond
734};
735
736namespace impl
737{
739template <>
740struct EnumMaxImpl<ILogger::Severity>
741{
743 static constexpr int32_t kVALUE = 5;
744};
745} // namespace impl
746
752enum class ErrorCode : int32_t
753{
757 kSUCCESS = 0,
758
763
768 kINTERNAL_ERROR = 2,
769
775
783 kINVALID_CONFIG = 4,
784
791
797
805
814
827 kINVALID_STATE = 9,
828
840
841};
842
843namespace impl
844{
846template <>
848{
850 static constexpr int32_t kVALUE = 11;
851};
852} // namespace impl
853
854namespace v_1_0
855{
857{
858public:
862 InterfaceInfo getInterfaceInfo() const noexcept override
863 {
864 return InterfaceInfo{"IErrorRecorder", 1, 0};
865 }
866
870 using ErrorDesc = char const*;
871
877 static constexpr size_t kMAX_DESC_LENGTH{127U};
878
882 using RefCount = int32_t;
883
884 IErrorRecorder() = default;
885 ~IErrorRecorder() noexcept override = default;
886
887 // Public API used to retrieve information from the error recorder.
888
912 virtual int32_t getNbErrors() const noexcept = 0;
913
932 virtual ErrorCode getErrorCode(int32_t errorIdx) const noexcept = 0;
933
955 virtual ErrorDesc getErrorDesc(int32_t errorIdx) const noexcept = 0;
956
971 virtual bool hasOverflowed() const noexcept = 0;
972
987 virtual void clear() noexcept = 0;
988
989 // API used by TensorRT to report Error information to the application.
990
1017 virtual bool reportError(ErrorCode val, ErrorDesc desc) noexcept = 0;
1018
1035 virtual RefCount incRefCount() noexcept = 0;
1036
1053 virtual RefCount decRefCount() noexcept = 0;
1054
1055protected:
1056 // @cond SuppressDoxyWarnings
1057 IErrorRecorder(IErrorRecorder const&) = default;
1058 IErrorRecorder(IErrorRecorder&&) = default;
1059 IErrorRecorder& operator=(IErrorRecorder const&) & = default;
1060 IErrorRecorder& operator=(IErrorRecorder&&) & = default;
1061 // @endcond
1062}; // class IErrorRecorder
1063} // namespace v_1_0
1064
1092using IErrorRecorder = v_1_0::IErrorRecorder;
1093
1099enum class TensorIOMode : int32_t
1100{
1102 kNONE = 0,
1103
1105 kINPUT = 1,
1106
1108 kOUTPUT = 2
1109};
1110
1111namespace v_1_0
1112{
1114{
1115public:
1120 ~IStreamReader() override = default;
1121 IStreamReader() = default;
1122
1126 InterfaceInfo getInterfaceInfo() const noexcept override
1127 {
1128 return InterfaceInfo{"IStreamReader", 1, 0};
1129 }
1130
1139 virtual int64_t read(void* destination, int64_t nbBytes) = 0;
1140
1141protected:
1142 IStreamReader(IStreamReader const&) = default;
1146};
1147} // namespace v_1_0
1148
1158
1159namespace v_1_0
1160{
1161
1163{
1164public:
1168 InterfaceInfo getInterfaceInfo() const noexcept override
1169 {
1170 return InterfaceInfo{"IPluginResource", 1, 0};
1171 }
1185 virtual int32_t release() noexcept = 0;
1186
1199 virtual IPluginResource* clone() noexcept = 0;
1200
1201 ~IPluginResource() noexcept override = default;
1202
1203 IPluginResource() = default;
1206 IPluginResource& operator=(IPluginResource const&) & = default;
1207 IPluginResource& operator=(IPluginResource&&) & = default;
1208}; // class IPluginResource
1209} // namespace v_1_0
1210
1220
1221namespace impl
1222{
1224template <>
1226{
1227 // Declaration of kVALUE that represents maximum number of elements in TensorIOMode enum
1228 static constexpr int32_t kVALUE = 3;
1229};
1230} // namespace impl
1231} // namespace nvinfer1
1232
1238extern "C" TENSORRTAPI int32_t getInferLibVersion() noexcept;
1239
1240#endif // NV_INFER_RUNTIME_BASE_H
#define TENSORRTAPI
Definition: NvInferRuntimeBase.h:59
int32_t getInferLibVersion() noexcept
Return the library version number.
#define TRT_DEPRECATED
Definition: NvInferRuntimeBase.h:45
Definition: NvInferRuntimeBase.h:202
static constexpr int32_t MAX_DIMS
The maximum rank (number of dimensions) supported for a tensor.
Definition: NvInferRuntimeBase.h:205
int64_t d[MAX_DIMS]
The extent of each dimension.
Definition: NvInferRuntimeBase.h:211
int32_t nbDims
The rank (number of dimensions).
Definition: NvInferRuntimeBase.h:208
Application-implemented logging interface for the builder, refitter and runtime.
Definition: NvInferRuntimeBase.h:683
virtual ~ILogger()=default
Severity
The severity corresponding to a log message.
Definition: NvInferRuntimeBase.h:691
virtual void log(Severity severity, AsciiChar const *msg) noexcept=0
A callback implemented by the application to handle logging messages;.
An Interface class for version control.
Definition: NvInferRuntimeBase.h:400
virtual InterfaceInfo getInterfaceInfo() const noexcept=0
Return version information associated with this interface. Applications must not override this method...
virtual APILanguage getAPILanguage() const noexcept
The language used to build the implementation of this Interface.
Definition: NvInferRuntimeBase.h:407
IVersionedInterface & operator=(IVersionedInterface const &) &=default
Version information associated with a TRT interface.
Definition: NvInferRuntimeBase.h:365
InterfaceKind kind
Definition: NvInferRuntimeBase.h:367
int32_t major
Definition: NvInferRuntimeBase.h:368
int32_t minor
Definition: NvInferRuntimeBase.h:369
Definition: NvInferRuntimeBase.h:857
char const * ErrorDesc
A typedef of a C-style string for reporting error descriptions.
Definition: NvInferRuntimeBase.h:870
~IErrorRecorder() noexcept override=default
int32_t RefCount
A typedef of a 32-bit integer for reference counting.
Definition: NvInferRuntimeBase.h:882
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferRuntimeBase.h:862
Definition: NvInferRuntimeBase.h:469
virtual void * allocateAsync(uint64_t const size, uint64_t const alignment, AllocatorFlags const flags, cudaStream_t) noexcept
A thread-safe callback implemented by the application to handle stream-ordered acquisition of GPU mem...
Definition: NvInferRuntimeBase.h:591
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferRuntimeBase.h:632
virtual TRT_DEPRECATED bool deallocate(void *const memory) noexcept=0
A thread-safe callback implemented by the application to handle release of GPU memory.
~IGpuAllocator() override=default
virtual void * reallocate(void *const, uint64_t, uint64_t) noexcept
A thread-safe callback implemented by the application to resize an existing allocation.
Definition: NvInferRuntimeBase.h:538
virtual TRT_DEPRECATED void * allocate(uint64_t const size, uint64_t const alignment, AllocatorFlags const flags) noexcept=0
A thread-safe callback implemented by the application to handle acquisition of GPU memory.
virtual bool deallocateAsync(void *const memory, cudaStream_t) noexcept
A thread-safe callback implemented by the application to handle stream-ordered release of GPU memory.
Definition: NvInferRuntimeBase.h:624
Definition: NvInferRuntimeBase.h:1163
virtual int32_t release() noexcept=0
Free the underlying resource.
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferRuntimeBase.h:1168
Definition: NvInferRuntimeBase.h:1114
~IStreamReader() override=default
IStreamReader & operator=(IStreamReader const &) &=default
IStreamReader & operator=(IStreamReader &&) &=default
virtual int64_t read(void *destination, int64_t nbBytes)=0
Read the next number of bytes in the stream.
IStreamReader(IStreamReader &&)=default
IStreamReader(IStreamReader const &)=default
InterfaceInfo getInterfaceInfo() const noexcept override
Return version information associated with this interface. Applications must not override this method...
Definition: NvInferRuntimeBase.h:1126
The TensorRT API version 1 namespace.
ErrorCode
Error codes that can be returned by TensorRT during execution.
Definition: NvInferRuntimeBase.h:753
TensorIOMode
Definition of tensor IO Mode.
Definition: NvInferRuntimeBase.h:1100
@ kOUTPUT
Tensor is output by the engine.
@ kINPUT
Tensor is input to the engine.
APILanguage
Programming language used in the implementation of a TRT interface.
Definition: NvInferRuntimeBase.h:378
char_t AsciiChar
Definition: NvInferRuntimeBase.h:107
char char_t
char_t is the type used by TensorRT to represent all valid characters.
Definition: NvInferRuntimeBase.h:103
DataType
The type of weights and tensors.
Definition: NvInferRuntimeBase.h:135
@ kINT64
Signed 64-bit integer type.
@ kFLOAT
32-bit floating point format.
@ kBOOL
8-bit boolean. 0 = false, 1 = true, other values undefined.
@ kHALF
IEEE 16-bit floating-point format – has a 5 bit exponent and 11 bit significand.
@ kINT8
Signed 8-bit integer representing a quantized floating-point value.
@ kBF16
Brain float – has an 8 bit exponent and 8 bit significand.
@ kINT4
Signed 4-bit integer type.
@ kINT32
Signed 32-bit integer format.
char const * InterfaceKind
Definition: NvInferRuntimeBase.h:357
v_1_0::IGpuAllocator IGpuAllocator
Definition: NvInferRuntimeBase.h:668
TensorFormat
Format of the input/output tensors.
Definition: NvInferRuntimeBase.h:250
constexpr int32_t EnumMax() noexcept
Maximum number of elements in an enumeration type.
Definition: NvInferRuntimeBase.h:125
v_1_0::IStreamReader IStreamReader
Definition: NvInferRuntimeBase.h:1157
AllocatorFlag
Allowed type of memory allocation.
Definition: NvInferRuntimeBase.h:445
@ kRESIZABLE
TensorRT may call realloc() on this allocation.
v_1_0::IErrorRecorder IErrorRecorder
Definition: NvInferRuntimeBase.h:114
uint32_t AllocatorFlags
Definition: NvInferRuntimeBase.h:461
Declaration of EnumMaxImpl struct to store maximum number of elements in an enumeration type.
Definition: NvInferRuntimeBase.h:120

  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