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

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

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