You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

server.h 1.8 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef MINDSPORE_SERVER_H
  17. #define MINDSPORE_SERVER_H
  18. #include <string>
  19. #include <mutex>
  20. #include <vector>
  21. #include <memory>
  22. #include "util/status.h"
  23. #include "version_control/model.h"
  24. #include "include/inference.h"
  25. #include "serving/ms_service.pb.h"
  26. #include "serving/ms_service.grpc.pb.h"
  27. namespace mindspore {
  28. namespace serving {
  29. using ms_serving::PredictReply;
  30. using ms_serving::PredictRequest;
  31. class Session {
  32. public:
  33. static Session &Instance();
  34. Status CreatDeviceSession(const std::string &device, uint32_t device_id);
  35. // Status Predict(const inference::MultiTensor &inputs, inference::MultiTensor &output);
  36. Status Predict(const PredictRequest &request, PredictReply &reply);
  37. Status Warmup(const MindSporeModelPtr model);
  38. Status Clear();
  39. private:
  40. Session() = default;
  41. ~Session() = default;
  42. int sesseion_id_{0};
  43. std::shared_ptr<inference::InferSession> session_{nullptr};
  44. bool model_loaded_ = false;
  45. uint32_t graph_id_{0};
  46. std::mutex mutex_;
  47. std::string device_type_;
  48. };
  49. class Server {
  50. public:
  51. Server() = default;
  52. ~Server() = default;
  53. Status BuildAndStart();
  54. };
  55. } // namespace serving
  56. } // namespace mindspore
  57. #endif // MINDSPORE_SERVER_H