TensorRT 8.6.0
NvInferRuntimeBase.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright (c) 1993-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 * SPDX-License-Identifier: LicenseRef-NvidiaProprietary
4 *
5 * NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
6 * property and proprietary rights in and to this material, related
7 * documentation and any modifications thereto. Any use, reproduction,
8 * disclosure or distribution of this material and related documentation
9 * without an express license agreement from NVIDIA CORPORATION or
10 * its affiliates is strictly prohibited.
11 */
12
13#ifndef NV_INFER_RUNTIME_BASE_H
14#define NV_INFER_RUNTIME_BASE_H
15
16#include "NvInferVersion.h"
17#include <cstddef>
18#include <cstdint>
19#include <cuda_runtime_api.h>
20
21// Items that are marked as deprecated will be removed in a future release.
22#if __cplusplus >= 201402L
23#define TRT_DEPRECATED [[deprecated]]
24#if __GNUC__ < 6
25#define TRT_DEPRECATED_ENUM
26#else
27#define TRT_DEPRECATED_ENUM TRT_DEPRECATED
28#endif
29#ifdef _MSC_VER
30#define TRT_DEPRECATED_API __declspec(dllexport)
31#else
32#define TRT_DEPRECATED_API [[deprecated]] __attribute__((visibility("default")))
33#endif
34#else
35#ifdef _MSC_VER
36#define TRT_DEPRECATED
37#define TRT_DEPRECATED_ENUM
38#define TRT_DEPRECATED_API __declspec(dllexport)
39#else
40#define TRT_DEPRECATED __attribute__((deprecated))
41#define TRT_DEPRECATED_ENUM
42#define TRT_DEPRECATED_API __attribute__((deprecated, visibility("default")))
43#endif
44#endif
45
46// Defines which symbols are exported
47#ifdef TENSORRT_BUILD_LIB
48#ifdef _MSC_VER
49#define TENSORRTAPI __declspec(dllexport)
50#else
51#define TENSORRTAPI __attribute__((visibility("default")))
52#endif
53#else
54#define TENSORRTAPI
55#endif
56#define TRTNOEXCEPT
65
66// forward declare some CUDA types to avoid an include dependency
67
68extern "C"
69{
71 struct cublasContext;
73 struct cudnnContext;
74}
75
76#define NV_TENSORRT_VERSION nvinfer1::kNV_TENSORRT_VERSION_IMPL
82namespace nvinfer1
83{
84
85static constexpr int32_t kNV_TENSORRT_VERSION_IMPL
86 = (NV_TENSORRT_MAJOR * 1000) + (NV_TENSORRT_MINOR * 100) + NV_TENSORRT_PATCH; // major, minor, patch
87
89using char_t = char;
90
95
97class IErrorRecorder;
99class IGpuAllocator;
100
101namespace impl
102{
104template <typename T>
106} // namespace impl
107
109template <typename T>
110constexpr int32_t EnumMax() noexcept
111{
113}
114
119enum class DataType : int32_t
120{
122 kFLOAT = 0,
123
125 kHALF = 1,
126
128 kINT8 = 2,
129
131 kINT32 = 3,
132
134 kBOOL = 4,
135
148 kUINT8 = 5,
149
153 kFP8 = 6
154
155};
156
157namespace impl
158{
160template <>
162{
163 // Declaration of kVALUE that represents maximum number of elements in DataType enum
164 static constexpr int32_t kVALUE = 7;
165};
166} // namespace impl
167
179{
180public:
182 static constexpr int32_t MAX_DIMS{8};
184 int32_t nbDims;
186 int32_t d[MAX_DIMS];
187};
188
194using Dims = Dims32;
195
208enum class TensorFormat : int32_t
209{
217 kLINEAR = 0,
218
225 kCHW2 = 1,
226
233 kHWC8 = 2,
234
250 kCHW4 = 3,
251
262 kCHW16 = 4,
263
273 kCHW32 = 5,
274
281 kDHWC8 = 6,
282
289 kCDHW32 = 7,
290
293 kHWC = 8,
294
303 kDLA_LINEAR = 9,
304
318 kDLA_HWC4 = 10,
319
326 kHWC16 = 11,
327
330 kDHWC = 12
331};
332
333namespace impl
334{
336template <>
338{
340 static constexpr int32_t kVALUE = 13;
341};
342} // namespace impl
343
344enum class AllocatorFlag : int32_t
345{
346 kRESIZABLE = 0,
347};
348
349namespace impl
350{
352template <>
354{
355 static constexpr int32_t kVALUE = 1;
356};
357} // namespace impl
358
359using AllocatorFlags = uint32_t;
360
367{
368public:
390 virtual void* allocate(uint64_t const size, uint64_t const alignment, AllocatorFlags const flags) noexcept = 0;
391
410 TRT_DEPRECATED virtual void free(void* const memory) noexcept = 0;
411
416 virtual ~IGpuAllocator() = default;
417 IGpuAllocator() = default;
418
452 virtual void* reallocate(void* /*baseAddr*/, uint64_t /*alignment*/, uint64_t /*newSize*/) noexcept
453 {
454 return nullptr;
455 }
456
477 virtual bool deallocate(void* const memory) noexcept
478 {
479 this->free(memory);
480 return true;
481 }
482
483protected:
484// @cond SuppressDoxyWarnings
485 IGpuAllocator(IGpuAllocator const&) = default;
486 IGpuAllocator(IGpuAllocator&&) = default;
487 IGpuAllocator& operator=(IGpuAllocator const&) & = default;
488 IGpuAllocator& operator=(IGpuAllocator&&) & = default;
489// @endcond
490};
491
505{
506public:
512 enum class Severity : int32_t
513 {
515 kINTERNAL_ERROR = 0,
517 kERROR = 1,
519 kWARNING = 2,
521 kINFO = 3,
523 kVERBOSE = 4,
524 };
525
538 virtual void log(Severity severity, AsciiChar const* msg) noexcept = 0;
539
540 ILogger() = default;
541 virtual ~ILogger() = default;
542
543protected:
544// @cond SuppressDoxyWarnings
545 ILogger(ILogger const&) = default;
546 ILogger(ILogger&&) = default;
547 ILogger& operator=(ILogger const&) & = default;
548 ILogger& operator=(ILogger&&) & = default;
549// @endcond
550};
551
552namespace impl
553{
555template <>
556struct EnumMaxImpl<ILogger::Severity>
557{
559 static constexpr int32_t kVALUE = 5;
560};
561} // namespace impl
562
568enum class ErrorCode : int32_t
569{
573 kSUCCESS = 0,
574
579
584 kINTERNAL_ERROR = 2,
585
591
599 kINVALID_CONFIG = 4,
600
607
613
621
630
643 kINVALID_STATE = 9,
644
656
657};
658
659namespace impl
660{
662template <>
664{
666 static constexpr int32_t kVALUE = 11;
667};
668} // namespace impl
669
694{
695public:
699 using ErrorDesc = char const*;
700
704 static constexpr size_t kMAX_DESC_LENGTH{127U};
705
709 using RefCount = int32_t;
710
711 IErrorRecorder() = default;
712 virtual ~IErrorRecorder() noexcept = default;
713
714 // Public API used to retrieve information from the error recorder.
715
734 virtual int32_t getNbErrors() const noexcept = 0;
735
753 virtual ErrorCode getErrorCode(int32_t errorIdx) const noexcept = 0;
754
774 virtual ErrorDesc getErrorDesc(int32_t errorIdx) const noexcept = 0;
775
790 virtual bool hasOverflowed() const noexcept = 0;
791
806 virtual void clear() noexcept = 0;
807
808 // API used by TensorRT to report Error information to the application.
809
830 virtual bool reportError(ErrorCode val, ErrorDesc desc) noexcept = 0;
831
848 virtual RefCount incRefCount() noexcept = 0;
849
866 virtual RefCount decRefCount() noexcept = 0;
867
868protected:
869 // @cond SuppressDoxyWarnings
870 IErrorRecorder(IErrorRecorder const&) = default;
871 IErrorRecorder(IErrorRecorder&&) = default;
872 IErrorRecorder& operator=(IErrorRecorder const&) & = default;
873 IErrorRecorder& operator=(IErrorRecorder&&) & = default;
874 // @endcond
875}; // class IErrorRecorder
876
882enum class TensorIOMode : int32_t
883{
885 kNONE = 0,
886
888 kINPUT = 1,
889
891 kOUTPUT = 2
892};
893
894namespace impl
895{
897template <>
899{
900 // Declaration of kVALUE that represents maximum number of elements in TensorIOMode enum
901 static constexpr int32_t kVALUE = 3;
902};
903} // namespace impl
904} // namespace nvinfer1
905
911extern "C" TENSORRTAPI int32_t getInferLibVersion() noexcept;
912
913#endif // NV_INFER_RUNTIME_BASE_H
#define TENSORRTAPI
Definition: NvInferRuntimeBase.h:54
int32_t getInferLibVersion() noexcept
Return the library version number.
#define TRT_DEPRECATED
Definition: NvInferRuntimeBase.h:40
#define NV_TENSORRT_MINOR
TensorRT minor version.
Definition: NvInferVersion.h:22
#define NV_TENSORRT_MAJOR
TensorRT major version.
Definition: NvInferVersion.h:21
#define NV_TENSORRT_PATCH
TensorRT patch version.
Definition: NvInferVersion.h:23
Definition: NvInferRuntimeBase.h:179
int32_t nbDims
The rank (number of dimensions).
Definition: NvInferRuntimeBase.h:184
static constexpr int32_t MAX_DIMS
The maximum rank (number of dimensions) supported for a tensor.
Definition: NvInferRuntimeBase.h:182
int32_t d[MAX_DIMS]
The extent of each dimension.
Definition: NvInferRuntimeBase.h:186
Reference counted application-implemented error reporting interface for TensorRT objects.
Definition: NvInferRuntimeBase.h:694
virtual int32_t getNbErrors() const noexcept=0
Return the number of errors.
virtual void clear() noexcept=0
Clear the error stack on the error recorder.
virtual ~IErrorRecorder() noexcept=default
char const * ErrorDesc
Definition: NvInferRuntimeBase.h:699
virtual bool hasOverflowed() const noexcept=0
Determine if the error stack has overflowed.
static constexpr size_t kMAX_DESC_LENGTH
Definition: NvInferRuntimeBase.h:704
virtual ErrorCode getErrorCode(int32_t errorIdx) const noexcept=0
Returns the ErrorCode enumeration.
int32_t RefCount
Definition: NvInferRuntimeBase.h:709
virtual RefCount decRefCount() noexcept=0
Decrements the refcount for the current ErrorRecorder.
virtual RefCount incRefCount() noexcept=0
Increments the refcount for the current ErrorRecorder.
virtual bool reportError(ErrorCode val, ErrorDesc desc) noexcept=0
Report an error to the error recorder with the corresponding enum and description.
virtual ErrorDesc getErrorDesc(int32_t errorIdx) const noexcept=0
Returns a null-terminated C-style string description of the error.
Application-implemented class for controlling allocation on the GPU.
Definition: NvInferRuntimeBase.h:367
virtual bool deallocate(void *const memory) noexcept
Definition: NvInferRuntimeBase.h:477
virtual void * reallocate(void *, uint64_t, uint64_t) noexcept
Definition: NvInferRuntimeBase.h:452
virtual ~IGpuAllocator()=default
virtual void * allocate(uint64_t const size, uint64_t const alignment, AllocatorFlags const flags) noexcept=0
virtual TRT_DEPRECATED void free(void *const memory) noexcept=0
Application-implemented logging interface for the builder, refitter and runtime.
Definition: NvInferRuntimeBase.h:505
virtual ~ILogger()=default
Severity
Definition: NvInferRuntimeBase.h:513
@ kWARNING
An application error has been discovered, but TensorRT has recovered or fallen back to a default.
@ kERROR
An application error has occurred.
@ kINFO
Informational messages with instructional information.
@ kINTERNAL_ERROR
An internal error has occurred. Execution is unrecoverable.
@ kVERBOSE
Verbose messages with debugging information.
virtual void log(Severity severity, AsciiChar const *msg) noexcept=0
The TensorRT API version 1 namespace.
ErrorCode
Error codes that can be returned by TensorRT during execution.
Definition: NvInferRuntimeBase.h:569
TensorIOMode
Definition of tensor IO Mode.
Definition: NvInferRuntimeBase.h:883
char_t AsciiChar
Definition: NvInferRuntimeBase.h:94
char char_t
char_t is the type used by TensorRT to represent all valid characters.
Definition: NvInferRuntimeBase.h:89
@ kOUTPUT
Output gate (o).
@ kINPUT
Input gate (i).
DataType
The type of weights and tensors.
Definition: NvInferRuntimeBase.h:120
@ kFLOAT
32-bit floating point format.
@ kBOOL
8-bit boolean. 0 = false, 1 = true, other values undefined.
@ kHALF
IEEE 16-bit floating-point format.
@ kINT8
Signed 8-bit integer representing a quantized floating-point value.
@ kINT32
Signed 32-bit integer format.
TensorFormat
Format of the input/output tensors.
Definition: NvInferRuntimeBase.h:209
constexpr int32_t EnumMax() noexcept
Maximum number of elements in an enumeration type.
Definition: NvInferRuntimeBase.h:110
AllocatorFlag
Definition: NvInferRuntimeBase.h:345
@ kRESIZABLE
TensorRT may call realloc() on this allocation.
uint32_t AllocatorFlags
Definition: NvInferRuntimeBase.h:359
Declaration of EnumMaxImpl struct to store maximum number of elements in an enumeration type.
Definition: NvInferRuntimeBase.h:105