|
NVIDIA DeepStream SDK API Reference
|
6.4 Release
|
Go to the documentation of this file.
12 #ifndef __NVDSINFER_FUNC_UTILS_H__
13 #define __NVDSINFER_FUNC_UTILS_H__
20 #include <condition_variable>
24 #include <unordered_set>
27 #include <NvInferRuntime.h>
34 #define DISABLE_CLASS_COPY(NoCopyClass) \
35 NoCopyClass(const NoCopyClass&) = delete; \
36 void operator=(const NoCopyClass&) = delete
38 #define SIMPLE_MOVE_COPY(Cls) \
39 Cls& operator=(Cls&& o) { \
40 move_copy(std::move(o)); \
43 Cls(Cls&& o) { move_copy(std::move(o)); }
45 #define CHECK_NVINFER_ERROR(err, action, fmt, ...) \
47 NvDsInferStatus ifStatus = (err); \
48 if (ifStatus != NVDSINFER_SUCCESS) { \
49 auto errStr = NvDsInferStatus2Str(ifStatus); \
50 dsInferError(fmt ", nvinfer error:%s", ##__VA_ARGS__, errStr); \
55 #define RETURN_NVINFER_ERROR(err, fmt, ...) \
56 CHECK_NVINFER_ERROR(err, return ifStatus, fmt, ##__VA_ARGS__)
58 #define CHECK_CUDA_ERR_W_ACTION(err, action, fmt, ...) \
60 cudaError_t errnum = (err); \
61 if (errnum != cudaSuccess) { \
62 dsInferError(fmt ", cuda err_no:%d, err_str:%s", ##__VA_ARGS__, \
63 (int)errnum, cudaGetErrorName(errnum)); \
68 #define CHECK_CUDA_ERR_NO_ACTION(err, fmt, ...) \
69 CHECK_CUDA_ERR_W_ACTION(err, , fmt, ##__VA_ARGS__)
71 #define RETURN_CUDA_ERR(err, fmt, ...) \
72 CHECK_CUDA_ERR_W_ACTION( \
73 err, return NVDSINFER_CUDA_ERROR, fmt, ##__VA_ARGS__)
75 #define READ_SYMBOL(lib, func_name) \
76 lib->symbol<decltype(&func_name)>(#func_name)
80 inline const char*
safeStr(
const char* str)
82 return !str ?
"" : str;
85 inline const char*
safeStr(
const std::string& str)
92 return !str || strlen(str) == 0;
98 return (access(path, F_OK) != -1);
106 std::string
dims2Str(
const nvinfer1::Dims& d);
120 : std::unique_ptr<T, void (*)(T*)>(t, [](T* t) {
131 : std::shared_ptr<T>(t, [](T* t) {
140 DlLibHandle(
const std::string& path,
int mode = RTLD_LAZY);
144 const std::string&
getPath()
const {
return m_LibPath; }
146 template <
typename FuncPtr>
152 return (FuncPtr)dlsym(m_LibHandle, func);
155 template <
typename FuncPtr>
158 return symbol<FuncPtr>(func.c_str());
162 void* m_LibHandle{
nullptr};
163 const std::string m_LibPath;
167 template <
typename Container>
171 typedef typename Container::value_type
T;
174 std::unique_lock<std::mutex> lock(m_Mutex);
175 m_Queue.push_back(data);
180 std::unique_lock<std::mutex> lock(m_Mutex);
181 m_Cond.wait(lock, [
this]() {
return !m_Queue.empty(); });
182 assert(!m_Queue.empty());
183 T ret = std::move(*m_Queue.begin());
184 m_Queue.erase(m_Queue.begin());
189 std::unique_lock<std::mutex> lock(m_Mutex);
190 return m_Queue.empty();
194 std::unique_lock<std::mutex> lock(m_Mutex);
200 std::condition_variable m_Cond;
221 "Failed to get element size on Unknown datatype:%d", (
int)t);
253 bool operator<=(
const nvinfer1::Dims& a,
const nvinfer1::Dims& b);
254 bool operator>(
const nvinfer1::Dims& a,
const nvinfer1::Dims& b);
255 bool operator==(
const nvinfer1::Dims& a,
const nvinfer1::Dims& b);
256 bool operator!=(
const nvinfer1::Dims& a,
const nvinfer1::Dims& b);
272 const nvinfer1::INetworkDefinition& network);
276 nvinfer1::DeviceType
str2DeviceType(
const std::string& deviceType);
SharedPtrWDestroy(T *t=nullptr)
const std::string & getPath() const
bool isValidPrecisionType(const std::string &dataType)
nvinfer1::Dims ds2TrtDims(const NvDsInferDimsCHW &dims)
bool isValidOutputFormat(const std::string &fmt)
std::string dims2Str(const nvinfer1::Dims &d)
void normalizeDims(NvDsInferDims &dims)
DlLibHandle(const std::string &path, int mode=RTLD_LAZY)
nvinfer1::Dims CombineDimsBatch(const NvDsInferDims &dims, int batch)
bool operator>(const nvinfer1::Dims &a, const nvinfer1::Dims &b)
nvinfer1::DataType str2PrecisionType(const std::string &dataType)
Holds the dimensions of a layer.
std::string networkMode2Str(const NvDsInferNetworkMode type)
#define dsInferError(fmt,...)
nvinfer1::DataType str2DataType(const std::string &dataType)
NvDsInferDataType
Specifies the data type of a layer.
NvDsInferNetworkMode
Defines internal data formats used by the inference engine.
Copyright (c) 2019-2021, NVIDIA CORPORATION.
bool operator!=(const nvinfer1::Dims &a, const nvinfer1::Dims &b)
uint32_t str2TensorFormat(const std::string &fmt)
@ FLOAT
Specifies FP32 format.
bool hasWildcard(const nvinfer1::Dims &dims)
@ HALF
Specifies FP16 format.
@ INT32
Specifies INT32 format.
Copyright (c) 2018-2020, NVIDIA CORPORATION.
@ INT8
Specifies INT8 format.
void convertFullDims(const nvinfer1::Dims &fullDims, NvDsInferBatchDims &batchDims)
UniquePtrWDestroy(T *t=nullptr)
Holds the dimensions of a three-dimensional layer.
bool operator==(const nvinfer1::Dims &a, const nvinfer1::Dims &b)
bool operator<=(const nvinfer1::Dims &a, const nvinfer1::Dims &b)
std::string dataType2Str(const nvinfer1::DataType type)
FuncPtr symbol(const std::string &func)
bool file_accessible(const char *path)
FuncPtr symbol(const char *func)
nvinfer1::DeviceType str2DeviceType(const std::string &deviceType)
bool string_empty(const char *str)
const char * safeStr(const char *str)
NvDsInferDims trt2DsDims(const nvinfer1::Dims &dims)
void SplitFullDims(const nvinfer1::Dims &fullDims, NvDsInferDims &dims, int &batch)
uint32_t getElementSize(NvDsInferDataType t)
Get the size of the element from the data type.
std::string batchDims2Str(const NvDsInferBatchDims &d)
bool validateIOTensorNames(const BuildParams ¶ms, const nvinfer1::INetworkDefinition &network)
InferDims fullDims(int batchSize, const InferDims &in)
Extend the dimensions to include batch size.
bool isValidDeviceType(const std::string &fmt)
bool isValidOutputDataType(const std::string &dataType)