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.

graph_runner.h 2.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Copyright 2019 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 TRANSFORM_GRAPH_RUNNER_H_
  17. #define TRANSFORM_GRAPH_RUNNER_H_
  18. #include <set>
  19. #include <string>
  20. #include <vector>
  21. #include <map>
  22. #include <memory>
  23. #include "transform/types.h"
  24. #include "transform/util.h"
  25. #include "ir/meta_tensor.h"
  26. #include "transform/df_graph_manager.h"
  27. namespace mindspore {
  28. namespace transform {
  29. using SessionOptions = std::map<std::string, std::string>;
  30. struct GraphRunnerOptions {
  31. std::string target{"default_graph_runner"};
  32. SessionOptions options;
  33. // if sess_ptr is nullptr, GraphRunner will create a new ge session
  34. std::shared_ptr<ge::Session> sess_ptr{nullptr};
  35. };
  36. struct RunOptions {
  37. // graph's name
  38. std::string name;
  39. };
  40. class GraphRunner {
  41. public:
  42. explicit GraphRunner(const GraphRunnerOptions &options);
  43. ~GraphRunner() { sess_ = nullptr; }
  44. Status RunGraph(const RunOptions &options, const std::vector<MeTensorPtr> &inputs, std::vector<MeTensorPtr> *outputs);
  45. Status RunGraph(const RunOptions &options, const std::vector<GeTensorPtr> &inputs, std::vector<GeTensorPtr> *outputs);
  46. static std::shared_ptr<ge::Session> NewSession(const SessionOptions &sess_options);
  47. private:
  48. std::shared_ptr<ge::Session> sess_;
  49. transform::GraphRunnerOptions options_;
  50. DfGraphManager &graph_manager_;
  51. };
  52. } // namespace transform
  53. } // namespace mindspore
  54. #endif // TRANSFORM_GRAPH_RUNNER_H_