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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 WorkCallBack = std::function<void(const Instance &output, const Status &error_msg)>;
  30. struct WorkerUserContext {
  31. WorkCallBack worker_call_back = nullptr;
  32. RequestSpec request_spec;
  33. MethodSignature method_def;
  34. };
  35. struct InstanceContext {
  36. uint64_t user_id = 0;
  37. uint32_t instance_index = 0;
  38. WorkCallBack worker_call_back = nullptr;
  39. std::shared_ptr<std::promise<void>> promise = nullptr;
  40. std::shared_ptr<WorkerUserContext> user_context = nullptr;
  41. RequestSpec request_spec;
  42. bool operator==(const InstanceContext &other) const {
  43. return user_id == other.user_id && instance_index == other.instance_index;
  44. }
  45. };
  46. struct Instance {
  47. InstanceData data; // for inputs of preprocess, predict, postprocess or output
  48. InstanceData input_data; // input data
  49. InstanceData preprocess_data; // preprocess result
  50. InstanceData predict_data; // predict result
  51. InstanceData postprocess_data; // postprocess result
  52. InstanceContext context;
  53. Status error_msg = SUCCESS;
  54. };
  55. struct ResultInstance {
  56. InstanceData data;
  57. Status error_msg = SUCCESS;
  58. };
  59. } // namespace mindspore::serving
  60. #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.