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.

model_parallel_runner.h 2.7 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright 2022 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_INCLUDE_API_MODEL_PARALLEL_RUNNER_H
  17. #define MINDSPORE_INCLUDE_API_MODEL_PARALLEL_RUNNER_H
  18. #include <vector>
  19. #include <memory>
  20. #include <utility>
  21. #include <string>
  22. #include "include/api/status.h"
  23. #include "include/api/context.h"
  24. namespace mindspore {
  25. struct RunnerConfig {
  26. std::shared_ptr<Context> context = nullptr;
  27. int workers_num = 0;
  28. };
  29. class ModelPool;
  30. /// \brief The ModelParallelRunner class is used to define a MindSpore ModelParallelRunner, facilitating Model
  31. /// management.
  32. class MS_API ModelParallelRunner {
  33. public:
  34. ModelParallelRunner() = default;
  35. ~ModelParallelRunner() = default;
  36. /// \brief build a model parallel runner from model path so that it can run on a device. Only valid for Lite.
  37. ///
  38. /// \param[in] model_path Define the model path.
  39. /// \param[in] runner_config Define the config used to store options during model pool init.
  40. ///
  41. /// \return Status.
  42. Status Init(const std::string &model_path, const std::shared_ptr<RunnerConfig> &runner_config = nullptr);
  43. /// \brief Obtains all input tensors information of the model.
  44. ///
  45. /// \return The vector that includes all input tensors.
  46. std::vector<MSTensor> GetInputs();
  47. /// \brief Obtains all output tensors information of the model.
  48. ///
  49. /// \return The vector that includes all output tensors.
  50. std::vector<MSTensor> GetOutputs();
  51. /// \brief Inference ModelParallelRunner.
  52. ///
  53. /// \param[in] inputs A vector where model inputs are arranged in sequence.
  54. /// \param[out] outputs Which is a pointer to a vector. The model outputs are filled in the container in sequence.
  55. /// \param[in] before CallBack before predict.
  56. /// \param[in] after CallBack after predict.
  57. ///
  58. /// \return Status.
  59. Status Predict(const std::vector<MSTensor> &inputs, std::vector<MSTensor> *outputs,
  60. const MSKernelCallBack &before = nullptr, const MSKernelCallBack &after = nullptr);
  61. private:
  62. std::shared_ptr<ModelPool> model_pool_ = nullptr;
  63. };
  64. } // namespace mindspore
  65. #endif // MINDSPORE_INCLUDE_API_MODEL_PARALLEL_RUNNER_H