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.

ge_ir_build.h 5.6 kB

3 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
4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * Copyright 2019-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_EXTERNAL_GE_IR_BUILD_H_
  17. #define INC_EXTERNAL_GE_IR_BUILD_H_
  18. #if defined(_MSC_VER)
  19. #ifdef FUNC_VISIBILITY
  20. #define GE_FUNC_VISIBILITY _declspec(dllexport)
  21. #else
  22. #define GE_FUNC_VISIBILITY
  23. #endif
  24. #else
  25. #ifdef FUNC_VISIBILITY
  26. #define GE_FUNC_VISIBILITY __attribute__((visibility("default")))
  27. #else
  28. #define GE_FUNC_VISIBILITY
  29. #endif
  30. #endif
  31. #include <string>
  32. #include <map>
  33. #include <memory>
  34. #include "graph/graph.h"
  35. #include "graph/ge_error_codes.h"
  36. namespace {
  37. const int IR_MAJOR_VERSION = 1;
  38. const int IR_MINOR_VERSION = 0;
  39. const int IR_PATCH_VERSION = 0;
  40. } // namespace
  41. namespace ge {
  42. struct ModelBufferData {
  43. std::shared_ptr<uint8_t> data = nullptr;
  44. uint64_t length;
  45. };
  46. enum aclgrphAttrType { ATTR_TYPE_KEEP_DTYPE = 0, ATTR_TYPE_WEIGHT_COMPRESS };
  47. /**
  48. * @ingroup AscendCL
  49. * @brief build model.Notice the model is stored in buffer
  50. *
  51. * @param global_options[IN] global init params for build
  52. * @retval GRAPH_SUCCESS The function is successfully executed.
  53. * @retval OtherValues Failure
  54. */
  55. ATTRIBUTED_DEPRECATED(GE_FUNC_VISIBILITY graphStatus aclgrphBuildInitialize(std::map<AscendString, AscendString> &))
  56. GE_FUNC_VISIBILITY graphStatus aclgrphBuildInitialize(std::map<std::string, std::string> global_options);
  57. GE_FUNC_VISIBILITY graphStatus aclgrphBuildInitialize(std::map<AscendString, AscendString> &global_options);
  58. /**
  59. * @ingroup AscendCL
  60. * @brief build model.Notice the model is stored in buffer
  61. *
  62. */
  63. GE_FUNC_VISIBILITY void aclgrphBuildFinalize();
  64. /**
  65. * @ingroup AscendCL
  66. * @brief build model.Notice the model is stored in buffer
  67. *
  68. * @param graph[IN] the graph ready to build
  69. * @param options[IN] options used for build
  70. * @param model[OUT] builded model
  71. * @retval GRAPH_SUCCESS The function is successfully executed.
  72. * @retval OtherValues Failure
  73. */
  74. ATTRIBUTED_DEPRECATED(GE_FUNC_VISIBILITY graphStatus aclgrphBuildModel(const ge::Graph &,
  75. const std::map<AscendString, AscendString> &,
  76. ModelBufferData &))
  77. GE_FUNC_VISIBILITY graphStatus aclgrphBuildModel(const ge::Graph &graph,
  78. const std::map<std::string, std::string> &build_options,
  79. ModelBufferData &model);
  80. GE_FUNC_VISIBILITY graphStatus aclgrphBuildModel(const ge::Graph &graph,
  81. const std::map<AscendString, AscendString> &build_options,
  82. ModelBufferData &model);
  83. /**
  84. * @ingroup AscendCL
  85. * @brief save model buffer to file
  86. *
  87. * @param output_file[IN] the file path to be saved
  88. * @param model[IN] model buffer data
  89. * @retval GRAPH_SUCCESS The function is successfully executed.
  90. * @retval OtherValues Failure
  91. */
  92. ATTRIBUTED_DEPRECATED(GE_FUNC_VISIBILITY graphStatus aclgrphSaveModel(const char *, const ModelBufferData &))
  93. GE_FUNC_VISIBILITY graphStatus aclgrphSaveModel(const string &output_file, const ModelBufferData &model);
  94. GE_FUNC_VISIBILITY graphStatus aclgrphSaveModel(const char *output_file, const ModelBufferData &model);
  95. /**
  96. * @ingroup AscendCL
  97. * @brief query IR interface version
  98. *
  99. * @param major_version[OUT] IR interface major version
  100. * @param minor_version[OUT] IR interface minor version
  101. * @param patch_version[OUT] IR interface patch version
  102. * @retval GRAPH_SUCCESS The function is successfully executed.
  103. * @retval OtherValues Failure
  104. */
  105. GE_FUNC_VISIBILITY graphStatus aclgrphGetIRVersion(int *major_version, int *minor_version, int *patch_version);
  106. /**
  107. * @ingroup AscendCL
  108. * @brief dump graph
  109. *
  110. * @param graph[IN] the graph ready to build
  111. * @param file[IN] file path
  112. * @param file[IN] file path string len
  113. * @retval GRAPH_SUCCESS The function is successfully executed.
  114. * @retval OtherValues Failure
  115. */
  116. GE_FUNC_VISIBILITY graphStatus aclgrphDumpGraph(const ge::Graph &graph, const char *file, const size_t len);
  117. /**
  118. * @ingroup AscendCL
  119. * @brief create single op graph
  120. *
  121. * @param op_type[IN] the op_type
  122. * @param inputs[IN] the inputdesc
  123. * @param outputs[IN] the outputdesc
  124. * @param graph[OUT] the graph
  125. * @retval GRAPH_SUCCESS The function is successfully executed.
  126. * @retval OtherValues Failure
  127. */
  128. GE_FUNC_VISIBILITY graphStatus aclgrphGenerateForOp(const AscendString &op_type, const std::vector<TensorDesc> &inputs,
  129. const std::vector<TensorDesc> &outputs, Graph &graph);
  130. /**
  131. * @name aclgrphSetOpAttr
  132. * @brief set attribute for operators in the configuration file
  133. * @param graph [IN/OUT] compute graph
  134. * @param attr_type [In] attribute type
  135. * @param cfg_path [IN] the config file path
  136. * @return graphStatus
  137. */
  138. GE_FUNC_VISIBILITY graphStatus aclgrphSetOpAttr(Graph &graph, aclgrphAttrType attr_type, const char *cfg_path);
  139. }; // namespace ge
  140. #endif // INC_EXTERNAL_GE_IR_BUILD_H_

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