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.

instance.h 2.2 kB

5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_SERVING_INSTANCE_H
  17. #define MINDSPORE_SERVING_INSTANCE_H
  18. #include <vector>
  19. #include <unordered_map>
  20. #include <memory>
  21. #include <string>
  22. #include <future>
  23. #include "common/serving_common.h"
  24. #include "common/servable.h"
  25. namespace mindspore::serving {
  26. using InstanceData = std::vector<TensorBasePtr>;
  27. using TensorsData = std::vector<TensorBasePtr>;
  28. struct Instance;
  29. using InstancePtr = std::shared_ptr<Instance>;
  30. struct WorkerUserContext {
  31. RequestSpec request_spec;
  32. MethodSignature method_def;
  33. };
  34. enum InstancePhase {
  35. kInstancePhaseNone,
  36. kInstancePhasePreprocess,
  37. kInstancePhasePredict,
  38. kInstancePhasePostprocess,
  39. kInstancePhaseDone,
  40. };
  41. struct InstanceContext {
  42. uint64_t user_id = 0;
  43. uint32_t instance_index = 0;
  44. std::promise<void> promise;
  45. std::shared_ptr<WorkerUserContext> user_context = nullptr;
  46. bool operator==(const InstanceContext &other) const {
  47. return user_id == other.user_id && instance_index == other.instance_index;
  48. }
  49. };
  50. struct Instance {
  51. InstanceData data; // for inputs of preprocess, predict, postprocess or output
  52. InstanceData input_data; // input data
  53. InstanceData preprocess_data; // preprocess result
  54. InstanceData predict_data; // predict result
  55. InstanceData postprocess_data; // postprocess result
  56. InstanceContext context;
  57. InstancePhase phase = kInstancePhaseNone;
  58. Status error_msg = SUCCESS;
  59. };
  60. struct ResultInstance {
  61. InstanceData data;
  62. Status error_msg = SUCCESS;
  63. };
  64. } // namespace mindspore::serving
  65. #endif // MINDSPORE_SERVING_INSTANCE_H

A lightweight and high-performance service module that helps MindSpore developers efficiently deploy online inference services in the production environment.