NVIDIA DeepStream SDK API Reference

9.1 Release
sources/libs/nvdsinferserver/infer_grpc_client.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2021-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 
26 #ifndef __INFER_GRPC_CLIENT_H__
27 #define __INFER_GRPC_CLIENT_H__
28 
29 #include <stdarg.h>
30 #include <condition_variable>
31 #include <functional>
32 #include <list>
33 #include <memory>
34 #include <mutex>
35 #include <queue>
36 
37 #include "infer_icontext.h"
38 #include "infer_post_datatypes.h"
39 #include "infer_common.h"
40 #include "grpc_client.h"
41 
42 
43 namespace tc = triton::client;
44 
45 namespace nvdsinferserver {
46 
47 typedef std::map<std::string, std::string> Headers;
48 
49 class TritonGrpcRequest;
50 
51 using SharedGrpcRequest = std::shared_ptr<TritonGrpcRequest>;
52 
54 
55 
61 public:
69  NvDsInferStatus appendInput(const std::shared_ptr<tc::InferInput> &input);
74  NvDsInferStatus setOutput(const std::vector<std::shared_ptr<tc::InferRequestedOutput>> &output);
75  NvDsInferStatus setOption(std::shared_ptr<tc::InferOptions> &option);
76  std::vector<std::shared_ptr<tc::InferInput>> inputs() { return m_InferInputs; }
77  std::vector<std::shared_ptr<tc::InferRequestedOutput>> outputs() { return m_RequestOutputs; }
78  std::shared_ptr<tc::InferOptions> getOption() {return m_InferOptions;}
79  SharedIBatchArray inputBatchArray() { return m_InputBatchArray;}
80  void setInputBatchArray(SharedIBatchArray inputBatch) { m_InputBatchArray = inputBatch;}
81  std::vector<std::string> getOutNames() { return m_OutputNames;}
82  std::vector<std::string> getInputCudaBufNames() { return m_InputCudaBufNames;}
83  void setOutNames(std::vector<std::string> outnames) {m_OutputNames = outnames;}
89  void attachData(void *data) {
90  m_CpuData.push_back(data);
91  }
92 
96  void attachInputCudaBuffer(std::string bufName) {
97  m_InputCudaBufNames.push_back(bufName);
98  }
99 
100 private:
104  std::vector<std::shared_ptr<tc::InferInput>> m_InferInputs;
108  std::vector<std::shared_ptr<tc::InferRequestedOutput>> m_RequestOutputs;
112  std::shared_ptr<tc::InferOptions> m_InferOptions;
116  std::vector<std::string> m_OutputNames;
120  SharedIBatchArray m_InputBatchArray;
124  std::vector<void*> m_CpuData;
128  std::vector<std::string> m_InputCudaBufNames;
129 };
130 
136 public:
142  InferGrpcClient (std::string url, bool enableCudaBufferSharing);
159  NvDsInferStatus getModelMetadata(inference::ModelMetadataResponse *model_metadata,
160  std::string &model_name, std::string &model_version);
169  NvDsInferStatus getModelConfig(inference::ModelConfigResponse *config, const std::string &name,
170  const std::string &version = "", const Headers &headers = Headers());
174  bool isServerLive();
178  bool isServerReady();
182  bool isModelReady(const std::string &model, const std::string version = "");
186  NvDsInferStatus LoadModel(const std::string& model_name, const Headers& headers = Headers());
190  NvDsInferStatus UnloadModel(const std::string& model_name, const Headers& headers = Headers());
203  SharedGrpcRequest createRequest(const std::string& model, const std::string &version, SharedIBatchArray input,
204  const std::vector<std::string> &outputs,
205  const std::vector<TritonClassParams>& classList = std::vector<TritonClassParams>());
206 
216 
217 private:
226  void InferComplete (tc::InferResult *result, SharedGrpcRequest request,
227  TritonGrpcAsyncDone done);
235  NvDsInferStatus parseOptions(tc::InferOptions *outOpt, const IOptions *inOpt);
244  tc::Error SetInputCudaSharedMemory(tc::InferInput *inferInput,
245  const SharedBatchBuf& inbuf, SharedGrpcRequest request, uint64_t bufId);
246 
247 private:
251  std::string m_Url;
255  bool m_EnableCudaBufferSharing;
259  std::unique_ptr<tc::InferenceServerGrpcClient> m_GrpcClient;
263  std::atomic<uint64_t> m_LastRequestId{UINT64_C(0)};
264 };
265 
266 } // namespace nvdsinferserver
267 
268 #endif
nvdsinferserver::TritonGrpcRequest::setInputBatchArray
void setInputBatchArray(SharedIBatchArray inputBatch)
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:80
nvdsinferserver::TritonGrpcRequest::getInputCudaBufNames
std::vector< std::string > getInputCudaBufNames()
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:82
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::InferGrpcClient::inferAsync
NvDsInferStatus inferAsync(SharedGrpcRequest request, TritonGrpcAsyncDone done)
Get the inference input and output list from the request and trigger the asynchronous inference reque...
nvdsinferserver::TritonGrpcAsyncDone
std::function< void(NvDsInferStatus, SharedBatchArray)> TritonGrpcAsyncDone
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:53
nvdsinferserver::InferGrpcClient::isServerLive
bool isServerLive()
Check if the Triton Inference Server is live.
nvdsinferserver::TritonGrpcRequest::inputBatchArray
SharedIBatchArray inputBatchArray()
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:79
nvdsinferserver::Headers
std::map< std::string, std::string > Headers
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:47
nvdsinferserver::InferGrpcClient::InferGrpcClient
InferGrpcClient(std::string url, bool enableCudaBufferSharing)
Constructor, save the server server URL and CUDA sharing flag.
nvdsinferserver::InferGrpcClient::~InferGrpcClient
~InferGrpcClient()
Destructor, default.
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::InferGrpcClient::LoadModel
NvDsInferStatus LoadModel(const std::string &model_name, const Headers &headers=Headers())
Request to load the given model using the Triton client library.
nvdsinferserver::TritonGrpcRequest::getOutNames
std::vector< std::string > getOutNames()
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:81
nvdsinferserver::TritonGrpcRequest::attachData
void attachData(void *data)
Append the array of host memory allocations.
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:89
nvdsinferserver::InferGrpcClient::isServerReady
bool isServerReady()
Check if the Triton Inference Server is ready.
nvdsinferserver::InferGrpcClient::isModelReady
bool isModelReady(const std::string &model, const std::string version="")
Check if the specified model is ready for inference.
infer_common.h
Header file of the common declarations for the nvinferserver library.
nvdsinferserver::TritonGrpcRequest::getOption
std::shared_ptr< tc::InferOptions > getOption()
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:78
nvdsinferserver::TritonGrpcRequest::~TritonGrpcRequest
~TritonGrpcRequest()
Destructor, free the host memory allocated for the request.
nvdsinferserver::TritonGrpcRequest::attachInputCudaBuffer
void attachInputCudaBuffer(std::string bufName)
Append the list of shared CUDA input buffers.
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:96
nvdsinferserver::TritonGrpcRequest::outputs
std::vector< std::shared_ptr< tc::InferRequestedOutput > > outputs()
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:77
nvdsinferserver::TritonGrpcRequest::setOutNames
void setOutNames(std::vector< std::string > outnames)
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:83
nvdsinferserver::InferGrpcClient::getModelMetadata
NvDsInferStatus getModelMetadata(inference::ModelMetadataResponse *model_metadata, std::string &model_name, std::string &model_version)
Get the model metadata from the Triton Inference server.
nvdsinferserver::TritonGrpcRequest::appendInput
NvDsInferStatus appendInput(const std::shared_ptr< tc::InferInput > &input)
Append the array of Triton client library inference input objects.
nvdsinferserver::TritonGrpcRequest::inputs
std::vector< std::shared_ptr< tc::InferInput > > inputs()
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:76
nvdsinferserver::TritonGrpcRequest::setOutput
NvDsInferStatus setOutput(const std::vector< std::shared_ptr< tc::InferRequestedOutput >> &output)
Helper functions to access the member variables.
nvdsinferserver::TritonGrpcRequest
Triton gRPC inference request class holding data associated with one inference request.
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:60
nvdsinferserver::InferGrpcClient::UnloadModel
NvDsInferStatus UnloadModel(const std::string &model_name, const Headers &headers=Headers())
Request to unload the given model using the Triton client library.
nvdsinferserver::InferGrpcClient
Wrapper class for the gRPC client of the Triton Inference Server, interfaces with the Triton client l...
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:135
nvdsinferserver::IOptions
Definition: sources/includes/nvdsinferserver/infer_ioptions.h:59
nvdsinferserver::InferGrpcClient::Initialize
NvDsInferStatus Initialize()
Create the gRPC client instance of the Triton Client library.
nvdsinferserver::InferGrpcClient::getModelConfig
NvDsInferStatus getModelConfig(inference::ModelConfigResponse *config, const std::string &name, const std::string &version="", const Headers &headers=Headers())
Get the model configuration from the Triton Inference Server.
nvdsinferserver::SharedGrpcRequest
std::shared_ptr< TritonGrpcRequest > SharedGrpcRequest
Definition: sources/libs/nvdsinferserver/infer_grpc_client.h:51
nvdsinferserver::SharedIBatchArray
std::shared_ptr< IBatchArray > SharedIBatchArray
Definition: sources/includes/nvdsinferserver/infer_datatypes.h:210
nvdsinferserver::TritonGrpcRequest::setOption
NvDsInferStatus setOption(std::shared_ptr< tc::InferOptions > &option)
nvdsinferserver::InferGrpcClient::createRequest
SharedGrpcRequest createRequest(const std::string &model, const std::string &version, SharedIBatchArray input, const std::vector< std::string > &outputs, const std::vector< TritonClassParams > &classList=std::vector< TritonClassParams >())
Create a new gRPC inference request.
NvDsInferStatus
NvDsInferStatus
Enum for the status codes returned by NvDsInferContext.
Definition: sources/includes/nvdsinfer.h:231