NVIDIA DeepStream SDK API Reference

7.0 Release
infer_defines.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020 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 __NVDSINFERSERVER_DEFINES_H__
14 #define __NVDSINFERSERVER_DEFINES_H__
15 
16 #include <stdarg.h>
17 #include <cassert>
18 #include <condition_variable>
19 #include <functional>
20 #include <list>
21 #include <memory>
22 #include <mutex>
23 #include <queue>
24 
25 #define DISABLE_CLASS_COPY(NoCopyClass) \
26  NoCopyClass(const NoCopyClass&) = delete; \
27  void operator=(const NoCopyClass&) = delete
28 
29 #define SIMPLE_MOVE_COPY(Cls) \
30  Cls& operator=(Cls&& o) { \
31  move_copy(std::move(o)); \
32  return *this; \
33  } \
34  Cls(Cls&& o) { move_copy(std::move(o)); }
35 
36 #define INFER_UNUSED(a) (void)(a)
37 
38 #if defined(NDEBUG)
39 #define INFER_LOG_FORMAT_(fmt) fmt
40 #else
41 #define INFER_LOG_FORMAT_(fmt) "%s:%d " fmt, __FILE__, __LINE__
42 #endif
43 
44 #define INFER_EXPORT_API __attribute__((__visibility__("default")))
45 
46 #define InferError(fmt, ...) \
47  do { \
48  dsInferLogPrint__( \
49  NVDSINFER_LOG_ERROR, INFER_LOG_FORMAT_(fmt), ##__VA_ARGS__); \
50  } while (0)
51 
52 #define InferWarning(fmt, ...) \
53  do { \
54  dsInferLogPrint__( \
55  NVDSINFER_LOG_WARNING, INFER_LOG_FORMAT_(fmt), ##__VA_ARGS__); \
56  } while (0)
57 
58 #define InferInfo(fmt, ...) \
59  do { \
60  dsInferLogPrint__( \
61  NVDSINFER_LOG_INFO, INFER_LOG_FORMAT_(fmt), ##__VA_ARGS__); \
62  } while (0)
63 
64 #define InferDebug(fmt, ...) \
65  do { \
66  dsInferLogPrint__( \
67  NVDSINFER_LOG_DEBUG, INFER_LOG_FORMAT_(fmt), ##__VA_ARGS__); \
68  } while (0)
69 
70 #define RETURN_IF_FAILED(condition, ret, fmt, ...) \
71  do { \
72  if (!(condition)) { \
73  InferError(fmt, ##__VA_ARGS__); \
74  return ret; \
75  } \
76  } while (0)
77 
78 #define CHECK_NVINFER_ERROR_PRINT(err, action, logPrint, fmt, ...) \
79  do { \
80  NvDsInferStatus ifStatus = (err); \
81  if (ifStatus != NVDSINFER_SUCCESS) { \
82  auto errStr = NvDsInferStatus2Str(ifStatus); \
83  logPrint(fmt ", nvinfer error:%s", ##__VA_ARGS__, errStr); \
84  action; \
85  } \
86  } while (0)
87 
88 #define CHECK_NVINFER_ERROR(err, action, fmt, ...) \
89  CHECK_NVINFER_ERROR_PRINT(err, action, InferError, fmt, ##__VA_ARGS__)
90 
91 #define RETURN_NVINFER_ERROR(err, fmt, ...) \
92  CHECK_NVINFER_ERROR(err, return ifStatus, fmt, ##__VA_ARGS__)
93 
94 #define CONTINUE_NVINFER_ERROR(err, fmt, ...) \
95  CHECK_NVINFER_ERROR(err, , fmt, ##__VA_ARGS__)
96 
97 
98 #define CHECK_CUDA_ERR_W_ACTION(err, action, logPrint, fmt, ...) \
99  do { \
100  cudaError_t errnum = (err); \
101  if (errnum != cudaSuccess) { \
102  logPrint(fmt ", cuda err_no:%d, err_str:%s", ##__VA_ARGS__, \
103  (int)errnum, cudaGetErrorName(errnum)); \
104  action; \
105  } \
106  } while (0)
107 
108 #define CHECK_CUDA_ERR_NO_ACTION(err, fmt, ...) \
109  CHECK_CUDA_ERR_W_ACTION(err, , InferError, fmt, ##__VA_ARGS__)
110 
111 #define RETURN_CUDA_ERR(err, fmt, ...) \
112  CHECK_CUDA_ERR_W_ACTION( \
113  err, return NVDSINFER_CUDA_ERROR, InferError, fmt, ##__VA_ARGS__)
114 
115 #define CONTINUE_CUDA_ERR(err, fmt, ...) \
116  CHECK_CUDA_ERR_NO_ACTION(err, fmt, ##__VA_ARGS__)
117 
118 #define READ_SYMBOL(lib, func_name) \
119  lib->symbol<decltype(&func_name)>(#func_name)
120 
121 #define DIVIDE_AND_ROUND_UP(a, b) ((a + b - 1) / b)
122 #define INFER_ROUND_UP(value, align) (((value) + (align)-1) & (~((align)-1)))
123 #define INFER_ROUND_DOWN(value, align) ((value) & (~((align)-1)))
124 #define INFER_WILDCARD_DIM_VALUE -1
125 #define INFER_MEM_ALIGNMENT 1024
126 
127 #endif