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.

hcom_util.h 4.8 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
5 years ago
5 years ago
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 GE_GRAPH_MANAGER_UTIL_HCOM_UTIL_H_
  17. #define GE_GRAPH_MANAGER_UTIL_HCOM_UTIL_H_
  18. #include <map>
  19. #include <string>
  20. #include <vector>
  21. #include "common/debug/log.h"
  22. #include "common/opskernel/ge_task_info.h"
  23. #include "common/string_util.h"
  24. #include "common/types.h"
  25. #include "common/util.h"
  26. #include "graph/op_desc.h"
  27. #include "hccl/hcom.h"
  28. #include "proto/task.pb.h"
  29. namespace ge {
  30. using std::string;
  31. using std::vector;
  32. static std::map<int64_t, HcclDataType> kConstOpHcclDataType = {
  33. {ge::DT_FLOAT, HCCL_DATA_TYPE_FP32},
  34. {ge::DT_FLOAT16, HCCL_DATA_TYPE_FP16},
  35. {ge::DT_INT8, HCCL_DATA_TYPE_INT8},
  36. {ge::DT_INT32, HCCL_DATA_TYPE_INT32},
  37. };
  38. static std::map<HcclDataType, int32_t> kConstOpHcclDataTypeSize = {
  39. {HCCL_DATA_TYPE_FP32, sizeof(float)},
  40. {HCCL_DATA_TYPE_FP16, sizeof(float) / 2},
  41. {HCCL_DATA_TYPE_INT8, sizeof(int8_t)},
  42. {HCCL_DATA_TYPE_INT32, sizeof(int32_t)},
  43. };
  44. static std::map<HorovodReduceOp, HcclReduceOp> kHorovodRedOpToHcclRedOp = {
  45. {HOROVOD_REDUCE_SUM, HCCL_REDUCE_SUM}, {HOROVOD_REDUCE_MIN, HCCL_REDUCE_MIN},
  46. {HOROVOD_REDUCE_MAX, HCCL_REDUCE_MAX}, {HOROVOD_REDUCE_PROD, HCCL_REDUCE_PROD},
  47. {HOROVOD_REDUCE_RESERVED, HCCL_REDUCE_RESERVED},
  48. };
  49. class HcomOmeUtil {
  50. public:
  51. ///
  52. /// @ingroup domi_ome
  53. /// @brief GetHcclDataType
  54. /// @return SUCCESS
  55. /// @return FAIL
  56. ///
  57. static Status GetHcclDataType(const ge::ConstOpDescPtr &op_desc,
  58. std::vector<GETaskKernelHcclInfo> &kernel_hccl_infos);
  59. ///
  60. /// @ingroup domi_ome
  61. /// @brief GetHcclTypeSize
  62. /// @return SUCCESS
  63. /// @return FAIL
  64. ///
  65. static Status GetHcclTypeSize(HcclDataType data_type, int32_t &size);
  66. ///
  67. /// @ingroup domi_ome
  68. /// @brief GetHcclCount
  69. /// @return SUCCESS
  70. /// @return FAIL
  71. ///
  72. static Status GetHcclCount(const ge::ConstOpDescPtr &op_desc, std::vector<GETaskKernelHcclInfo> &kernel_hccl_infos);
  73. ///
  74. /// @ingroup domi_ome
  75. /// @brief GetHcclOperationType
  76. /// @return SUCCESS
  77. /// @return FAIL
  78. ///
  79. static Status GetHcclOperationType(const ge::ConstOpDescPtr &op_desc, HcclReduceOp &op_type);
  80. ///
  81. /// @ingroup domi_ome
  82. /// @brief GetHcclRootId
  83. /// @return SUCCESS
  84. /// @return FAIL
  85. ///
  86. static Status GetHcclRootId(const ge::ConstOpDescPtr &op_desc, int64_t &root_id);
  87. ///
  88. /// @ingroup domi_ome
  89. /// @brief GetAllRootId
  90. /// @return SUCCESS
  91. /// @return FAIL
  92. ///
  93. static Status GetAllRootId(const ge::ConstOpDescPtr &op_desc, std::vector<GETaskKernelHcclInfo> &kernel_hccl_infos);
  94. ///
  95. /// @ingroup domi_ome
  96. /// @brief check the op_type whether is hcom operator or not
  97. /// @return true
  98. /// @return false
  99. ///
  100. static bool IsHCOMOp(const string &op_type);
  101. ///
  102. /// @ingroup domi_ome
  103. /// @brief check the op_type whether is horovod operator or not
  104. /// @return true
  105. /// @return false
  106. ///
  107. static bool IsHorovodOp(const string &op_type);
  108. ///
  109. /// @ingroup domi_ome
  110. /// @brief GetHcclType
  111. /// @return void
  112. ///
  113. static void GetHcclType(const domi::TaskDef &task_def, std::vector<GETaskKernelHcclInfo> &kernel_hccl_infos);
  114. ///
  115. /// @ingroup domi_ome
  116. /// @brief CheckKernelHcclInfo
  117. /// @return SUCCESS
  118. /// @return FAIL
  119. ///
  120. static Status CheckKernelHcclInfo(const ge::ConstOpDescPtr &op_desc,
  121. std::vector<GETaskKernelHcclInfo> &kernel_hccl_infos);
  122. ///
  123. /// @ingroup domi_ome
  124. /// @brief GetHorovodInputs
  125. /// @return SUCCESS
  126. /// @return FAIL
  127. ///
  128. static Status GetHorovodInputs(const ge::ConstOpDescPtr &op_desc,
  129. std::vector<GETaskKernelHcclInfo> &kernel_hccl_infos);
  130. ///
  131. /// @ingroup domi_ome
  132. /// @brief GetHcomCount
  133. /// @return SUCCESS
  134. /// @return FAIL
  135. ///
  136. static Status GetHcomCount(const ge::ConstOpDescPtr &op_desc, HcclDataType data_type, bool is_allgather, int &count);
  137. private:
  138. ///
  139. /// @ingroup domi_ome
  140. /// @brief GetHorovodCount
  141. /// @return SUCCESS
  142. /// @return FAIL
  143. ///
  144. static Status GetHorovodCount(const ge::ConstOpDescPtr &op_desc,
  145. std::vector<GETaskKernelHcclInfo> &kernel_hccl_infos);
  146. };
  147. } // namespace ge
  148. #endif // GE_GRAPH_MANAGER_UTIL_HCOM_UTIL_H_

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