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.h 8.3 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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. /**
  17. * @file hcom.h
  18. * @brief HCOM API
  19. */
  20. #ifndef HCOM_H_
  21. #define HCOM_H_
  22. #include <hccl/base.h>
  23. #include <hccl/hccl_types.h>
  24. #include <functional>
  25. #include <vector>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif // __cplusplus
  29. /**
  30. * @brief Get the rank number in the group.
  31. *
  32. * @param group A string identifying the group name.
  33. * @param rankSize A pointer identifying the rank number.
  34. * @return HcclResult
  35. */
  36. HcclResult hcom_get_rank_size(const char *group, u32 *rankSize);
  37. /**
  38. * @brief Get the rank number in the group.
  39. *
  40. * @param group A string identifying the group name.
  41. * @param rankSize A pointer identifying the rank number.
  42. * @return HcclResult
  43. */
  44. HcclResult HcomGetRankSize(const char *group, u32 *rankSize);
  45. /**
  46. * @brief Get the rank number of this rank's server within the group.
  47. *
  48. * @param group A string identifying the group name.
  49. * @param localRankSize A pointer identifying the rank number.
  50. * @return HcclResult
  51. */
  52. HcclResult hcom_get_local_rank_size(const char *group, u32 *localRankSize);
  53. /**
  54. * @brief Get the rank number of this rank's server within the group.
  55. *
  56. * @param group A string identifying the group name.
  57. * @param localRankSize A pointer identifying the rank number.
  58. * @return HcclResult
  59. */
  60. HcclResult HcomGetLocalRankSize(const char *group, u32 *localRankSize);
  61. /**
  62. * @brief Get the rank id of this rank.
  63. *
  64. * @param group A string identifying the group name.
  65. * @param rankId A pointer identifying the rank id.
  66. * @return HcclResult
  67. */
  68. HcclResult hcom_get_rank_id(const char *group, u32 *rankId);
  69. /**
  70. * @brief Get the rank id of this rank.
  71. *
  72. * @param group A string identifying the group name.
  73. * @param rankId A pointer identifying the rank id.
  74. * @return HcclResult
  75. */
  76. HcclResult HcomGetRankId(const char *group, u32 *rankId);
  77. /**
  78. * @brief Get the local rank id of this rank's server within the group.
  79. *
  80. * @param group A string identifying the group name.
  81. * @param localRankId A pointer identifying the local rank id.
  82. * @return HcclResult
  83. */
  84. HcclResult hcom_get_local_rank_id(const char *group, u32 *localRankId);
  85. /**
  86. * @brief Get the local rank id of this rank's server within the group.
  87. *
  88. * @param group A string identifying the group name.
  89. * @param localRankId A pointer identifying the local rank id.
  90. * @return HcclResult
  91. */
  92. HcclResult HcomGetLocalRankId(const char *group, u32 *localRankId);
  93. /**
  94. * @brief Get the world rank id according to the group rank id.
  95. *
  96. * @param group A string identifying the group name.
  97. * @param groupRank An integer(u32) identifying the group rank id.
  98. * @param worldRank A pointer identifying the world rank id.
  99. * @return HcclResult
  100. */
  101. HcclResult hcom_get_world_rank_from_group_rank(const char *group, u32 groupRank, u32 *worldRank);
  102. /**
  103. * @brief Get the world rank id according to the group rank id.
  104. *
  105. * @param group A string identifying the group name.
  106. * @param groupRank An integer(u32) identifying the group rank id.
  107. * @param worldRank A pointer identifying the world rank id.
  108. * @return HcclResult
  109. */
  110. HcclResult HcomGetWorldRankFromGroupRank(const char *group, u32 groupRank, u32 *worldRank);
  111. /**
  112. * @brief Get the group rank id according to the world rank id.
  113. *
  114. * @param worldRank An integer(u32) identifying the world rank id.
  115. * @param group A string identifying the group name.
  116. * @param groupRank A pointer identifying the group rank id.
  117. * @return HcclResult
  118. */
  119. HcclResult hcom_get_group_rank_from_world_rank(u32 worldRank, const char *group, u32 *groupRank);
  120. /**
  121. * @brief Get the group rank id according to the world rank id.
  122. *
  123. * @param worldRank An integer(u32) identifying the world rank id.
  124. * @param group A string identifying the group name.
  125. * @param groupRank A pointer identifying the group rank id.
  126. * @return HcclResult
  127. */
  128. HcclResult HcomGetGroupRankFromWorldRank(u32 worldRank, const char *group, u32 *groupRank);
  129. /**
  130. * @brief Create group.
  131. *
  132. * @param group A string identifying the group name.
  133. * @param rankNum An integer(u32) identifying the number of ranks in the group.
  134. * @param rankIds A list identifying the ranks in the group.
  135. * @return HcclResult
  136. */
  137. HcclResult hcom_create_group(const char *group, u32 rankNum, u32 *rankIds);
  138. /**
  139. * @brief Create group.
  140. *
  141. * @param group A string identifying the group name.
  142. * @param rankNum An integer(u32) identifying the number of ranks in the group.
  143. * @param rankIds A list identifying the ranks in the group.
  144. * @return HcclResult
  145. */
  146. HcclResult HcomCreateGroup(const char *group, u32 rankNum, u32 *rankIds);
  147. /**
  148. * @brief Destroy group
  149. *
  150. * @param group A string identifying the group name.
  151. * @return HcclResult
  152. */
  153. HcclResult hcom_destroy_group(const char *group);
  154. /**
  155. * @brief Destroy group
  156. *
  157. * @param group A string identifying the group name.
  158. * @return HcclResult
  159. */
  160. HcclResult HcomDestroyGroup(const char *group);
  161. /**
  162. * @brief Set the gradient split strategy with in the group, according to gradient index.
  163. *
  164. * @param group A string identifying the group name.
  165. * @param segmentNum An integer(u32) identifying the segments number of gradients.
  166. * @param IdxList A list identifying the index of end gradient in each segment.
  167. * @return HcclResult
  168. */
  169. extern HcclResult hcom_set_split_strategy_by_index(const char *group, u32 segmentNum, const u32 *IdxList);
  170. /**
  171. * @brief Set the gradient split strategy with in the group, according to gradient index.
  172. *
  173. * @param group A string identifying the group name.
  174. * @param segmentNum An integer(u32) identifying the segments number of gradients.
  175. * @param IdxList A list identifying the index of end gradient in each segment.
  176. * @return HcclResult
  177. */
  178. extern HcclResult HcomSetGradFusionByIndex(const char *group, u32 segmentNum, const u32 *IdxList);
  179. /**
  180. * @brief Set the gradient split strategy with in the group, according to gradient data size.
  181. *
  182. * @param group A string identifying the group name.
  183. * @param segmentNum An integer(u32) identifying the segments number of gradients.
  184. * @param sizeList A list identifying the percent of each segment.
  185. * @return HcclResult
  186. */
  187. extern HcclResult hcom_set_split_strategy_by_size(const char *group, u32 segmentNum, const float *sizeList);
  188. /**
  189. * @brief Set the gradient split strategy with in the group, according to gradient data size.
  190. *
  191. * @param group A string identifying the group name.
  192. * @param segmentNum An integer(u32) identifying the segments number of gradients.
  193. * @param sizeList A list identifying the percent of each segment.
  194. * @return HcclResult
  195. */
  196. extern HcclResult HcomSetGradFusionBySize(const char *group, u32 segmentNum, const float *sizeList);
  197. /**
  198. * @brief Register memories and init resources for remote access.
  199. *
  200. * @param addrList memory addresses for remote access.
  201. * @param count number of remote memory addresses.
  202. * @return HcclResult
  203. */
  204. extern HcclResult hcom_remote_access_mem_register(const MemRegisterAddr* addrList, u32 count);
  205. /**
  206. * @brief Register memories and init resources for remote access.
  207. *
  208. * @param addrList memory addresses for remote access.
  209. * @param count number of remote memory addresses.
  210. * @return HcclResult
  211. */
  212. extern HcclResult HcomRegRemoteAccessMem(const MemRegisterAddr* addrList, u32 count);
  213. HcclResult HcomExecInitialize();
  214. HcclResult HcomExecFinalize();
  215. HcclResult HcomExecEnqueueOperation(HcomOperation opInfo, std::function<void(HcclResult status)> callback);
  216. HcclResult HcomExecEnqueueRemoteAccess(const std::string& remoteAccessType,
  217. const std::vector<HcomRemoteAccessAddrInfo>& addrInfos,
  218. std::function<void(HcclResult status)> callback);
  219. #ifdef __cplusplus
  220. }
  221. #endif // __cplusplus
  222. #endif // HCOM_H_

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