NVIDIA DeepStream SDK API Reference

9.1 Release
sources/libs/nvdsinferserver/infer_cuda_context.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2018-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 
28 #ifndef __INFER_CUDA_CONTEXT_H__
29 #define __INFER_CUDA_CONTEXT_H__
30 
31 #include <shared_mutex>
32 
33 #include "infer_base_context.h"
34 #include "infer_common.h"
35 #include "infer_datatypes.h"
36 #include "infer_utils.h"
37 
38 namespace nvdsinferserver {
39 
40 class CropSurfaceConverter;
41 class NetworkPreprocessor;
42 class Postprocessor;
43 class CudaEventInPool;
44 
50 public:
58  ~InferCudaContext() override;
59 
66  SharedSysMem acquireTensorHostBuf(const std::string& name, size_t bytes);
67 
72 
73 protected:
82  const ic::InferenceConfig& config, BaseBackend& backend) override;
89  NvDsInferStatus createPreprocessor(const ic::PreProcessParams& params,
90  std::vector<UniqPreprocessor>& processors) override;
97  NvDsInferStatus createPostprocessor(const ic::PostProcessParams& params,
98  UniqPostprocessor& processor) override;
106  const ic::InferenceConfig& config) override;
115  SharedBatchArray& inputs, const ic::InferenceConfig& config) override;
123  SharedBatchArray& outputs, SharedOptions inOptions) override;
127  void notifyError(NvDsInferStatus status) override;
133  NvDsInferStatus deinit() override;
137  void getNetworkInputInfo(NvDsInferNetworkInfo &networkInfo) override {
138  networkInfo = m_NetworkImageInfo;
139  }
143  int tensorPoolSize() const;
144 
145 private:
153  NvDsInferStatus addHostTensorPool(const LayerDescription& layer,
154  int poolSize, int gpuId);
155 
162  NvDsInferStatus ensureLstmInputReady(
163  SharedBatchArray& inputs, const ic::InferenceConfig& config);
164 
173  NvDsInferStatus initFixedExtraInputLayers(
174  SharedBatchArray& inputs, const ic::InferenceConfig& config);
175 
179  bool hasExtraProcess() const { return m_ExtraProcessor.get(); }
180 
191  NvDsInferStatus loadExtraProcessor(
192  const ic::InferenceConfig& config, BaseBackend& backend, const std::string& primaryTensor);
193 
194 protected:
195 
205  std::string m_NetworkImageName;
214 
218  std::vector<SharedCudaTensorBuf> m_ExtraInputs;
222  MapBufferPool<std::string, UniqSysMem> m_HostTensorPool;
226  SharedBufPool<std::unique_ptr<CudaEventInPool>> m_HostTensorEvents;
227 
234 
241 };
242 
243 } // namespace nvdsinferserver
244 
245 #endif
nvdsinferserver::InferCudaContext::m_HostTensorEvents
SharedBufPool< std::unique_ptr< CudaEventInPool > > m_HostTensorEvents
Pool of CUDA events for host tensor copy.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:226
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::InferCudaContext::getNetworkInputInfo
void getNetworkInputInfo(NvDsInferNetworkInfo &networkInfo) override
Get the network input layer information.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:137
nvdsinferserver::InferDataType
InferDataType
Datatype of the tensor buffer.
Definition: sources/includes/nvdsinferserver/infer_datatypes.h:88
nvdsinferserver::InferCudaContext::m_MultiStreamManager
UniqStreamManager m_MultiStreamManager
stream-id based management.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:231
nvdsinferserver::InferCudaContext::m_FinalProcessor
Postprocessor * m_FinalProcessor
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:239
infer_base_context.h
Header file of the base class for inference context.
nvdsinferserver::InferMediaFormat
InferMediaFormat
Image formats.
Definition: sources/includes/nvdsinferserver/infer_datatypes.h:134
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::InferCudaContext::allocateResource
NvDsInferStatus allocateResource(const ic::InferenceConfig &config) override
Allocate resources for the preprocessors and post-processor.
nvdsinferserver::InferCudaContext::m_NetworkPreprocessor
NetworkPreprocessor * m_NetworkPreprocessor
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:238
nvdsinferserver::NetworkPreprocessor
Preprocessor for scaling and normalization of the input and conversion to network media format.
Definition: sources/libs/nvdsinferserver/infer_preprocess.h:56
nvdsinferserver::InferTensorOrder
InferTensorOrder
The type of tensor order.
Definition: sources/includes/nvdsinferserver/infer_datatypes.h:46
nvdsinferserver::LayerDescription
Stores the information of a layer in the inference model.
Definition: sources/libs/nvdsinferserver/infer_ibackend.h:39
nvdsinferserver::SharedBatchArray
std::shared_ptr< BaseBatchArray > SharedBatchArray
Definition: sources/libs/nvdsinferserver/infer_common.h:80
nvdsinferserver::InferCudaContext::m_LstmController
UniqLstmController m_LstmController
LSTM controller.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:229
nvdsinferserver::SharedCuEvent
std::shared_ptr< CudaEvent > SharedCuEvent
Definition: sources/libs/nvdsinferserver/infer_common.h:91
nvdsinferserver::InferCudaContext::InferCudaContext
InferCudaContext()
Constructor.
nvdsinferserver::InferMediaFormat::kRGB
@ kRGB
24-bit interleaved R-G-B
nvdsinferserver::Postprocessor
A generic post processor class.
Definition: sources/libs/nvdsinferserver/infer_postprocess.h:59
nvdsinferserver::InferCudaContext::m_NetworkImageName
std::string m_NetworkImageName
The input layer name.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:205
nvdsinferserver::InferCudaContext::acquireTensorHostEvent
SharedCuEvent acquireTensorHostEvent()
Acquire a CUDA event from the events pool.
nvdsinferserver::InferCudaContext::m_ExtraInputs
std::vector< SharedCudaTensorBuf > m_ExtraInputs
Array of buffers of the additional inputs.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:218
nvdsinferserver::InferCudaContext::tensorPoolSize
int tensorPoolSize() const
Get the size of the tensor pool.
infer_common.h
Header file of the common declarations for the nvinferserver library.
nvdsinferserver::CropSurfaceConverter
Preprocessor for cropping, scaling and padding the inference input to required height,...
Definition: sources/libs/nvdsinferserver/infer_preprocess.h:118
nvdsinferserver::InferCudaContext::notifyError
void notifyError(NvDsInferStatus status) override
In case of error, notify the waiting threads.
nvdsinferserver::UniqPostprocessor
std::unique_ptr< BasePostprocessor > UniqPostprocessor
Processor interfaces.
Definition: sources/libs/nvdsinferserver/infer_common.h:103
NvDsInferNetworkInfo
Holds information about the model network.
Definition: sources/includes/nvdsinfer.h:119
nvdsinferserver::UniqStreamManager
std::unique_ptr< StreamManager > UniqStreamManager
Definition: sources/libs/nvdsinferserver/infer_common.h:136
nvdsinferserver::InferCudaContext::m_InputDataType
InferDataType m_InputDataType
The input layer datatype.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:213
nvdsinferserver::SharedOptions
std::shared_ptr< IOptions > SharedOptions
Definition: sources/libs/nvdsinferserver/infer_common.h:78
nvdsinferserver::InferCudaContext::m_HostTensorPool
MapBufferPool< std::string, UniqSysMem > m_HostTensorPool
Map of pools for the output tensors.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:222
nvdsinferserver::InferCudaContext::deinit
NvDsInferStatus deinit() override
Release the host tensor pool buffers, extra input buffers, LSTM controller, extra input processor.
nvdsinferserver::UniqLstmController
std::unique_ptr< LstmController > UniqLstmController
Definition: sources/libs/nvdsinferserver/infer_common.h:133
nvdsinferserver::InferDataType::kFp32
@ kFp32
nvdsinferserver::SharedSysMem
std::shared_ptr< SysMem > SharedSysMem
Definition: sources/libs/nvdsinferserver/infer_common.h:93
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: sources/libs/nvdsinferserver/infer_base_context.h:106
nvdsinferserver::InferBaseContext
The base class for handling the inference context.
Definition: sources/libs/nvdsinferserver/infer_base_context.h:57
nvdsinferserver::InferCudaContext::m_ExtraProcessor
UniqInferExtraProcessor m_ExtraProcessor
Extra and custom processing pre/post inference.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:233
nvdsinferserver::InferCudaContext::m_InputTensorOrder
InferTensorOrder m_InputTensorOrder
The input layer tensor order.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:209
nvdsinferserver::InferBaseContext::config
const ic::InferenceConfig & config() const
Definition: sources/libs/nvdsinferserver/infer_base_context.h:103
nvdsinferserver::InferTensorOrder::kNone
@ kNone
nvdsinferserver::InferCudaContext::acquireTensorHostBuf
SharedSysMem acquireTensorHostBuf(const std::string &name, size_t bytes)
Allocator.
nvdsinferserver::InferCudaContext::m_SurfaceConverter
CropSurfaceConverter * m_SurfaceConverter
Preprocessor and post-processor handles.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:237
nvdsinferserver::InferCudaContext::createPostprocessor
NvDsInferStatus createPostprocessor(const ic::PostProcessParams &params, UniqPostprocessor &processor) override
Create the post-processor as per the network output type.
infer_utils.h
Header file containing utility functions and classes used by the nvinferserver low level library.
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::UniqInferExtraProcessor
std::unique_ptr< InferExtraProcessor > UniqInferExtraProcessor
Definition: sources/libs/nvdsinferserver/infer_common.h:144
nvdsinferserver::BaseBackend
Base class of inference backend processing.
Definition: sources/libs/nvdsinferserver/infer_base_backend.h:45
nvdsinferserver::InferCudaContext::m_NetworkImageFormat
InferMediaFormat m_NetworkImageFormat
The input layer media format.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:201
nvdsinferserver::InferCudaContext::~InferCudaContext
~InferCudaContext() override
Destructor.
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: sources/includes/nvdsinfer.h:231
nvdsinferserver::InferCudaContext::m_NetworkImageInfo
NvDsInferNetworkInfo m_NetworkImageInfo
Network input height, width, channels for preprocessing.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:197
nvdsinferserver::InferCudaContext
Class for inference context CUDA processing.
Definition: sources/libs/nvdsinferserver/infer_cuda_context.h:49