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.

omg.h 4.7 kB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * Copyright 2020 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 INC_FRAMEWORK_OMG_OMG_H_
  17. #define INC_FRAMEWORK_OMG_OMG_H_
  18. #include <google/protobuf/message.h>
  19. #include <string>
  20. #include <unordered_map>
  21. #include <vector>
  22. #include "framework/omg/omg_inner_types.h"
  23. #include "framework/omg/parser/parser_inner_ctx.h"
  24. #include "proto/ge_ir.pb.h"
  25. #include "proto/om.pb.h"
  26. #include "graph/compute_graph.h"
  27. #include "graph/graph.h"
  28. #include "graph/model.h"
  29. #include "runtime/kernel.h"
  30. using domi::Status;
  31. using std::pair;
  32. using std::string;
  33. using std::unordered_map;
  34. using std::vector;
  35. namespace ge {
  36. /**
  37. * @ingroup domi_omg
  38. * @brief init omg context
  39. * @return void
  40. */
  41. GE_FUNC_VISIBILITY Status InitDomiOmgContext(const string &input_shape, const string &input_format,
  42. const string &net_format, bool is_dynamic_input);
  43. /**
  44. * @ingroup domi_omg
  45. * @brief generate graph based on the input model file and weight file
  46. * @param [out] graph graph
  47. * @param [in] model_file path of model file
  48. * @param [in] weights_file path of weight file
  49. * @param [in] type type of the input model
  50. * @param [in] op_conf op mapping configuration
  51. * @param [in] target type of platform. If a tiny model is generated, set target to tiny
  52. * @param [in] run_mode run model
  53. * @param [in] enable_l2dynamic enable l2dynamic
  54. * @param [in] is_dynamic_input dynamic input, true of false
  55. * @param [in] atc_params multiply atc params
  56. * @return Status result code
  57. */
  58. GE_FUNC_VISIBILITY Status ParseGraph(ge::Graph &graph, const std::map<string, string> &atc_params,
  59. const char *model_file, const char *weights_file, domi::FrameworkType type,
  60. const char *op_conf = nullptr, const char *target = nullptr,
  61. RunMode run_mode = GEN_OM_MODEL, bool is_dynamic_input = false);
  62. /**
  63. * @ingroup domi_omg
  64. * @brief generates a simplified JSON file based on the key value of the offline model file in protobuf format
  65. * @param [in] model_file path of offline model file
  66. * @param [out] json_file path of json file
  67. * @param [key] encrypted key
  68. * @return Status result code
  69. */
  70. GE_FUNC_VISIBILITY Status ConvertOm(const char *model_file, const char *json_file, bool is_covert_to_json);
  71. GE_FUNC_VISIBILITY Status ConvertPbtxtToJson(const char *model_file, const char *json_file);
  72. /**
  73. * @ingroup domi_omg
  74. * @brief convert the model file in protobuf format into a JSON file.
  75. * @param [in] framework type of model
  76. * @param [in] om model_file path of offline model file
  77. * @param [out] json_file path of json file
  78. * @param [key] encrypted key
  79. * @return Status result code
  80. */
  81. GE_FUNC_VISIBILITY Status ConvertFwkModelToJson(domi::FrameworkType framework, const char *model_file,
  82. const char *json_file);
  83. GE_FUNC_VISIBILITY void GetGroupName(ge::proto::ModelDef &model);
  84. GE_FUNC_VISIBILITY void FindParserSo(const string &path, vector<string> &fileList, string &caffe_parser_path);
  85. GE_FUNC_VISIBILITY Status DumpInfershapeJson(const ge::Graph &graph, const char *json_file);
  86. GE_FUNC_VISIBILITY Status SetOutputNodeInfo(ge::Graph &graph, const std::string &output_type,
  87. const std::string &output_format);
  88. GE_FUNC_VISIBILITY Status GetOutputLeaf(ge::NodePtr node,
  89. std::vector<std::pair<ge::NodePtr, int32_t>> &output_nodes_info);
  90. GE_FUNC_VISIBILITY void GetOutputNodesNameAndIndex(std::vector<std::pair<ge::NodePtr, int32_t>> &output_nodes_info,
  91. std::vector<std::string> &output_nodes_name);
  92. GE_FUNC_VISIBILITY void UpdateOmgCtxWithParserCtx();
  93. GE_FUNC_VISIBILITY void UpdateParserCtxWithOmgCtx();
  94. GE_FUNC_VISIBILITY void PrintModelInfo(ge::proto::ModelDef *model_def, uint32_t modeldef_size);
  95. } // namespace ge
  96. namespace domi {
  97. /**
  98. * @ingroup domi_omg
  99. * @brief get omg context
  100. * @return reference of OmgContext
  101. */
  102. GE_FUNC_VISIBILITY ge::OmgContext &GetContext();
  103. } // namespace domi
  104. #endif // INC_FRAMEWORK_OMG_OMG_H_

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知。GE主要由GE API和GE Core两部分组成,详细的架构图如下所示