triton_engine.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <iostream>
  16. #include <string>
  17. #include <vector>
  18. #include <memory>
  19. #include "./common.h"
  20. #include "./http_client.h"
  21. #include "rapidjson/document.h"
  22. #include "rapidjson/rapidjson.h"
  23. #include "rapidjson/error/en.h"
  24. #include "model_deploy/common/include/output_struct.h"
  25. #include "model_deploy/engine/include/engine.h"
  26. #include "model_deploy/common/include/base_model.h"
  27. namespace nic = nvidia::inferenceserver::client;
  28. namespace PaddleDeploy {
  29. class TritonInferenceEngine : public InferEngine {
  30. public:
  31. std::unique_ptr<nic::InferenceServerHttpClient> client_;
  32. TritonInferenceEngine() : options_("") {}
  33. bool Init(const InferenceConfig& engine_configs);
  34. bool Infer(const std::vector<DataBlob>& input_blobs,
  35. std::vector<DataBlob>* output_blobs);
  36. private:
  37. nic::InferOptions options_;
  38. nic::Headers headers_;
  39. nic::Parameters query_params_;
  40. void ParseConfigs(const TritonEngineConfig& configs);
  41. void CreateInput(const std::vector<DataBlob>& input_blobs,
  42. std::vector<nic::InferInput* >* inputs);
  43. void CreateOutput(const rapidjson::Document& model_metadata,
  44. std::vector<const nic::InferRequestedOutput* >* outputs);
  45. nic::Error GetModelMetaData(rapidjson::Document* model_metadata);
  46. };
  47. } // namespace PaddleDeploy