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.

generate_graph.h 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 MINDSPORE_CCSRC_PARALLEL_GRAPH_UTIL_GENERATE_GRAPH_H_
  17. #define MINDSPORE_CCSRC_PARALLEL_GRAPH_UTIL_GENERATE_GRAPH_H_
  18. #include <map>
  19. #include <memory>
  20. #include <string>
  21. #include <unordered_map>
  22. #include <utility>
  23. #include <vector>
  24. #include "./common.h"
  25. #include "optimizer/opt.h"
  26. #include "parallel/strategy.h"
  27. #include "parallel/tensor_layout/tensor_redistribution.h"
  28. namespace mindspore {
  29. namespace parallel {
  30. #define USING_HASH_NAME "USING_HASH_NAME"
  31. // Get the operator's path where the operator has be defined
  32. std::string GetOpPythonPath(const OperatorName &op_name);
  33. // Init python operator Instance
  34. ValuePtr CreatOpInstance(const OperatorAttrs &attrs, const OperatorName &op_name, const std::string &instance_name);
  35. AnfNodePtr CreatTypeInt(int32_t value);
  36. AnfNodePtr CreatInt32Imm(int32_t value);
  37. AnfNodePtr CreateInt32Tensor(int32_t value);
  38. std::string HashInstanceName(const std::string &name);
  39. class GenerateGraph {
  40. public:
  41. GenerateGraph() : name_idx_(0) {}
  42. Status Init(const CNodePtr &cnode);
  43. ~GenerateGraph() = default;
  44. AnfNodePtr virtual_input_node() { return virtual_input_node_; }
  45. AnfNodePtr NewOpInst(const OperatorName &op_name, const OperatorAttrs &attrs);
  46. AnfNodePtr NewOpInst(const OperatorName &op_name);
  47. AnfNodePtr PushBack(const std::vector<AnfNodePtr> &inputs);
  48. private:
  49. CNodePtr cnode_;
  50. FuncGraphManagerPtr manager_;
  51. ScopePtr scope_;
  52. FuncGraphPtr func_graph_;
  53. AnfNodePtr virtual_input_node_;
  54. std::string instance_name_base_;
  55. int64_t name_idx_;
  56. };
  57. } // namespace parallel
  58. } // namespace mindspore
  59. #endif // MINDSPORE_CCSRC_PARALLEL_GRAPH_UTIL_GENERATE_GRAPH_H_