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

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. // Initialize GE
  28. Status GEInitialize(const std::map<std::string, std::string> &options);
  29. // Finalize GE, release all resources
  30. Status GEFinalize();
  31. class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Session {
  32. public:
  33. explicit Session(const std::map<std::string, std::string> &options);
  34. ~Session();
  35. ///
  36. /// @ingroup client
  37. /// @brief add a graph with a specific graphId
  38. /// @param [in] graphId graph id
  39. /// @return Status result of function
  40. ///
  41. Status AddGraph(uint32_t graphId, const Graph &graph);
  42. ///
  43. /// @ingroup client
  44. /// @brief add a graph with a specific graphId and graphOptions
  45. /// @param [in] graphId graph id
  46. /// @param [in] graph the graph
  47. /// @param [in] options graph options
  48. /// @return Status result of function
  49. ///
  50. Status AddGraph(uint32_t graphId, const Graph &graph, const std::map<std::string, std::string> &options);
  51. ///
  52. /// @ingroup ge_graph
  53. /// @brief remove a graph of the session with specific session id
  54. /// @param [in] graphId graph id
  55. /// @return Status result of function
  56. ///
  57. Status RemoveGraph(uint32_t graphId);
  58. ///
  59. /// @ingroup ge_graph
  60. /// @brief run a graph of the session with specific session id
  61. /// @param [in] graphId graph id
  62. /// @param [in] inputs input data
  63. /// @param [out] outputs output data
  64. /// @return Status result of function
  65. ///
  66. Status RunGraph(uint32_t graphId, const std::vector<Tensor> &inputs, std::vector<Tensor> &outputs);
  67. ///
  68. /// @ingroup ge_graph
  69. /// @brief run graph in the session with specific session id asynchronously
  70. /// @param [in] graphId: graph id
  71. /// @param [in] inputs: input data
  72. /// @param [out] callback: callback while runing graph has been finished.
  73. /// The callback function will not be checked.
  74. /// Please ensure that the implementation of the function is trusted.
  75. /// @return Status result of function
  76. ///
  77. Status RunGraphAsync(uint32_t graphId, const std::vector<ge::InputTensorInfo> &inputs, RunAsyncCallback callback);
  78. ///
  79. /// @ingroup ge_graph
  80. /// @brief register callback func with specific summary or checkpoint by users
  81. /// @param [in] key: func key
  82. /// @param [in] callback: callback specific summary or checkpoint.
  83. /// The callback function will not be checked.
  84. /// Please ensure that the implementation of the function is trusted.
  85. /// @return Status result of function
  86. ///
  87. Status RegisterCallBackFunc(const std::string &key, const pCallBackFunc &callback);
  88. bool IsGraphNeedRebuild(uint32_t graphId);
  89. private:
  90. uint64_t sessionId_;
  91. };
  92. } // namespace ge
  93. #endif // INC_EXTERNAL_GE_GE_API_H_

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