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.7 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 "mindspore/ccsrc/debug/info.h"
  26. namespace mindspore {
  27. namespace serving {
  28. class Session {
  29. public:
  30. static Session &Instance();
  31. Status CreatDeviceSession(const std::string &device, uint32_t device_id);
  32. Status Predict(const std::vector<std::shared_ptr<inference::MSTensor>> &inputs, inference::MultiTensor *output);
  33. Status Warmup(const MindSporeModelPtr model);
  34. Status Clear();
  35. private:
  36. Session() = default;
  37. ~Session() = default;
  38. int sesseion_id_{0};
  39. std::shared_ptr<inference::MSSession> session_{nullptr};
  40. FuncGraphPtr last_graph_{nullptr};
  41. uint32_t graph_id_{0};
  42. std::mutex mutex_;
  43. std::string device_type_;
  44. };
  45. class Server {
  46. public:
  47. Server() = default;
  48. ~Server() = default;
  49. Status BuildAndStart();
  50. };
  51. } // namespace serving
  52. } // namespace mindspore
  53. #endif // MINDSPORE_SERVER_H