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_executor.h 6.6 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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_FRAMEWORK_EXECUTOR_GE_EXECUTOR_H_
  17. #define INC_FRAMEWORK_EXECUTOR_GE_EXECUTOR_H_
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. #include "common/ge_inner_error_codes.h"
  22. #include "common/ge_types.h"
  23. #include "common/types.h"
  24. #include "graph/tensor.h"
  25. #include "runtime/base.h"
  26. namespace ge {
  27. class ModelListenerAdapter;
  28. class SingleOp;
  29. struct RunModelData {
  30. uint32_t index; // Data index
  31. uint32_t model_id; // Model id
  32. std::vector<DataBuffer> blobs; // All input/output data buffer
  33. uint32_t timestamp; // Data creation time
  34. uint32_t timeout; // Processing timeout
  35. uint64_t request_id = 0; // Request ID
  36. };
  37. class GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY GeExecutor {
  38. public:
  39. GeExecutor();
  40. ~GeExecutor() = default;
  41. ge::Status Initialize();
  42. // Load model
  43. ge::Status LoadModelOffline(uint32_t &model_id, const std::string &path, const std::string &key, int32_t priority,
  44. std::shared_ptr<ge::ModelListener> listener);
  45. ge::Status UnloadModel(uint32_t model_id);
  46. ge::Status RunModel(const ge::RunModelData &input_data, ge::RunModelData &output_data);
  47. // Get input and output descriptor
  48. ge::Status GetModelDescInfo(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc,
  49. std::vector<ge::TensorDesc> &output_desc);
  50. ge::Status GetModelDescInfoForZeroCopy(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc,
  51. std::vector<ge::TensorDesc> &output_desc);
  52. ge::Status LoadModel(uint32_t &model_id, const ge::ModelData &model_data,
  53. std::shared_ptr<ge::ModelListener> listener);
  54. ge::Status CommandHandle(const ge::Command &command);
  55. ///
  56. /// @ingroup ge
  57. /// @brief Query model memory consuming interface
  58. /// @param [in] model_id Offline model ID
  59. /// @param [out] max_size Memory size
  60. /// @return SUCCESS
  61. /// @return FAILED
  62. ///
  63. ge::Status GetMaxUsedMemory(uint32_t model_id, uint32_t &max_size);
  64. ///
  65. /// @ingroup ge
  66. /// @brief Load data from model file to memory
  67. /// @param [in] const std::string &path: Offline model file path
  68. /// @param [out] ModelData &model_data: Offline model memory data
  69. /// @return SUCCESS handle successfully / others handle failed
  70. ///
  71. ge::Status LoadDataFromFile(const std::string &path, ge::ModelData &model_data);
  72. ///
  73. /// @ingroup ge
  74. /// @brief Load model from offline model memory data
  75. /// @param [in] ModelData &model_data: Offline model data
  76. /// @param [in] void *dev_ptr: Input/Output memory address
  77. /// @param [in] size_t mem_size: Input/Output memory length
  78. /// @param [in] void *weight_ptr: Weight memory address
  79. /// @param [in] size_t weight_size: Weight memory length
  80. /// @param [out] uint32_t &model_id: Corresponding identification after model loading
  81. /// @return SUCCESS handle successfully / others handle failed
  82. ///
  83. ge::Status LoadModelFromData(uint32_t &model_id, const ge::ModelData &model_data, void *dev_ptr, size_t mem_size,
  84. void *weight_ptr, size_t weight_size);
  85. ///
  86. /// @ingroup ge
  87. /// @brief Load task list from ModelData with queue.
  88. /// @param [out] model_id: model id allocate from manager.
  89. /// @param [in] model_data: Model data load from offline model.
  90. /// @param [in] input_queue_ids: input queue ids create from user.
  91. /// @param [in] output_queue_ids: input queue ids create from user.
  92. /// @return: 0 for success / others for fail
  93. ///
  94. ge::Status LoadModelWithQ(uint32_t &model_id, const ge::ModelData &model_data,
  95. const std::vector<uint32_t> &input_queue_ids,
  96. const std::vector<uint32_t> &output_queue_ids);
  97. ///
  98. /// @ingroup ge
  99. /// @brief Synchronous execution of offline model(Do not create thread)
  100. /// @param [in] uint32_t model_id: Model ID to execute
  101. /// @param [in] void* stream: stream to execute
  102. /// @param [in] bool async_mode: is asynchronize mode.
  103. /// @param [in] const domi::InputData *input_data: Model input data
  104. /// @param [out] domi::OutputData *output_data: Model output data
  105. /// @return SUCCESS handle successfully / others handle failed
  106. ///
  107. ge::Status ExecModel(uint32_t model_id, void *stream, const ge::RunModelData &input_data,
  108. ge::RunModelData &output_data, bool async_mode = false);
  109. ///
  110. /// @ingroup ge
  111. /// @brief Get weight memory size from model file
  112. /// @param [in] const std::string &path: Offline model file path
  113. /// @param [out] size_t &mem_size Execution memory size
  114. /// @param [out] size_t &weight_size Weight memory space size
  115. /// @return SUCCESS handle successfully / others handle failed
  116. ///
  117. ge::Status GetMemAndWeightSize(const std::string &path, size_t &mem_size, size_t &weight_size);
  118. ///
  119. /// @ingroup ge
  120. /// @brief Get weight memory size from model file
  121. /// @param [in] const void *model_data Offline model buffer
  122. /// @param [in] size_t model_size Offline model buffer length
  123. /// @param [out] size_t &mem_size Execution memory size
  124. /// @param [out] size_t &weight_size Weight memory space size
  125. /// @return SUCCESS handle successfully / others handle failed
  126. ///
  127. ge::Status GetMemAndWeightSize(const void *model_data, size_t model_size, size_t &mem_size, size_t &weight_size);
  128. static ge::Status LoadSingleOp(const std::string &model_name, const ge::ModelData &model_data, void *stream,
  129. SingleOp **single_op);
  130. static ge::Status ExecuteAsync(SingleOp *executor, const std::vector<DataBuffer> &inputs,
  131. std::vector<DataBuffer> &outputs);
  132. static ge::Status ReleaseSingleOpResource(void *stream);
  133. private:
  134. static bool is_init_;
  135. std::vector<std::shared_ptr<ModelListenerAdapter>> listener_adapters_;
  136. };
  137. ge::Status ModelInfoParser(const ge::ModelData &model, ge::ModelInfo &model_info);
  138. } // namespace ge
  139. #endif // INC_FRAMEWORK_EXECUTOR_GE_EXECUTOR_H_

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

Contributors (1)