NVIDIA DeepStream SDK API Reference

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