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_execution.h 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 PREDICT_SRC_GRAPH_EXECUTION_H_
  17. #define PREDICT_SRC_GRAPH_EXECUTION_H_
  18. #include <map>
  19. #include <deque>
  20. #include <fstream>
  21. #include <sstream>
  22. #include <unordered_map>
  23. #include <unordered_set>
  24. #include <vector>
  25. #include "common/mslog.h"
  26. #include "src/graph.h"
  27. #include "include/errorcode.h"
  28. #include "schema/inner/ms_generated.h"
  29. #include "src/operator/cpu/include/op_func_comm.h"
  30. #include "src/node.h"
  31. namespace mindspore {
  32. namespace predict {
  33. class GraphExecution {
  34. public:
  35. explicit GraphExecution(const Context &ctx);
  36. GraphExecution(const Context &ctx, Graph *staticGraph);
  37. virtual ~GraphExecution();
  38. virtual std::vector<Tensor *> GetInput();
  39. virtual int SetInputTensors(const std::vector<Tensor *> &inputs);
  40. virtual int Run(const std::vector<Tensor *> &inputs);
  41. virtual std::map<NODE_ID, std::vector<Tensor *>> GetAllOutput();
  42. virtual std::vector<Tensor *> GetOutput(const NODE_ID &nodeName);
  43. private:
  44. void ResetInputData();
  45. int MallocOutput();
  46. void FreeTensors(std::vector<Tensor *> *tensors);
  47. int TransInputDataToNc4hw4(const Tensor &src, Tensor *dst);
  48. int CopyOutputTensors(const std::vector<Tensor *> &refOutputs, std::vector<Tensor *> *outputs);
  49. void FreeOutputMap(std::map<NODE_ID, std::vector<Tensor *>> *map);
  50. void FreeAllTensors();
  51. protected:
  52. Graph *graph;
  53. const Context &_ctx;
  54. std::vector<Tensor *> inputTensors;
  55. std::vector<Tensor *> outputTensors;
  56. std::unordered_map<Node *, std::unordered_set<Node *>> depends; // records the dependencies
  57. std::deque<Node *> readyQue; // the nodes which can execute without any dependencies
  58. };
  59. } // namespace predict
  60. } // namespace mindspore
  61. #endif // PREDICT_SRC_GRAPH_EXECUTION_H_