|
|
NVIDIA DeepStream SDK API Reference
|
9.2 Release
|
Go to the documentation of this file.
24 #ifndef __NVDSINFERSERVER_BATCH_BUFFER_H__
25 #define __NVDSINFERSERVER_BATCH_BUFFER_H__
29 #include <unordered_map>
30 #include "nvbufsurftransform.h"
32 #include "infer_datatypes.h"
50 assert(m_Desc.elementSize >= 0);
51 uint32_t b = getBatchSize();
52 return m_Desc.elementSize * m_Desc.dims.numElements * (b ? b : 1);
75 assert(!hasAttachLoop());
77 void detach() { m_Attaches.clear(); }
86 std::set<BaseBatchBuffer*> allAttached;
87 for (
auto const& buf : m_Attaches) {
89 if (allAttached.count(buf.get())) {
92 allAttached.emplace(buf.get());
98 uint64_t
bufId()
const {
return m_BufId; }
107 assert(getBufPtr(0) && getBufPtr(batchIdx));
108 if (getBufPtr(0) ==
nullptr || getBufPtr(batchIdx) ==
nullptr) {
111 return (uint8_t*)getBufPtr(batchIdx) - (uint8_t*)getBufPtr(0);
118 uint32_t m_BatchSize = 0;
120 std::vector<SharedBatchBuf> m_Attaches;
121 uint64_t m_BufId = UINT64_C(0);
133 uint32_t
getSize() const final {
return m_Bufs.size(); }
136 assert(arrayIdx < (uint32_t)m_Bufs.size());
137 assert(m_Bufs.at(arrayIdx).get());
138 return m_Bufs.at(arrayIdx).get();
142 assert(arrayIdx < (uint32_t)m_Bufs.size());
143 assert(m_Bufs.at(arrayIdx).get());
144 return buf(arrayIdx);
149 std::dynamic_pointer_cast<BaseBatchBuffer>(
buf);
157 const std::vector<SharedBatchBuf>&
bufs()
const {
return m_Bufs; }
162 assert(idx < (uint32_t)m_Bufs.size());
163 return m_Bufs.at(idx);
167 assert(idx < (uint32_t)m_Bufs.size());
168 return m_Bufs.at(idx);
174 auto iter = std::find_if(m_Bufs.cbegin(), m_Bufs.cend(),
177 const InferBufferDescription& desc = buf->getBufDesc();
178 if (desc.memType == InferMemType::kGpuCuda) {
186 assert((iter != m_Bufs.cend() && gpuId >= 0) ||
187 (iter == m_Bufs.cend() && gpuId == -1));
192 uint64_t
bufId()
const {
return m_BufId; }
198 std::vector<SharedBatchBuf> m_Bufs;
200 uint64_t m_BufId = UINT64_C(0);
213 void* bufBase,
size_t offset,
size_t bufBytes,
216 m_BufBytes(bufBytes), m_BufOffset(offset)
222 assert(batchIdx == 0 || batchIdx < getBatchSize());
224 assert(batchIdx <= 0 || desc.
dataType != InferDataType::kString);
226 return (
void*)((uint8_t*)m_BufBase +
238 assert(batchIdx == 0 || batchIdx < getBatchSize());
240 assert(batchIdx <= 0 || desc.
dataType != InferDataType::kString);
246 mutable void* m_BufBase =
nullptr;
247 size_t m_BufBytes = 0;
251 size_t m_BufOffset = 0;
256 template <
typename BufPtr>
263 return m_Impl->getBufDesc();
266 return m_Impl->getBufPtr(batchIdx);
const SharedBatchBuf & buf(uint32_t idx) const
This is a header file for pre-processing cuda kernels with normalization and mean subtraction require...
uint32_t getBatchSize() const final
uint32_t getSize() const final
~BaseBatchArray() override=default
void setBufId(uint64_t id)
const IOptions * getOptions() const final
struct NvBufSurfTransformSyncObj * NvBufSurfTransformSyncObj_t
Holds the information about synchronization objects for asynchronous transform/composite APIs.
RefBatchBuffer(void *bufBase, size_t offset, size_t bufBytes, const InferBufferDescription &desc, uint32_t batchSize)
std::shared_ptr< IOptions > SharedIOptions
void setBufId(uint64_t id)
NvBufSurfTransform_Error NvBufSurfTransformSyncObjDestroy(NvBufSurfTransformSyncObj_t *sync_obj)
Destroy the synchronization object.
A batch buffer with allocated memory.
const SharedCuEvent & cuEvent() const
std::shared_ptr< BaseBatchBuffer > SharedBatchBuf
Common buffer interfaces (internal).
size_t getBufOffset(uint32_t batchIdx) const override
Get the offset from start of the memory allocation to the buffer pointer.
NvBufSurfTransformSyncObj_t & getSyncObj()
void normalizeDims(InferDims &dims)
void setIOptions(SharedIOptions o) final
const IBatchBuffer * getBuffer(uint32_t arrayIdx) const final
const std::vector< SharedBatchBuf > & attachedBufs() const
uint64_t getTotalBytes() const final
Interface class for a batch buffer.
void setCuEvent(SharedCuEvent e)
virtual void setBatchSize(uint32_t size)
const SharedCuEvent & cuEvent() const
std::shared_ptr< CudaEvent > SharedCuEvent
void addBuf(SharedBatchBuf buf)
Header file of the common declarations for the nvinferserver library.
std::vector< SharedBatchBuf > & mutableBufs()
SharedIBatchBuffer getSafeBuf(uint32_t arrayIdx) const final
int max(int a, int b)
Compute the component-wise maximum.
void setOptions(SharedIOptions o)
const InferBufferDescription & getBufDesc() const final
uint32_t getBatchSize() const final
std::shared_ptr< IOptions > SharedOptions
constexpr absl::OTABSL_OPTION_NAMESPACE_NAME::remove_reference_t< T > && move(T &&t) noexcept
uint64_t getTotalBytes() const override
WrapCBatchBuffer(BufPtr buf)
void * getBufPtr(uint32_t batchIdx) const final
NvBufSurfTransform_Error NvBufSurfTransformSyncObjWait(NvBufSurfTransformSyncObj_t sync_obj, uint32_t time_out)
Wait on the synchronization object.
uint64_t getTotalBytes() const final
constexpr const char * size
void setSyncObj(NvBufSurfTransformSyncObj_t SyncObj)
std::vector< SharedBatchBuf > & mutableAttachedBufs()
InferDataType dataType
Datatype associated with the buffer.
BaseBatchBuffer(uint32_t batchSize)
bool hasAttachedBufs() const
void * getBufPtr(uint32_t batchIdx) const override
void appendIBatchBuf(SharedIBatchBuffer buf) final
void setBufDesc(const InferBufferDescription &desc)
Extensions to the C++ standard library.
The base class for array of batch buffers.
std::shared_ptr< IBatchBuffer > SharedIBatchBuffer
void setCuEvent(SharedCuEvent e)
unsigned int numElements
Number of elements in the layer including all dimensions.
SharedBatchBuf & buf(uint32_t idx)
InferDims dims
Dimensions of the tensor.
SharedIOptions getSafeOptions() const
The base class for batch buffers.
uint32_t elementSize
Per element bytes, except kString (with elementSize is 0)
void attach(SharedBatchBuf buf)
int findFirstGpuId() const
Interface class for an array of batch buffers.
InferBufferDescription & mutableBufDesc()
bool hasAttachLoop() const
size_t getBufOffset(uint32_t batchIdx) const override
Get the offset from start of the memory allocation to the buffer pointer.
const std::vector< SharedBatchBuf > & bufs() const
Holds the information about a inference buffer.