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_api.h 7.2 kB

5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_GE_API_H_
  17. #define INC_EXTERNAL_GE_GE_API_H_
  18. #include <map>
  19. #include <string>
  20. #include <vector>
  21. #include "ge/ge_api_error_codes.h"
  22. #include "ge/ge_api_types.h"
  23. #include "graph/graph.h"
  24. #include "graph/tensor.h"
  25. namespace ge {
  26. typedef uint32_t (*pCallBackFunc)(uint32_t graph_id, const std::map<std::string, ge::Tensor> &params_list);
  27. namespace session {
  28. typedef uint32_t (*pCallBackFunc)(uint32_t graph_id, const std::map<AscendString, ge::Tensor> &params_list);
  29. }
  30. // Initialize GE
  31. ATTRIBUTED_DEPRECATED(GE_FUNC_VISIBILITY Status GEInitialize(const std::map<AscendString, AscendString> &))
  32. GE_FUNC_VISIBILITY Status GEInitialize(const std::map<std::string, std::string> &options);
  33. GE_FUNC_VISIBILITY Status GEInitialize(const std::map<AscendString, AscendString> &options);
  34. // Finalize GE, release all resources
  35. GE_FUNC_VISIBILITY Status GEFinalize();
  36. GE_FUNC_VISIBILITY std::string GEGetErrorMsg();
  37. GE_FUNC_VISIBILITY std::string GEGetWarningMsg();
  38. class GE_FUNC_VISIBILITY Session {
  39. public:
  40. ATTRIBUTED_DEPRECATED(Session(const std::map<AscendString, AscendString> &))
  41. explicit Session(const std::map<std::string, std::string> &options);
  42. explicit Session(const std::map<AscendString, AscendString> &options);
  43. ~Session();
  44. ///
  45. /// @ingroup client
  46. /// @brief add a graph with a specific graph id
  47. /// @param [in] graph_id graph id
  48. /// @return Status result of function
  49. ///
  50. Status AddGraph(uint32_t graph_id, const Graph &graph);
  51. ///
  52. /// @ingroup client
  53. /// @brief add a graph with a specific graph id and graphOptions
  54. /// @param [in] graphId graph id
  55. /// @param [in] graph the graph
  56. /// @param [in] options graph options
  57. /// @return Status result of function
  58. ///
  59. ATTRIBUTED_DEPRECATED(Status AddGraph(uint32_t, const Graph &, const std::map<AscendString, AscendString> &))
  60. Status AddGraph(uint32_t graphId, const Graph &graph, const std::map<std::string, std::string> &options);
  61. ///
  62. /// @ingroup client
  63. /// @brief add a graph with a specific graphId and graphOptions
  64. /// @param [in] graphId graph id
  65. /// @param [in] graph the graph
  66. /// @param [in] options graph options
  67. /// @return Status result of function
  68. ///
  69. Status AddGraph(uint32_t graphId, const Graph &graph, const std::map<AscendString, AscendString> &options);
  70. ///
  71. /// @ingroup client
  72. /// @brief add a copy graph with a specific graphId
  73. /// @param [in] graphId graph id
  74. /// @param [in] graph the graph
  75. /// @return Status result of function
  76. ///
  77. Status AddGraphWithCopy(uint32_t graph_id, const Graph &graph);
  78. ///
  79. /// @ingroup client
  80. /// @brief add a copy graph with a specific graphId and graphOptions
  81. /// @param [in] graphId graph id
  82. /// @param [in] graph the graph
  83. /// @param [in] options graph options
  84. /// @return Status result of function
  85. ///
  86. Status AddGraphWithCopy(uint32_t graph_id, const Graph &graph, const std::map<AscendString, AscendString> &options);
  87. ///
  88. /// @ingroup ge_graph
  89. /// @brief remove a graph of the session with specific session id
  90. /// @param [in] graph_d graph id
  91. /// @return Status result of function
  92. ///
  93. Status RemoveGraph(uint32_t graph_id);
  94. ///
  95. /// @ingroup ge_graph
  96. /// @brief run a graph of the session with specific session id
  97. /// @param [in] graphId graph id
  98. /// @param [in] inputs input data
  99. /// @param [out] outputs output data
  100. /// @return Status result of function
  101. ///
  102. Status RunGraph(uint32_t graphId, const std::vector<Tensor> &inputs, std::vector<Tensor> &outputs);
  103. ///
  104. /// @ingroup ge_graph
  105. /// @brief run a graph of the session with specific session id and specific stream asynchronously
  106. /// @param [in] graph_id graph id
  107. /// @param [in] stream specific stream
  108. /// @param [in] inputs input data
  109. /// @param [out] outputs output data
  110. /// @return Status result of function
  111. ///
  112. Status RunGraphWithStreamAsync(uint32_t graph_id, void *stream, const std::vector<Tensor> &inputs,
  113. std::vector<Tensor> &outputs);
  114. ///
  115. /// @ingroup ge_graph
  116. /// @brief build graph in the session with specific session id
  117. /// @param [in] graphId: graph id
  118. /// @param [in] inputs: input data
  119. /// @return Status result of function
  120. ///
  121. Status BuildGraph(uint32_t graphId, const std::vector<InputTensorInfo> &inputs);
  122. Status BuildGraph(uint32_t graphId, const std::vector<ge::Tensor> &inputs); /*lint !e148*/
  123. ///
  124. /// @ingroup ge_graph
  125. /// @brief run graph in the session with specific session id asynchronously
  126. /// @param [in] graphId: graph id
  127. /// @param [in] inputs: input data
  128. /// @param [out] callback: callback while runing graph has been finished.
  129. /// The callback function will not be checked.
  130. /// Please ensure that the implementation of the function is trusted.
  131. /// @return Status result of function
  132. ///
  133. Status RunGraphAsync(uint32_t graphId, const std::vector<ge::Tensor> &inputs, RunAsyncCallback callback);
  134. ///
  135. /// @ingroup ge_graph
  136. /// @brief get variables in the session with specific session id
  137. /// @param [in] var_names: variable names
  138. /// @param [out] var_values: variable values
  139. /// @return Status result of function
  140. ///
  141. ATTRIBUTED_DEPRECATED(Status GetVariables(const std::vector<std::string> &, std::vector<Tensor> &))
  142. Status GetVariables(const std::vector<std::string> &var_names, std::vector<Tensor> &var_values);
  143. ///
  144. /// @ingroup ge_graph
  145. /// @brief get variables in the session with specific session id
  146. /// @param [in] var_names: variable names
  147. /// @param [out] var_values: variable values
  148. /// @return Status result of function
  149. ///
  150. Status GetVariables(const std::vector<AscendString> &var_names, std::vector<Tensor> &var_values);
  151. ///
  152. /// @ingroup ge_graph
  153. /// @brief register callback func with specific summary or checkpoint by users
  154. /// @param [in] key: func key
  155. /// @param [in] callback: callback specific summary or checkpoint.
  156. /// The callback function will not be checked.
  157. /// Please ensure that the implementation of the function is trusted.
  158. /// @return Status result of function
  159. ///
  160. ATTRIBUTED_DEPRECATED(Status RegisterCallBackFunc(const char *, const session::pCallBackFunc &))
  161. Status RegisterCallBackFunc(const std::string &key, const pCallBackFunc &callback);
  162. Status RegisterCallBackFunc(const char *key, const session::pCallBackFunc &callback);
  163. bool IsGraphNeedRebuild(uint32_t graph_id);
  164. private:
  165. uint64_t sessionId_;
  166. };
  167. } // namespace ge
  168. #endif // INC_EXTERNAL_GE_GE_API_H_

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