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