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

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

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