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.

data_inputer.h 3.5 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * Copyright 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 GE_GRAPH_LOAD_NEW_MODEL_MANAGER_DATA_INPUTER_H_
  17. #define GE_GRAPH_LOAD_NEW_MODEL_MANAGER_DATA_INPUTER_H_
  18. #include <memory>
  19. #include <string>
  20. #include <vector>
  21. #include "common/blocking_queue.h"
  22. #include "common/ge_types.h"
  23. #include "common/types.h"
  24. namespace ge {
  25. ///
  26. /// @ingroup domi_ome
  27. /// @brief wrapper input data
  28. /// @author
  29. ///
  30. class InputDataWrapper {
  31. public:
  32. InputDataWrapper() : is_init(false) {}
  33. ~InputDataWrapper() {}
  34. ///
  35. /// @ingroup domi_ome
  36. /// @brief init InputData
  37. /// @param [in] input use input to init InputData
  38. /// @param [in] output data copy dest address
  39. /// @return SUCCESS success
  40. /// @return other init failed
  41. ///
  42. domi::Status Init(const InputData &input, const OutputData &output);
  43. ///
  44. /// @ingroup domi_ome
  45. /// @brief init InputData
  46. /// @param [in] input use input to init InputData
  47. /// @param [in] output data copy dest address
  48. /// @return SUCCESS success
  49. /// @return other init failed
  50. ///
  51. OutputData *GetOutput() { return &output_; }
  52. ///
  53. /// @ingroup domi_ome
  54. /// @brief return InputData
  55. /// @return InputData
  56. ///
  57. const InputData &GetInput() const { return input_; }
  58. private:
  59. OutputData output_;
  60. InputData input_;
  61. bool is_init;
  62. };
  63. ///
  64. /// @ingroup domi_ome
  65. /// @brief manage data input
  66. /// @author
  67. ///
  68. class DataInputer {
  69. public:
  70. ///
  71. /// @ingroup domi_ome
  72. /// @brief constructor
  73. ///
  74. DataInputer() {}
  75. ///
  76. /// @ingroup domi_ome
  77. /// @brief destructor
  78. ///
  79. ~DataInputer() {}
  80. ///
  81. /// @ingroup domi_ome
  82. /// @brief init
  83. /// @return SUCCESS init success
  84. ///
  85. domi::Status Init() { return domi::SUCCESS; }
  86. ///
  87. /// @ingroup domi_ome
  88. /// @brief is input data full
  89. /// @return true full
  90. /// @return false not full
  91. ///
  92. bool IsDataFull() { return queue_.IsFull(); }
  93. ///
  94. /// @ingroup domi_ome
  95. /// @brief add input data
  96. /// @param [int] input data
  97. /// @return SUCCESS add successful
  98. /// @return INTERNAL_ERROR add failed
  99. ///
  100. domi::Status Push(const std::shared_ptr<InputDataWrapper> &data) {
  101. bool success = queue_.Push(data, false);
  102. return success ? domi::SUCCESS : domi::INTERNAL_ERROR;
  103. }
  104. ///
  105. /// @ingroup domi_ome
  106. /// @brief pop input data
  107. /// @param [out] save popped input data
  108. /// @return SUCCESS pop success
  109. /// @return INTERNAL_ERROR pop fail
  110. ///
  111. domi::Status Pop(std::shared_ptr<InputDataWrapper> &data) {
  112. bool success = queue_.Pop(data);
  113. return success ? domi::SUCCESS : domi::INTERNAL_ERROR;
  114. }
  115. ///
  116. /// @ingroup domi_ome
  117. /// @brief stop receiving data, invoke thread at Pop
  118. ///
  119. void Stop() { queue_.Stop(); }
  120. private:
  121. ///
  122. /// @ingroup domi_ome
  123. /// @brief save input data queue
  124. ///
  125. BlockingQueue<std::shared_ptr<InputDataWrapper>> queue_;
  126. };
  127. } // namespace ge
  128. #endif // GE_GRAPH_LOAD_NEW_MODEL_MANAGER_DATA_INPUTER_H_

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