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.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. AnfNodePtr ValuePtrToAnfNodePtr(const ValuePtr &value_ptr);
  39. std::string HashInstanceName(const std::string &name);
  40. class GenerateGraph {
  41. public:
  42. GenerateGraph() : name_idx_(0) {}
  43. Status Init(const CNodePtr &cnode);
  44. ~GenerateGraph() = default;
  45. AnfNodePtr virtual_input_node() { return virtual_input_node_; }
  46. AnfNodePtr NewOpInst(const OperatorName &op_name, const OperatorAttrs &attrs);
  47. AnfNodePtr NewOpInst(const OperatorName &op_name);
  48. AnfNodePtr PushBack(const std::vector<AnfNodePtr> &inputs);
  49. private:
  50. CNodePtr cnode_;
  51. FuncGraphManagerPtr manager_;
  52. ScopePtr scope_;
  53. FuncGraphPtr func_graph_;
  54. AnfNodePtr virtual_input_node_;
  55. std::string instance_name_base_;
  56. int64_t name_idx_;
  57. };
  58. } // namespace parallel
  59. } // namespace mindspore
  60. #endif // MINDSPORE_CCSRC_PARALLEL_GRAPH_UTIL_GENERATE_GRAPH_H_