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 8.7 kB

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

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