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.

zero_copy_task.h 3.2 kB

4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 GE_GRAPH_LOAD_NEW_MODEL_MANAGER_ZERO_COPY_TASK_H_
  17. #define GE_GRAPH_LOAD_NEW_MODEL_MANAGER_ZERO_COPY_TASK_H_
  18. #include <map>
  19. #include <set>
  20. #include <vector>
  21. #include <string>
  22. #include "external/ge/ge_api_error_codes.h"
  23. #include "framework/common/ge_types.h"
  24. #include "runtime/mem.h"
  25. using std::map;
  26. using std::set;
  27. using std::vector;
  28. using std::string;
  29. namespace ge {
  30. class ZeroCopyTask {
  31. public:
  32. ZeroCopyTask(const string &name, uint8_t *args, size_t size);
  33. ~ZeroCopyTask();
  34. /**
  35. * @ingroup ge
  36. * @brief Set Task zero copy addr info.
  37. * @param [in] addr: task addr value.
  38. * @param [in] offset: saved offset in task args.
  39. * @return: 0 SUCCESS / others FAILED
  40. */
  41. ge::Status SetTaskArgsOffset(uintptr_t addr, size_t offset);
  42. /**
  43. * @ingroup ge
  44. * @brief Is need zero copy.
  45. * @return: true / false
  46. */
  47. bool IsTaskArgsSet() const { return !task_addr_offset_.empty(); }
  48. /**
  49. * @ingroup ge
  50. * @brief Save orignal data of task args.
  51. * @param [in] info: task args orignal data.
  52. * @param [in] size: args size.
  53. * @return: void
  54. */
  55. void SetOriginalArgs(const void *info, size_t size);
  56. /**
  57. * @ingroup ge
  58. * @brief Set user data addr to Task param.
  59. * @param [in] addr: virtual address value from Op.
  60. * @param [in] buffer_addr: data buffer_addr from user.
  61. * @param [in] batch_addrs: dynamic batch addr info.
  62. * @param [in] batch_label: batch label.
  63. * @return: 0 SUCCESS / others FAILED
  64. */
  65. ge::Status UpdateTaskParam(uintptr_t addr, void *buffer_addr, const map<string, set<uintptr_t>> &batch_addrs,
  66. const string &batch_label);
  67. /**
  68. * @ingroup ge
  69. * @brief Update task param to device.
  70. * @param [in] async_mode: true for asychronous mode.
  71. * @param [in] stream: Stream for asychronous update.
  72. * @return: 0 SUCCESS / others FAILED
  73. */
  74. ge::Status DistributeParam(bool async_mode, rtStream_t stream);
  75. void SetBatchLabel(const string &batch_label) {
  76. batch_label_ = batch_label;
  77. }
  78. const string& GetBatchLabel() const {
  79. return batch_label_;
  80. }
  81. protected:
  82. bool CheckDynamicBatch(const map<string, set<uintptr_t>> &batch_addrs, const string &batch_label, uintptr_t addr);
  83. private:
  84. const string name_;
  85. uint8_t *args_addr_;
  86. const size_t args_size_;
  87. vector<uint8_t> args_info_;
  88. bool is_updated_;
  89. string batch_label_;
  90. // <address from Op, {offset in args}>
  91. map<uintptr_t, set<size_t>> task_addr_offset_;
  92. };
  93. } // namespace ge
  94. #endif // GE_GRAPH_LOAD_NEW_MODEL_MANAGER_ZERO_COPY_TASK_H_

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