NVIDIA DeepStream SDK API Reference

7.0 Release
infer_cuda_context.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-2022 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 
23 #ifndef __INFER_CUDA_CONTEXT_H__
24 #define __INFER_CUDA_CONTEXT_H__
25 
26 #include <shared_mutex>
27 
28 #include "infer_base_context.h"
29 #include "infer_common.h"
30 #include "infer_datatypes.h"
31 #include "infer_utils.h"
32 
33 namespace nvdsinferserver {
34 
35 class CropSurfaceConverter;
36 class NetworkPreprocessor;
37 class Postprocessor;
38 class CudaEventInPool;
39 
45 public:
53  ~InferCudaContext() override;
54 
61  SharedSysMem acquireTensorHostBuf(const std::string& name, size_t bytes);
62 
67 
68 protected:
77  const ic::InferenceConfig& config, BaseBackend& backend) override;
84  NvDsInferStatus createPreprocessor(const ic::PreProcessParams& params,
85  std::vector<UniqPreprocessor>& processors) override;
92  NvDsInferStatus createPostprocessor(const ic::PostProcessParams& params,
93  UniqPostprocessor& processor) override;
101  const ic::InferenceConfig& config) override;
110  SharedBatchArray& inputs, const ic::InferenceConfig& config) override;
118  SharedBatchArray& outputs, SharedOptions inOptions) override;
122  void notifyError(NvDsInferStatus status) override;
128  NvDsInferStatus deinit() override;
132  void getNetworkInputInfo(NvDsInferNetworkInfo &networkInfo) override {
133  networkInfo = m_NetworkImageInfo;
134  }
138  int tensorPoolSize() const;
139 
140 private:
148  NvDsInferStatus addHostTensorPool(const LayerDescription& layer,
149  int poolSize, int gpuId);
150 
157  NvDsInferStatus ensureLstmInputReady(
158  SharedBatchArray& inputs, const ic::InferenceConfig& config);
159 
168  NvDsInferStatus initFixedExtraInputLayers(
169  SharedBatchArray& inputs, const ic::InferenceConfig& config);
170 
174  bool hasExtraProcess() const { return m_ExtraProcessor.get(); }
175 
186  NvDsInferStatus loadExtraProcessor(
187  const ic::InferenceConfig& config, BaseBackend& backend, const std::string& primaryTensor);
188 
189 protected:
190 
200  std::string m_NetworkImageName;
209 
213  std::vector<SharedCudaTensorBuf> m_ExtraInputs;
217  MapBufferPool<std::string, UniqSysMem> m_HostTensorPool;
221  SharedBufPool<std::unique_ptr<CudaEventInPool>> m_HostTensorEvents;
222 
229 
236 };
237 
238 } // namespace nvdsinferserver
239 
240 #endif
nvdsinferserver
This is a header file for pre-processing cuda kernels with normalization and mean subtraction require...
Definition: infer_custom_process.h:24
nvdsinferserver::InferCudaContext::getNetworkInputInfo
void getNetworkInputInfo(NvDsInferNetworkInfo &networkInfo) override
Get the network input layer information.
Definition: infer_cuda_context.h:132
nvdsinferserver::InferDataType
InferDataType
Datatype of the tensor buffer.
Definition: infer_datatypes.h:83
nvdsinferserver::UniqInferExtraProcessor
std::unique_ptr< InferExtraProcessor > UniqInferExtraProcessor
Definition: infer_common.h:139
nvdsinferserver::InferCudaContext::m_MultiStreamManager
UniqStreamManager m_MultiStreamManager
stream-id based management.
Definition: infer_cuda_context.h:226
nvdsinferserver::InferMediaFormat
InferMediaFormat
Image formats.
Definition: infer_datatypes.h:129
nvdsinferserver::InferCudaContext::extraOutputTensorCheck
NvDsInferStatus extraOutputTensorCheck(SharedBatchArray &outputs, SharedOptions inOptions) override
Post inference steps for the custom processor and LSTM controller.
nvdsinferserver::InferCudaContext::createPreprocessor
NvDsInferStatus createPreprocessor(const ic::PreProcessParams &params, std::vector< UniqPreprocessor > &processors) override
Create the surface converter and network preprocessor.
nvdsinferserver::SharedSysMem
std::shared_ptr< SysMem > SharedSysMem
Definition: infer_common.h:88
nvdsinferserver::InferCudaContext::allocateResource
NvDsInferStatus allocateResource(const ic::InferenceConfig &config) override
Allocate resources for the preprocessors and post-processor.
infer_datatypes.h
Header file for the data types used in the inference processing.
nvdsinferserver::NetworkPreprocessor
Preprocessor for scaling and normalization of the input and conversion to network media format.
Definition: infer_preprocess.h:51
nvdsinferserver::InferTensorOrder
InferTensorOrder
The type of tensor order.
Definition: infer_datatypes.h:41
nvdsinferserver::LayerDescription
Stores the information of a layer in the inference model.
Definition: infer_ibackend.h:34
nvdsinferserver::InferCudaContext::m_HostTensorPool
MapBufferPool< std::string, UniqSysMem > m_HostTensorPool
Map of pools for the output tensors.
Definition: infer_cuda_context.h:217
nvdsinferserver::InferCudaContext::m_LstmController
UniqLstmController m_LstmController
LSTM controller.
Definition: infer_cuda_context.h:224
infer_utils.h
Header file containing utility functions and classes used by the nvinferserver low level library.
nvdsinferserver::InferCudaContext::InferCudaContext
InferCudaContext()
Constructor.
nvdsinferserver::InferMediaFormat::kRGB
@ kRGB
24-bit interleaved R-G-B
nvdsinferserver::Postprocessor
A generic post processor class.
Definition: infer_postprocess.h:54
infer_common.h
Header file of the common declarations for the nvinferserver library.
nvdsinferserver::InferCudaContext::m_NetworkImageName
std::string m_NetworkImageName
The input layer name.
Definition: infer_cuda_context.h:200
nvdsinferserver::InferCudaContext::acquireTensorHostEvent
SharedCuEvent acquireTensorHostEvent()
Acquire a CUDA event from the events pool.
nvdsinferserver::InferCudaContext::tensorPoolSize
int tensorPoolSize() const
Get the size of the tensor pool.
nvdsinferserver::CropSurfaceConverter
Preprocessor for cropping, scaling and padding the inference input to required height,...
Definition: infer_preprocess.h:113
nvdsinferserver::InferCudaContext::notifyError
void notifyError(NvDsInferStatus status) override
In case of error, notify the waiting threads.
NvDsInferNetworkInfo
Holds information about the model network.
Definition: nvdsinfer.h:110
nvdsinferserver::InferCudaContext::m_InputDataType
InferDataType m_InputDataType
The input layer datatype.
Definition: infer_cuda_context.h:208
nvdsinferserver::InferCudaContext::m_ExtraInputs
std::vector< SharedCudaTensorBuf > m_ExtraInputs
Array of buffers of the additional inputs.
Definition: infer_cuda_context.h:213
nvdsinferserver::SharedOptions
std::shared_ptr< IOptions > SharedOptions
Definition: infer_common.h:73
nvdsinferserver::InferCudaContext::deinit
NvDsInferStatus deinit() override
Release the host tensor pool buffers, extra input buffers, LSTM controller, extra input processor.
nvdsinferserver::InferCudaContext::m_SurfaceConverter
CropSurfaceConverter * m_SurfaceConverter
Preprocessor and post-processor handles.
Definition: infer_cuda_context.h:232
nvdsinferserver::InferDataType::kFp32
@ kFp32
nvdsinferserver::InferCudaContext::m_NetworkPreprocessor
NetworkPreprocessor * m_NetworkPreprocessor
Definition: infer_cuda_context.h:233
nvdsinferserver::InferCudaContext::preInference
NvDsInferStatus preInference(SharedBatchArray &inputs, const ic::InferenceConfig &config) override
Initialize non-image input layers if the custom library has implemented the interface.
nvdsinferserver::InferBaseContext::backend
BaseBackend * backend()
Definition: infer_base_context.h:101
nvdsinferserver::InferBaseContext
The base class for handling the inference context.
Definition: infer_base_context.h:52
nvdsinferserver::InferCudaContext::m_ExtraProcessor
UniqInferExtraProcessor m_ExtraProcessor
Extra and custom processing pre/post inference.
Definition: infer_cuda_context.h:228
nvdsinferserver::InferCudaContext::m_InputTensorOrder
InferTensorOrder m_InputTensorOrder
The input layer tensor order.
Definition: infer_cuda_context.h:204
nvdsinferserver::InferBaseContext::config
const ic::InferenceConfig & config() const
Definition: infer_base_context.h:98
nvdsinferserver::InferTensorOrder::kNone
@ kNone
nvdsinferserver::InferCudaContext::m_FinalProcessor
Postprocessor * m_FinalProcessor
Definition: infer_cuda_context.h:234
nvdsinferserver::InferCudaContext::acquireTensorHostBuf
SharedSysMem acquireTensorHostBuf(const std::string &name, size_t bytes)
Allocator.
nvdsinferserver::InferCudaContext::createPostprocessor
NvDsInferStatus createPostprocessor(const ic::PostProcessParams &params, UniqPostprocessor &processor) override
Create the post-processor as per the network output type.
nvdsinferserver::UniqStreamManager
std::unique_ptr< StreamManager > UniqStreamManager
Definition: infer_common.h:131
nvdsinferserver::InferCudaContext::m_HostTensorEvents
SharedBufPool< std::unique_ptr< CudaEventInPool > > m_HostTensorEvents
Pool of CUDA events for host tensor copy.
Definition: infer_cuda_context.h:221
nvdsinferserver::InferCudaContext::fixateInferenceInfo
NvDsInferStatus fixateInferenceInfo(const ic::InferenceConfig &config, BaseBackend &backend) override
Check the tensor order, media format, and datatype for the input tensor.
nvdsinferserver::UniqLstmController
std::unique_ptr< LstmController > UniqLstmController
Definition: infer_common.h:128
nvdsinferserver::UniqPostprocessor
std::unique_ptr< BasePostprocessor > UniqPostprocessor
Processor interfaces.
Definition: infer_common.h:98
nvdsinferserver::SharedCuEvent
std::shared_ptr< CudaEvent > SharedCuEvent
Definition: infer_common.h:86
nvdsinferserver::BaseBackend
Base class of inference backend processing.
Definition: infer_base_backend.h:40
nvdsinferserver::InferCudaContext::m_NetworkImageFormat
InferMediaFormat m_NetworkImageFormat
The input layer media format.
Definition: infer_cuda_context.h:196
nvdsinferserver::SharedBatchArray
std::shared_ptr< BaseBatchArray > SharedBatchArray
Definition: infer_common.h:75
nvdsinferserver::InferCudaContext::~InferCudaContext
~InferCudaContext() override
Destructor.
infer_base_context.h
Header file of the base class for inference context.
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: nvdsinfer.h:218
nvdsinferserver::InferCudaContext::m_NetworkImageInfo
NvDsInferNetworkInfo m_NetworkImageInfo
Network input height, width, channels for preprocessing.
Definition: infer_cuda_context.h:192
nvdsinferserver::InferCudaContext
Class for inference context CUDA processing.
Definition: infer_cuda_context.h:44