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

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