NVIDIA DeepStream SDK API Reference

9.1 Release
sources/libs/nvdsinferserver/infer_lstm.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2020-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 
18 #ifndef __INFER_LSTM_CONTROL_H__
19 #define __INFER_LSTM_CONTROL_H__
20 
21 #include "infer_base_context.h"
22 #include "infer_common.h"
23 #include "infer_datatypes.h"
24 #include "infer_proto_utils.h"
25 #include "infer_utils.h"
26 
27 namespace nvdsinferserver {
28 
30 public:
31  LstmController(const ic::LstmParams& params, int devId, int maxBatchSize)
32  {
33  m_Params.CopyFrom(params);
34  m_DevId = devId;
35  m_MaxBatchSize = maxBatchSize;
36  }
37  ~LstmController() = default;
38 
42  void notifyError(NvDsInferStatus status);
43  void destroy()
44  {
45  UniqLock locker(m_Mutex);
46  m_InProgress = 0;
47  m_Cond.notify_all();
48  locker.unlock();
49  m_LoopStateMap.clear();
50  m_LstmInputs.clear();
51  }
52 
53 private:
54  // check input/output tensor names/dims/datatype must be same
55  NvDsInferStatus checkTensorInfo(BaseBackend& backend);
56  struct LoopState {
57  std::string inputName;
58  SharedCudaTensorBuf inputTensor;
59  SharedBatchBuf outputTensor;
60  bool keepOutputParsing = false;
61  };
62 
63 private:
64  ic::LstmParams m_Params;
65  int m_DevId = 0;
66  int m_MaxBatchSize = 1;
67  // map<outputName, loopState>
68  std::unordered_map<std::string, LoopState> m_LoopStateMap;
69  std::vector<SharedCudaTensorBuf> m_LstmInputs;
70  std::atomic<int32_t> m_InProgress{0};
71  std::mutex m_Mutex;
72  std::condition_variable m_Cond;
73  SharedCuEvent m_InputReadyEvent;
74  SharedCuStream m_LstmStream;
75 };
76 
77 } // namespace nvdsinferserver
78 
79 #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::LstmController::destroy
void destroy()
Definition: sources/libs/nvdsinferserver/infer_lstm.h:43
infer_base_context.h
Header file of the base class for inference context.
nvdsinferserver::SharedBatchBuf
std::shared_ptr< BaseBatchBuffer > SharedBatchBuf
Common buffer interfaces (internal).
Definition: sources/libs/nvdsinferserver/infer_common.h:76
nvdsinferserver::SharedBatchArray
std::shared_ptr< BaseBatchArray > SharedBatchArray
Definition: sources/libs/nvdsinferserver/infer_common.h:80
nvdsinferserver::SharedCuEvent
std::shared_ptr< CudaEvent > SharedCuEvent
Definition: sources/libs/nvdsinferserver/infer_common.h:91
nvdsinferserver::LstmController::waitAndGetInputs
NvDsInferStatus waitAndGetInputs(SharedBatchArray &inputs)
infer_common.h
Header file of the common declarations for the nvinferserver library.
infer_proto_utils.h
nvdsinferserver::LstmController::~LstmController
~LstmController()=default
nvdsinferserver::LstmController
Definition: sources/libs/nvdsinferserver/infer_lstm.h:29
nvdsinferserver::SharedCuStream
std::shared_ptr< CudaStream > SharedCuStream
Cuda based pointers.
Definition: sources/libs/nvdsinferserver/infer_common.h:89
nvdsinferserver::UniqLock
std::unique_lock< std::mutex > UniqLock
Miscellaneous declarations.
Definition: sources/libs/nvdsinferserver/infer_common.h:113
nvdsinferserver::LstmController::notifyError
void notifyError(NvDsInferStatus status)
infer_utils.h
Header file containing utility functions and classes used by the nvinferserver low level library.
nvdsinferserver::LstmController::LstmController
LstmController(const ic::LstmParams &params, int devId, int maxBatchSize)
Definition: sources/libs/nvdsinferserver/infer_lstm.h:31
nvdsinferserver::SharedCudaTensorBuf
std::shared_ptr< CudaTensorBuf > SharedCudaTensorBuf
Definition: sources/libs/nvdsinferserver/infer_common.h:96
nvdsinferserver::BaseBackend
Base class of inference backend processing.
Definition: sources/libs/nvdsinferserver/infer_base_backend.h:45
nvdsinferserver::LstmController::initInputState
NvDsInferStatus initInputState(BaseBackend &backend)
nvdsinferserver::LstmController::feedbackInputs
NvDsInferStatus feedbackInputs(SharedBatchArray &outTensors)
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: sources/includes/nvdsinfer.h:231