NVIDIA DeepStream SDK API Reference
7.1 Release
defines.h
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: Copyright (c) 2021-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 _DS3D_COMMON_DEFINES__H
14
#define _DS3D_COMMON_DEFINES__H
15
16
#include <cassert>
17
#include <fstream>
18
#include <iostream>
19
#include <memory>
20
#include <numeric>
21
22
#define ENABLE_DEBUG NvDs3dEnableDebug()
23
24
#ifndef DS3D_DISABLE_CLASS_COPY
25
#define DS3D_DISABLE_CLASS_COPY(NoCopyClass) \
26
NoCopyClass(const NoCopyClass&) = delete; \
27
void operator=(const NoCopyClass&) = delete
28
#endif
29
30
#undef DS_ASSERT
31
#define DS_ASSERT(...) assert((__VA_ARGS__))
32
33
#if defined(NDEBUG)
34
#define DS3D_FORMAT_(fmt, ...) fmt "\n", ##__VA_ARGS__
35
#else
36
#define DS3D_FORMAT_(fmt, ...) "%s:%d, " fmt "\n", __FILE__, __LINE__, ##__VA_ARGS__
37
#endif
38
39
40
#define DS3D_LOG_PRINT_(out, level, fmt, ...) \
41
fprintf(out, DS3D_FORMAT_(#level ": " fmt, ##__VA_ARGS__)); \
42
fflush(out)
43
44
#undef LOG_PRINT
45
#undef LOG_DEBUG
46
#undef LOG_ERROR
47
#undef LOG_WARNING
48
#undef LOG_INFO
49
50
#define LOG_PRINT(fmt, ...) \
51
fprintf(stdout, fmt, ##__VA_ARGS__); \
52
fflush(stdout)
53
54
#define LOG_DEBUG(fmt, ...) \
55
if (ENABLE_DEBUG) { \
56
DS3D_LOG_PRINT_(stdout, DEBUG, fmt, ##__VA_ARGS__); \
57
}
58
59
#define LOG_ERROR(fmt, ...) DS3D_LOG_PRINT_(stderr, ERROR, fmt, ##__VA_ARGS__)
60
#define LOG_WARNING(fmt, ...) DS3D_LOG_PRINT_(stderr, WARNING, fmt, ##__VA_ARGS__)
61
#define LOG_INFO(fmt, ...) DS3D_LOG_PRINT_(stdout, INFO, fmt, ##__VA_ARGS__)
62
63
// check ERROR
64
#define DS3D_FAILED_RETURN(condition, ret, fmt, ...) \
65
do { \
66
if (!(condition)) { \
67
LOG_ERROR(fmt ", check failure", ##__VA_ARGS__); \
68
return (ret); \
69
} \
70
} while (0)
71
72
#define DS3D_ERROR_RETURN(code, fmt, ...) \
73
do { \
74
ErrCode __cd = (code); \
75
DS3D_FAILED_RETURN(isGood(__cd), __cd, fmt, ##__VA_ARGS__); \
76
} while (0)
77
78
#define DS3D_THROW_ERROR(statement, code, msg) \
79
if (!(statement)) { \
80
throwError(code, msg); \
81
}
82
83
#define DS3D_THROW_ERROR_FMT(statement, code, fmt, ...) \
84
if (!(statement)) { \
85
char __smsg[2048] = {0}; \
86
snprintf(__smsg, sizeof(__smsg) - 1, fmt, ##__VA_ARGS__); \
87
throwError(code, __smsg); \
88
}
89
90
#define DS3D_CHECK_CUDA_ERROR(err, action, fmt, ...) \
91
do { \
92
cudaError_t errnum = (err); \
93
if (errnum != cudaSuccess) { \
94
LOG_ERROR( \
95
fmt ", cuda err_no:%d, err_str:%s", ##__VA_ARGS__, (int)errnum, \
96
cudaGetErrorName(errnum)); \
97
action; \
98
} \
99
} while (0)
100
101
#define DS3D_UNUSED(a) (void)(a)
102
103
#undef DS3D_TRY
104
#undef DS3D_CATCH_ERROR
105
#undef DS3D_CATCH_ANY
106
#undef DS3D_CATCH_FULL
107
108
#define DS3D_TRY try
109
110
#define DS3D_CATCH_ERROR(type, errcode, fmt, ...) \
111
catch (const type& e) \
112
{ \
113
LOG_ERROR(fmt ", catched " #type ": %s", ##__VA_ARGS__, e.what()); \
114
return errcode; \
115
}
116
117
#define DS3D_CATCH_ANY(errcode, fmt, ...) \
118
catch (...) \
119
{ \
120
LOG_ERROR(fmt ", catched unknown error", ##__VA_ARGS__); \
121
return errcode; \
122
}
123
124
#define DS3D_EXPORT_API __attribute__((__visibility__("default")))
125
#define DS3D_EXTERN_C_BEGIN extern "C" {
126
#define DS3D_EXTERN_C_END }
127
128
#define DS3D_STR_PREFIX "DS3D::"
129
#define DS3D_KEY_NAME(name) DS3D_STR_PREFIX name
130
131
#define REGISTER_TYPE_ID(uint64Id) \
132
static constexpr TIdType __typeid() { return uint64Id; }
133
134
135
#define DS3D_ROUND_UP(value, align) (((value) + (align)-1) & (~((align)-1)))
136
137
#endif // _DS3D_COMMON_DEFINES__H
Advance Information | Subject to Change | Generated by NVIDIA | Mon Oct 14 2024 13:27:44 | PR-09318-R32