NVIDIA DeepStream SDK API Reference

9.1 Release
sources/libs/nvdsinferserver/infer_utils.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2019-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 
25 #ifndef __NVDSINFER_SERVER_INFER_UTILS_H__
26 #define __NVDSINFER_SERVER_INFER_UTILS_H__
27 
28 #include <infer_batch_buffer.h>
29 #include <infer_common.h>
30 #include <infer_datatypes.h>
31 
32 #include <algorithm>
33 #include <iomanip>
34 #include <iostream>
35 #include <limits>
36 #include <numeric>
37 
39 
44 void dsInferLogPrint__(NvDsInferLogLevel level, const char* fmt, ...);
45 
61 void dsInferLogVPrint__(NvDsInferLogLevel level, const char* fmt, va_list args);
62 
63 
69 inline const char* safeStr(const char* str) {
70  return !str ? "" : str;
71 }
72 
73 inline const char* safeStr(const std::string& str) {
74  return str.c_str();
75 }
82 inline bool string_empty(const char* str) {
83  return !str || strlen(str) == 0;
84 }
85 
91 inline bool file_accessible(const char* path) {
92  assert(path);
93  return (access(path, F_OK) != -1);
94 }
95 
96 inline bool file_accessible(const std::string& path) {
97  return (!path.empty()) && file_accessible(path.c_str());
98 }
104 template <typename T>
105 inline bool
107 {
108  return b == 0;
109 }
110 
116 std::string dims2Str(const InferDims& d);
117 std::string batchDims2Str(const InferBatchDims& d);
118 std::string dataType2Str(const InferDataType type);
119 std::string dataType2GrpcStr(const InferDataType type);
120 InferDataType grpcStr2DataType(const std::string &type);
122  const InferDims& d, InferTensorOrder order);
123 std::string tensorOrder2Str(InferTensorOrder order);
130 bool fEqual(float a, float b);
131 
135 class DlLibHandle {
136 public:
142  DlLibHandle(const std::string& path, int mode = RTLD_LAZY);
143 
144  /*
145  * @brief Destructor. Close the dynamically loaded library.
146  */
147  ~DlLibHandle();
148 
149  /*
150  * @brief Check that the library handle is valid.
151  */
152  bool isValid() const { return m_LibHandle; }
153 
154  /*
155  * @brief Get the filename of the library.
156  */
157  const std::string& getPath() const { return m_LibPath; }
158 
159  /*
160  * @brief Get the function pointer from the library for given function
161  * name.
162  */
164  template <typename FuncPtr>
165  FuncPtr symbol(const char* func) {
166  assert(!string_empty(func));
167  if (!m_LibHandle)
168  return nullptr;
169  InferDebug("lib: %s dlsym :%s", safeStr(m_LibPath), safeStr(func));
170  return (FuncPtr)dlsym(m_LibHandle, func);
171  }
172 
173  template <typename FuncPtr>
174  FuncPtr symbol(const std::string& func) {
175  return symbol<FuncPtr>(func.c_str());
176  }
179 private:
180  /*
181  * @brief Handle for the library returned by dlopen().
182  */
183  void* m_LibHandle{nullptr};
184  /*
185  * @brief Filename of the dynamically loaded library.
186  */
187  const std::string m_LibPath;
188 };
189 
193 class WakeupException : public std::exception {
194  std::string m_Msg;
195 
196 public:
197  WakeupException(const std::string& s) : m_Msg(s) {}
198  const char* what() const noexcept override { return m_Msg.c_str(); }
199 };
200 
207 template <typename Container>
208 class GuardQueue {
209 public:
210  typedef typename Container::value_type T;
214  void push(T data) {
215  std::unique_lock<std::mutex> lock(m_Mutex);
216  m_Queue.emplace_back(std::move(data));
217  m_Cond.notify_one();
218  }
225  T pop() {
226  std::unique_lock<std::mutex> lock(m_Mutex);
227  m_Cond.wait(
228  lock, [this]() { return m_WakeupOnce || !m_Queue.empty(); });
229  if (m_WakeupOnce) {
230  m_WakeupOnce = false;
231  InferDebug("GuardQueue pop end on wakeup signal");
232  throw WakeupException("GuardQueue stopped");
233  }
234  assert(!m_Queue.empty());
235  T ret = std::move(*m_Queue.begin());
236  m_Queue.erase(m_Queue.begin());
237  return ret;
238  }
242  void wakeupOnce() {
243  InferDebug("GuardQueue trigger wakeup once");
244  std::unique_lock<std::mutex> lock(m_Mutex);
245  m_WakeupOnce = true;
246  m_Cond.notify_all();
247  }
251  void clear() {
252  InferDebug("GuardQueue clear");
253  std::unique_lock<std::mutex> lock(m_Mutex);
254  m_Queue.clear();
255  m_WakeupOnce = false;
256  }
260  int size() {
261  std::unique_lock<std::mutex> lock(m_Mutex);
262  return m_Queue.size();
263  }
264 
265 private:
269  std::mutex m_Mutex;
273  std::condition_variable m_Cond;
277  Container m_Queue;
281  bool m_WakeupOnce = false;
282 };
283 
291 template <typename Container>
292 class QueueThread {
293 public:
294  using Item = typename Container::value_type;
295  using RunFunc = std::function<bool(Item)>;
296 
304  QueueThread(RunFunc runFunc, const std::string& name) : m_Run(runFunc) {
305  std::promise<void> p;
306  std::future<void> f = p.get_future();
307  InferDebug("QueueThread starting new thread");
308  m_Thread = std::thread([&p, this]() {
309  p.set_value();
310  this->threadLoop();
311  });
312  setThreadName(name);
313  f.wait();
314  }
319  void setThreadName(const std::string &name) {
320  assert(!name.empty());
321  m_Name = name;
322  if (m_Thread.joinable()) {
323  const int kMakLen = 16;
324  char cName[kMakLen];
325  strncpy(cName, name.c_str(), kMakLen);
326  cName[kMakLen - 1] = 0;
327  if (pthread_setname_np(m_Thread.native_handle(), cName) != 0) {
328  InferError("set thread name: %s failed", safeStr(name));
329  return;
330  }
331  InferDebug("QueueThread set new thread name:%s", cName);
332  }
333  }
338  ~QueueThread() { join(); }
339  void join() {
340  InferDebug("QueueThread: %s join", safeStr(m_Name));
341  if (m_Thread.joinable()) {
342  m_Queue.wakeupOnce();
343  m_Thread.join();
344  }
345  m_Queue.clear();
346  }
350  bool queueItem(Item item) {
351  m_Queue.push(std::move(item));
352  return true;
353  }
354 
355 private:
363  void threadLoop() {
364  while (true) {
365  try {
366  Item item = m_Queue.pop();
367  if (!m_Run(std::move(item))) {
368  InferDebug("QueueThread:%s return and stop", safeStr(m_Name));
369  return;
370  }
371  }
372  catch (const WakeupException& e) {
373  InferDebug("QueueThread:%s stopped", safeStr(m_Name));
374  return;
375  }
376  catch (...) { // unexpected
377  InferError(
378  "QueueThread:%s internal unexpected error, may cause stop",
379  safeStr(m_Name));
380  // Usually can move on to next, but need developer to check
381  continue;
382  }
383  }
384  }
385 
386 private:
390  std::thread m_Thread;
394  std::string m_Name;
398  RunFunc m_Run;
402  GuardQueue<Container> m_Queue;
403 };
404 
409 template <class UniPtr>
410 class BufferPool : public std::enable_shared_from_this<BufferPool<UniPtr> > {
411 public:
412  using ItemType = typename UniPtr::element_type;
413  using RecylePtr = std::unique_ptr<ItemType, std::function<void(ItemType*)>>;
417  BufferPool(const std::string &name)
418  : m_Name(name) {}
422  virtual ~BufferPool()
423  {
424  InferDebug(
425  "BufferPool: %s deleted with free buffer size:%d", safeStr(m_Name),
426  m_FreeBuffers.size());
427  }
433  bool setBuffer(UniPtr buf) {
434  assert(buf);
435  buf->reuse();
436  m_FreeBuffers.push(std::move(buf));
437  InferDebug("BufferPool: %s set buf to free, available size:%d",
438  safeStr(m_Name), m_FreeBuffers.size());
439  return true;
440  }
444  int size() { return m_FreeBuffers.size(); }
445 
456  try {
457  UniPtr p = m_FreeBuffers.pop();
458  auto deleter = p.get_deleter();
459  std::weak_ptr<BufferPool<UniPtr>> poolPtr =
460  this->shared_from_this();
461  RecylePtr recBuf(
462  p.release(), [poolPtr, d = deleter](ItemType* buf) {
463  assert(buf);
464  UniPtr data(buf, d);
465  auto pool = poolPtr.lock();
466  if (pool) {
467  InferDebug("BufferPool: %s release a buffer", safeStr(pool->m_Name));
468  pool->setBuffer(std::move(data));
469  } else {
470  InferError("BufferPool is deleted, check internal error.");
471  assert(false);
472  }
473  });
474  InferDebug("BufferPool: %s acquired buffer, available free buffer left:%d",
475  safeStr(m_Name), m_FreeBuffers.size());
476  return recBuf;
477  } catch (...) {
478  InferDebug(
479  "BufferPool: %s acquired buffer failed, queue maybe waked up.",
480  safeStr(m_Name));
481  assert(false);
482  return nullptr;
483  }
484  }
485 
486 private:
490  GuardQueue<std::deque<UniPtr>> m_FreeBuffers;
494  const std::string m_Name;
495 };
496 
497 template <class UniPtr>
498 using SharedBufPool = std::shared_ptr<BufferPool<UniPtr>>;
499 
505 template<typename Key, typename UniqBuffer>
507 public:
510 public:
514  MapBufferPool(const std::string &name): m_Name(name) {}
518  virtual ~MapBufferPool()
519  {
520  InferDebug(
521  "MapBufferPool: %s deleted with buffer pool size:%d",
522  safeStr(m_Name), (int)m_MapPool.size());
523  }
524 
527  MapBufferPool(const MapBufferPool& other) = delete;
528  MapBufferPool& operator=(const MapBufferPool& other) = delete;
541  bool setBuffer(const Key &key, UniqBuffer buf) {
542  std::unique_lock<std::shared_timed_mutex> uniqLock(m_MapPoolMutex);
543  assert(buf);
544  SharedPool &pool = m_MapPool[key];
545  if(!pool) {
546  uint32_t id = m_MapPool.size() - 1;
547  std::string poolName = m_Name + std::to_string(id);
548  pool = std::make_shared<BufferPool<UniqBuffer>>(poolName);
549  assert(pool);
550  InferDebug("MapBufferPool: %s create new pool id:%d",
551  safeStr(m_Name), id);
552  }
553  if(!pool) {
554  return false;
555  }
556  return pool->setBuffer(std::move(buf));
557  }
563  uint32_t getPoolSize(const Key &key) {
564  SharedPool pool = findPool(key);
565  if (!pool)
566  return 0;
567  return pool->size();
568  }
569 
576  RecylePtr acquireBuffer(const Key &key) {
577  SharedPool pool = findPool(key);
578  assert(pool);
579  if (!pool) {
580  InferWarning(
581  "MapBufferPool: %s acquire buffer failed, no key found",
582  safeStr(m_Name));
583  return nullptr;
584  }
585  InferDebug("MapBufferPool: %s acquire buffer", safeStr(m_Name));
586  return pool->acquireBuffer();
587  }
591  void clear() {
592  InferDebug("MapBufferPool: %s clear all buffers", safeStr(m_Name));
593  std::unique_lock<std::shared_timed_mutex> uniqLock(m_MapPoolMutex);
594  m_MapPool.clear();
595  }
596 
597 private:
601  SharedPool findPool(const Key& key) {
602  std::shared_lock<std::shared_timed_mutex> sharedLock(m_MapPoolMutex);
603  auto iter = m_MapPool.find(key);
604  if (iter != m_MapPool.end()) {
605  assert(iter->second);
606  return iter->second;
607  }
608  return nullptr;
609  }
610 
611 private:
615  std::map<Key, SharedPool> m_MapPool;
619  std::shared_timed_mutex m_MapPoolMutex;
623  const std::string m_Name;
624 };
625 
629 inline uint32_t getElementSize(InferDataType t) {
630  switch (t) {
631  case InferDataType::kInt32:
632  case InferDataType::kUint32:
633  case InferDataType::kFp32:
634  return 4;
635  case InferDataType::kFp16:
636  case InferDataType::kInt16:
637  case InferDataType::kUint16:
638  return 2;
639  case InferDataType::kInt8:
640  case InferDataType::kUint8:
641  case InferDataType::kBool:
642  return 1;
643  case InferDataType::kString:
644  return 0;
645  case InferDataType::kFp64:
646  case InferDataType::kInt64:
647  case InferDataType::kUint64:
648  return 8;
649  default:
650  InferError("Failed to get element size on Unknown datatype:%d",
651  static_cast<int>(t));
652  return 0;
653  }
654 }
655 
660 inline bool
661 hasWildcard(const InferDims& dims)
662 {
663  return std::any_of(
664  dims.d, dims.d + dims.numDims,
665  [](int d) { return d <= INFER_WILDCARD_DIM_VALUE; });
666 }
667 
674 inline size_t
675 dimsSize(const InferDims& dims)
676 {
677  if (hasWildcard(dims) || !dims.numDims) {
678  return 0;
679  } else {
680  return std::accumulate(
681  dims.d, dims.d + dims.numDims, 1,
682  [](int s, int i) { return s * i; });
683  }
684 }
685 
690 inline void
691 normalizeDims(InferDims& dims)
692 {
693  dims.numElements = dimsSize(dims);
694 }
695 
700 bool operator<=(const InferDims& a, const InferDims& b);
701 bool operator>(const InferDims& a, const InferDims& b);
702 bool operator==(const InferDims& a, const InferDims& b);
703 bool operator!=(const InferDims& a, const InferDims& b);
706 struct LayerDescription;
707 
712 NvDsInferLayerInfo toCapi(const LayerDescription& desc, void* bufPtr);
713 
718 NvDsInferDims toCapi(const InferDims &dims);
719 
725  const InferBufferDescription& desc, void* buf = nullptr);
726 
732 
747 bool intersectDims(
748  const InferDims& a, const InferDims& b, InferDims& c);
749 
755 bool isPrivateTensor(const std::string &tensorName);
756 
761 std::string joinPath(const std::string& a, const std::string& b);
762 std::string dirName(const std::string& path);
763 bool isAbsolutePath(const std::string& path);
764 bool realPath(const std::string &inPath, std::string &absPath);
770 bool isCpuMem(InferMemType type);
771 
775 std::string memType2Str(InferMemType type);
776 
783 InferDims fullDims(int batchSize, const InferDims& in);
784 
793 bool debatchFullDims(
794  const InferDims& full, InferDims& debatched, uint32_t& batch);
795 
804 bool squeezeMatch(const InferDims& a, const InferDims& b);
805 
819  const SharedBatchBuf& in, uint32_t batch, const InferDims& dims,
820  bool reCalcBytes = false);
821 
832  bool reCalcBytes = false);
833 
849  const SharedBatchBuf& in, const SharedBatchBuf& out,
850  const SharedCuStream& stream);
851 
852 } // namespace nvdsinferserver
853 
854 extern "C" {
855 
860 
875  const std::string& configStr, const std::string& path, std::string& updated);
876 }
877 
878 #endif
nvdsinferserver
This is a header file for pre-processing cuda kernels with normalization and mean subtraction require...
Definition: sources/gst-plugins/gst-nvinferserver/gstnvinferserver_impl.h:69
nvdsinferserver::InferDataType
InferDataType
Datatype of the tensor buffer.
Definition: sources/includes/nvdsinferserver/infer_datatypes.h:88
INFER_EXPORT_API::isNonBatch
bool isNonBatch(T b)
Checks if the input batch size is zero.
Definition: sources/libs/nvdsinferserver/infer_utils.h:106
INFER_EXPORT_API::GuardQueue::pop
T pop()
Pop an item from the queue.
Definition: sources/libs/nvdsinferserver/infer_utils.h:225
INFER_EXPORT_API::intersectDims
bool intersectDims(const InferDims &a, const InferDims &b, InferDims &c)
Get the intersection of the two input dimensions.
INFER_EXPORT_API::operator<=
bool operator<=(const InferDims &a, const InferDims &b)
Comparison operators for the InferDims type.
INFER_EXPORT_API::grpcStr2DataType
InferDataType grpcStr2DataType(const std::string &type)
INFER_EXPORT_API::debatchFullDims
bool debatchFullDims(const InferDims &full, InferDims &debatched, uint32_t &batch)
Separates batch size from given dimensions.
INFER_EXPORT_API::operator>
bool operator>(const InferDims &a, const InferDims &b)
INFER_EXPORT_API::GuardQueue
Template class for creating a thread safe queue for the given container class.
Definition: sources/libs/nvdsinferserver/infer_utils.h:208
INFER_EXPORT_API::dims2Str
std::string dims2Str(const InferDims &d)
Helper functions to convert the various data types to string values for debug, log information.
INFER_EXPORT_API::realPath
bool realPath(const std::string &inPath, std::string &absPath)
INFER_EXPORT_API::GuardQueue::T
Container::value_type T
Definition: sources/libs/nvdsinferserver/infer_utils.h:210
INFER_EXPORT_API::dims2ImageInfo
NvDsInferNetworkInfo dims2ImageInfo(const InferDims &d, InferTensorOrder order)
INFER_EXPORT_API::MapBufferPool::MapBufferPool
MapBufferPool(const std::string &name)
Construct the buffer pool map with a name.
Definition: sources/libs/nvdsinferserver/infer_utils.h:514
INFER_EXPORT_API::toCapi
NvDsInferDims toCapi(const InferDims &dims)
Convert the InferDims to NvDsInferDims of the library interface.
InferDebug
#define InferDebug(fmt,...)
Definition: sources/includes/nvdsinferserver/infer_defines.h:69
INFER_EXPORT_API::QueueThread::Item
typename Container::value_type Item
Definition: sources/libs/nvdsinferserver/infer_utils.h:294
INFER_EXPORT_API::getElementSize
uint32_t getElementSize(InferDataType t)
Get the size of the element from the data type.
Definition: sources/libs/nvdsinferserver/infer_utils.h:629
nvdsinferserver::SharedBatchBuf
std::shared_ptr< BaseBatchBuffer > SharedBatchBuf
Common buffer interfaces (internal).
Definition: sources/libs/nvdsinferserver/infer_common.h:76
INFER_EXPORT_API::dataType2GrpcStr
std::string dataType2GrpcStr(const InferDataType type)
nvdsinferserver::InferTensorOrder
InferTensorOrder
The type of tensor order.
Definition: sources/includes/nvdsinferserver/infer_datatypes.h:46
INFER_EXPORT_API::BufferPool::setBuffer
bool setBuffer(UniPtr buf)
Add a buffer to the pool.
Definition: sources/libs/nvdsinferserver/infer_utils.h:433
NvDsInferDims
Holds the dimensions of a layer.
Definition: sources/includes/nvdsinfer.h:51
INFER_EXPORT_API::joinPath
std::string joinPath(const std::string &a, const std::string &b)
Helper functions for parsing the configuration file.
INFER_EXPORT_API::toCapiLayerInfo
NvDsInferLayerInfo toCapiLayerInfo(const InferBufferDescription &desc, void *buf=nullptr)
Generate NvDsInferLayerInfo of the interface from the buffer description and buffer pointer.
INFER_EXPORT_API::DlLibHandle::symbol
FuncPtr symbol(const char *func)
Definition: sources/libs/nvdsinferserver/infer_utils.h:165
INFER_EXPORT_API::WakeupException::what
const char * what() const noexcept override
Definition: sources/libs/nvdsinferserver/infer_utils.h:198
INFER_EXPORT_API::BufferPool::~BufferPool
virtual ~BufferPool()
Destructor.
Definition: sources/libs/nvdsinferserver/infer_utils.h:422
INFER_EXPORT_API::dirName
std::string dirName(const std::string &path)
INFER_EXPORT_API::DlLibHandle
Helper class for dynamic loading of custom library.
Definition: sources/libs/nvdsinferserver/infer_utils.h:135
INFER_EXPORT_API::SharedBufPool
std::shared_ptr< BufferPool< UniPtr > > SharedBufPool
Definition: sources/libs/nvdsinferserver/infer_utils.h:498
INFER_EXPORT_API::GuardQueue::wakeupOnce
void wakeupOnce()
Send the wakeup trigger to the queue thread.
Definition: sources/libs/nvdsinferserver/infer_utils.h:242
INFER_EXPORT_API::dimsSize
size_t dimsSize(const InferDims &dims)
Calculate the total number of elements for the given dimensions.
Definition: sources/libs/nvdsinferserver/infer_utils.h:675
INFER_EXPORT_API::DlLibHandle::isValid
bool isValid() const
Definition: sources/libs/nvdsinferserver/infer_utils.h:152
InferError
#define InferError(fmt,...)
Definition: sources/includes/nvdsinferserver/infer_defines.h:51
INFER_EXPORT_API::MapBufferPool
Template class for a map of buffer pools.
Definition: sources/libs/nvdsinferserver/infer_utils.h:506
INFER_EXPORT_API::BufferPool::RecylePtr
std::unique_ptr< ItemType, std::function< void(ItemType *)> > RecylePtr
Definition: sources/libs/nvdsinferserver/infer_utils.h:413
INFER_EXPORT_API::GuardQueue::push
void push(T data)
Push an item to the queue.
Definition: sources/libs/nvdsinferserver/infer_utils.h:214
INFER_EXPORT_API::DlLibHandle::symbol
FuncPtr symbol(const std::string &func)
Definition: sources/libs/nvdsinferserver/infer_utils.h:174
NvDsInferLogLevel
NvDsInferLogLevel
Enum for the log levels of NvDsInferContext.
Definition: sources/includes/nvdsinfer.h:262
INFER_EXPORT_API::squeezeMatch
bool squeezeMatch(const InferDims &a, const InferDims &b)
Check that the two dimensions are equal ignoring single element values.
INFER_EXPORT_API::dsInferLogPrint__
void dsInferLogPrint__(NvDsInferLogLevel level, const char *fmt,...)
Print the nvinferserver log messages as per the configured log level.
Definition: sources/includes/nvdsinferserver/infer_options.h:32
NvDsInferDataType
NvDsInferDataType
Specifies the data type of a layer.
Definition: sources/includes/nvdsinfer.h:77
INFER_EXPORT_API::dsInferLogVPrint__
void dsInferLogVPrint__(NvDsInferLogLevel level, const char *fmt, va_list args)
Helper function to print the nvinferserver logs.
INFER_EXPORT_API::MapBufferPool::clear
void clear()
Remove all pools from the map.
Definition: sources/libs/nvdsinferserver/infer_utils.h:591
INFER_EXPORT_API::MapBufferPool::getPoolSize
uint32_t getPoolSize(const Key &key)
Get the size of a pool from the map.
Definition: sources/libs/nvdsinferserver/infer_utils.h:563
INFER_EXPORT_API::BufferPool
Template class for buffer pool of the specified buffer type.
Definition: sources/libs/nvdsinferserver/infer_utils.h:410
INFER_EXPORT_API::QueueThread::QueueThread
QueueThread(RunFunc runFunc, const std::string &name)
Create a new thread that runs the specified function over the queued items in a loop.
Definition: sources/libs/nvdsinferserver/infer_utils.h:304
infer_common.h
Header file of the common declarations for the nvinferserver library.
INFER_EXPORT_API::batchDims2Str
std::string batchDims2Str(const InferBatchDims &d)
INFER_EXPORT_API::QueueThread::queueItem
bool queueItem(Item item)
Add an item to the queue for processing.
Definition: sources/libs/nvdsinferserver/infer_utils.h:350
INFER_EXPORT_API::QueueThread
Template class for running the specified function on the queue items in a separate thread.
Definition: sources/libs/nvdsinferserver/infer_utils.h:292
infer_batch_buffer.h
Header file of batch buffer related class declarations.
nvdsinferserver::SharedCuStream
std::shared_ptr< CudaStream > SharedCuStream
Cuda based pointers.
Definition: sources/libs/nvdsinferserver/infer_common.h:89
validateInferConfigStr
INFER_EXPORT_API bool validateInferConfigStr(const std::string &configStr, const std::string &path, std::string &updated)
Validates the provided nvinferserver configuration string.
NvDsInferNetworkInfo
Holds information about the model network.
Definition: sources/includes/nvdsinfer.h:119
INFER_EXPORT_API::file_accessible
bool file_accessible(const std::string &path)
Definition: sources/libs/nvdsinferserver/infer_utils.h:96
NvDsInferLayerInfo
Holds information about one layer in the model.
Definition: sources/includes/nvdsinfer.h:96
INFER_EXPORT_API::GuardQueue::size
int size()
Current size of the queue.
Definition: sources/libs/nvdsinferserver/infer_utils.h:260
INFER_EXPORT_API::memType2Str
std::string memType2Str(InferMemType type)
Returns a string object corresponding to the InferMemType name.
INFER_EXPORT_API::QueueThread::~QueueThread
~QueueThread()
Destructor.
Definition: sources/libs/nvdsinferserver/infer_utils.h:338
INFER_EXPORT_API::toCapiDataType
NvDsInferDataType toCapiDataType(InferDataType dt)
Convert the InferDataType to NvDsInferDataType of the library interface.
INFER_EXPORT_API::BufferPool::BufferPool
BufferPool(const std::string &name)
Constructor.
Definition: sources/libs/nvdsinferserver/infer_utils.h:417
INFER_EXPORT_API::isAbsolutePath
bool isAbsolutePath(const std::string &path)
INFER_EXPORT_API::WakeupException
Wrapper class for handling exception.
Definition: sources/libs/nvdsinferserver/infer_utils.h:193
INFER_EXPORT_API::QueueThread::join
void join()
Definition: sources/libs/nvdsinferserver/infer_utils.h:339
INFER_EXPORT_API::MapBufferPool::RecylePtr
typename BufferPool< UniqBuffer >::RecylePtr RecylePtr
Definition: sources/libs/nvdsinferserver/infer_utils.h:509
INFER_EXPORT_API::isPrivateTensor
bool isPrivateTensor(const std::string &tensorName)
Check if the given tensor is marked as private (contains INFER_SERVER_PRIVATE_BUF in the name).
INFER_EXPORT_API::dataType2Str
std::string dataType2Str(const InferDataType type)
INFER_EXPORT_API::tensorOrder2Str
std::string tensorOrder2Str(InferTensorOrder order)
INFER_EXPORT_API::DlLibHandle::getPath
const std::string & getPath() const
Definition: sources/libs/nvdsinferserver/infer_utils.h:157
INFER_EXPORT_API::QueueThread::RunFunc
std::function< bool(Item)> RunFunc
Definition: sources/libs/nvdsinferserver/infer_utils.h:295
INFER_EXPORT_API::normalizeDims
void normalizeDims(InferDims &dims)
Recalculates the total number of elements for the dimensions.
Definition: sources/libs/nvdsinferserver/infer_utils.h:691
INFER_EXPORT_API::MapBufferPool::acquireBuffer
RecylePtr acquireBuffer(const Key &key)
Acquire a buffer from the selected pool.
Definition: sources/libs/nvdsinferserver/infer_utils.h:576
INFER_EXPORT_API::isCpuMem
bool isCpuMem(InferMemType type)
Check if the memory type uses CPU memory (kCpu or kCpuCuda).
INFER_EXPORT_API::MapBufferPool::~MapBufferPool
virtual ~MapBufferPool()
Destructor.
Definition: sources/libs/nvdsinferserver/infer_utils.h:518
INFER_EXPORT_API
Definition: sources/libs/nvdsinferserver/infer_utils.h:38
INFER_EXPORT_API::MapBufferPool::setBuffer
bool setBuffer(const Key &key, UniqBuffer buf)
Add a buffer to the pool map.
Definition: sources/libs/nvdsinferserver/infer_utils.h:541
INFER_EXPORT_API::MapBufferPool::SharedPool
SharedBufPool< UniqBuffer > SharedPool
Definition: sources/libs/nvdsinferserver/infer_utils.h:508
nvdsinferserver::InferMemType
InferMemType
The memory types of inference buffers.
Definition: sources/includes/nvdsinferserver/infer_datatypes.h:61
INFER_EXPORT_API::hasWildcard
bool hasWildcard(const InferDims &dims)
Check if any of the InferDims dimensions are of dynamic size (-1 or negative values).
Definition: sources/libs/nvdsinferserver/infer_utils.h:661
INFER_EXPORT_API::safeStr
const char * safeStr(const std::string &str)
Definition: sources/libs/nvdsinferserver/infer_utils.h:73
NvDsInferStatus2Str
const INFER_EXPORT_API char * NvDsInferStatus2Str(NvDsInferStatus status)
Returns the NvDsInferStatus enum name as a string.
INFER_EXPORT_API::operator==
bool operator==(const InferDims &a, const InferDims &b)
INFER_EXPORT_API::BufferPool::size
int size()
Get the number of free buffers.
Definition: sources/libs/nvdsinferserver/infer_utils.h:444
INFER_EXPORT_API::BufferPool::acquireBuffer
RecylePtr acquireBuffer()
Acquire a buffer from the pool.
Definition: sources/libs/nvdsinferserver/infer_utils.h:455
INFER_EXPORT_API::fEqual
bool fEqual(float a, float b)
Check if the two floating point values are equal, the difference is less than or equal to the epsilon...
INFER_EXPORT_API::WakeupException::WakeupException
WakeupException(const std::string &s)
Definition: sources/libs/nvdsinferserver/infer_utils.h:197
INFER_EXPORT_API::QueueThread::setThreadName
void setThreadName(const std::string &name)
Set the internal (m_Name) name of the thread and system name using pthread_setname_np().
Definition: sources/libs/nvdsinferserver/infer_utils.h:319
INFER_EXPORT_API::operator!=
bool operator!=(const InferDims &a, const InferDims &b)
InferWarning
#define InferWarning(fmt,...)
Definition: sources/includes/nvdsinferserver/infer_defines.h:57
INFER_EXPORT_API::reshapeToFullDimsBuf
SharedBatchBuf reshapeToFullDimsBuf(const SharedBatchBuf &buf, bool reCalcBytes=false)
Reshape the buffer dimensions with batch size added as new dimension.
INFER_EXPORT_API::GuardQueue::clear
void clear()
Clear the queue.
Definition: sources/libs/nvdsinferserver/infer_utils.h:251
INFER_EXPORT_API::ReshapeBuf
SharedBatchBuf ReshapeBuf(const SharedBatchBuf &in, uint32_t batch, const InferDims &dims, bool reCalcBytes=false)
Update the buffer dimensions as per provided new dimensions.
INFER_EXPORT_API::string_empty
bool string_empty(const char *str)
Helper function, returns true if the input C string is empty or null.
Definition: sources/libs/nvdsinferserver/infer_utils.h:82
INFER_EXPORT_API::fullDims
InferDims fullDims(int batchSize, const InferDims &in)
Extend the dimensions to include batch size.
INFER_EXPORT_API::tensorBufferCopy
NvDsInferStatus tensorBufferCopy(const SharedBatchBuf &in, const SharedBatchBuf &out, const SharedCuStream &stream)
Copy one tensor buffer to another.
INFER_EXPORT_API::BufferPool::ItemType
typename UniPtr::element_type ItemType
Definition: sources/libs/nvdsinferserver/infer_utils.h:412
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: sources/includes/nvdsinfer.h:231