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 11 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
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. #ifdef __cplusplus
  24. extern "C" {
  25. #endif // __cplusplus
  26. /**
  27. * @brief Initialize HCOM.
  28. *
  29. * @param rank_table A string identifying the rank table file path, include file name.
  30. * @param identify A string identifying the identify for the rank.
  31. * @return hcclResult_t
  32. * @see hcom_destroy()
  33. */
  34. extern hcclResult_t hcom_init(const char *rank_table, const char *identify);
  35. /**
  36. * @brief Destroy HCOM
  37. *
  38. * @return hcclResult_t
  39. * @see hcom_init()
  40. */
  41. extern hcclResult_t hcom_destroy(void);
  42. /**
  43. * @brief Bind the model.
  44. *
  45. * @param model A pointer identifying the model information.
  46. * @param stream A pointer identifying the stream information.
  47. * @return hcclResult_t
  48. * @see hcom_unbind_model()
  49. */
  50. extern hcclResult_t hcom_bind_model(rtModel_t model, rtStream_t stream);
  51. /**
  52. * @brief Unbind the model.
  53. *
  54. * @param model An pointer identifying the model information.
  55. * @return hcclResult_t
  56. * @see hcom_unbind_model()
  57. */
  58. extern hcclResult_t hcom_unbind_model(rtModel_t model);
  59. /**
  60. * @brief All-gather operator.
  61. *
  62. * @param tag A string identifying the tag of the operator.
  63. * @param inputPtr A pointer identifying the input data address of the operator.
  64. * @param outputPtr A pointer identifying the output data address of the operator.
  65. * @param inputCount An integer(u64) identifying the number of the input data.
  66. * @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
  67. * @param group A string identifying the group name of ranks participating in the operator.
  68. * @param stream A pointer identifying the stream information.
  69. * @return hcclResult_t
  70. */
  71. extern hcclResult_t hcom_all_gather(const char *tag, void *inputPtr, void *outputPtr, u64 inputCount,
  72. hcclDataType_t dataType, const char *group, rtStream_t stream);
  73. /**
  74. * @brief All-reduce operator.
  75. *
  76. * @param tag A string identifying the tag of the operator.
  77. * @param inputPtr A pointer identifying the input data address of the operator.
  78. * @param outputPtr A pointer identifying the output data address of the operator.
  79. * @param count An integer(u64) identifying the number of the output data.
  80. * @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
  81. * @param op The reduction type of the operator, must be one of the following types: sum, min, max, prod.
  82. * @param group A string identifying the group name of ranks participating in the operator.
  83. * @param stream A pointer identifying the stream information.
  84. * @return hcclResult_t
  85. */
  86. extern hcclResult_t hcom_all_reduce(const char *tag, void *inputPtr, void *outputPtr, u64 count,
  87. hcclDataType_t dataType, hcclRedOp_t op, const char *group, rtStream_t stream);
  88. /**
  89. * @brief Broadcast operator.
  90. *
  91. * @param tag A string identifying the tag of the operator.
  92. * @param ptr A pointer identifying the data address of the operator.
  93. * @param count An integer(u64) identifying the number of the data.
  94. * @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
  95. * @param root An integer(u32) identifying the the root rank in the operator.
  96. * @param group A string identifying the group name of ranks participating in the operator.
  97. * @param stream A pointer identifying the stream information.
  98. * @return hcclResult_t
  99. */
  100. extern hcclResult_t hcom_broadcast(const char *tag, void *ptr, u64 count, hcclDataType_t dataType, u32 root,
  101. const char *group, rtStream_t stream);
  102. /**
  103. * @brief Reduce-scatter operator.
  104. *
  105. * @param tag A string identifying the tag of the operator.
  106. * @param inputPtr A pointer identifying the input data address of the operator.
  107. * @param outputPtr A pointer identifying the output data address of the operator.
  108. * @param count An integer(u64) identifying the number of the data.
  109. * @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
  110. * @param op The reduction type of the operator, must be one of the following types: sum, min, max, prod.
  111. * @param group A string identifying the group name of ranks participating in the operator.
  112. * @param stream A pointer identifying the stream information.
  113. * @return hcclResult_t
  114. */
  115. extern hcclResult_t hcom_reduce_scatter(const char *tag, void *inputPtr, void *outputPtr, u64 count,
  116. hcclDataType_t dataType, hcclRedOp_t op, const char *group, rtStream_t stream);
  117. /**
  118. * @brief Get the rank number in the group.
  119. *
  120. * @param group A string identifying the group name.
  121. * @param rankSize A pointer identifying the rank number.
  122. * @return hcclResult_t
  123. */
  124. hcclResult_t hcom_get_rank_size(const char *group, u32 *rankSize);
  125. /**
  126. * @brief Get the rank number of this rank's server within the group.
  127. *
  128. * @param group A string identifying the group name.
  129. * @param localRankSize A pointer identifying the rank number.
  130. * @return hcclResult_t
  131. */
  132. hcclResult_t hcom_get_local_rank_size(const char *group, u32 *localRankSize);
  133. /**
  134. * @brief Get the rank id of this rank.
  135. *
  136. * @param group A string identifying the group name.
  137. * @param rankId A pointer identifying the rank id.
  138. * @return hcclResult_t
  139. */
  140. hcclResult_t hcom_get_rank_id(const char *group, u32 *rankId);
  141. /**
  142. * @brief Get the local rank id of this rank's server within the group.
  143. *
  144. * @param group A string identifying the group name.
  145. * @param localRankId A pointer identifying the local rank id.
  146. * @return hcclResult_t
  147. */
  148. hcclResult_t hcom_get_local_rank_id(const char *group, u32 *localRankId);
  149. /**
  150. * @brief Get the world rank id according to the group rank id.
  151. *
  152. * @param group A string identifying the group name.
  153. * @param groupRank An integer(u32) identifying the group rank id.
  154. * @param worldRank A pointer identifying the world rank id.
  155. * @return hcclResult_t
  156. */
  157. hcclResult_t hcom_get_world_rank_from_group_rank(const char *group, u32 groupRank, u32 *worldRank);
  158. /**
  159. * @brief Get the group rank id according to the world rank id.
  160. *
  161. * @param worldRank An integer(u32) identifying the world rank id.
  162. * @param group A string identifying the group name.
  163. * @param groupRank A pointer identifying the group rank id.
  164. * @return hcclResult_t
  165. */
  166. hcclResult_t hcom_get_group_rank_from_world_rank(u32 worldRank, const char *group, u32 *groupRank);
  167. /**
  168. * @brief Create group.
  169. *
  170. * @param group A string identifying the group name.
  171. * @param rankNum An integer(u32) identifying the number of ranks in the group.
  172. * @param rankIds A list identifying the ranks in the group.
  173. * @return hcclResult_t
  174. */
  175. hcclResult_t hcom_create_group(const char *group, u32 rankNum, u32 *rankIds);
  176. /**
  177. * @brief Destroy group
  178. *
  179. * @param group A string identifying the group name.
  180. * @return hcclResult_t
  181. */
  182. hcclResult_t hcom_destroy_group(const char *group);
  183. /**
  184. * @brief Send operator.
  185. *
  186. * @param tag A string identifying the tag of the operator.
  187. * @param inputPtr A pointer identifying the input data address of the operator.
  188. * @param count An integer(u64) identifying the number of the data.
  189. * @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
  190. * @param destRank An integer identifying the destination rank.
  191. * @param srTag An integer identifying the send/recv message tag.
  192. * The message will be send by the receive operator with the same "sr_tag".
  193. * @param group A string identifying the group name of ranks participating in the operator.
  194. * @param stream A pointer identifying the stream information.
  195. * @return hcclResult_t
  196. */
  197. hcclResult_t hcom_send(const char *tag, void *inputPtr, u64 count, hcclDataType_t dataType,
  198. u32 destRank, u32 srTag, const char *group, rtStream_t stream);
  199. /**
  200. * @brief Receive operator.
  201. *
  202. * @param tag A string identifying the tag of the operator.
  203. * @param outputPtr A pointer identifying the output data address of the operator.
  204. * @param count An integer(u64) identifying the number of the data.
  205. * @param dataType The data type of the operator, must be one of the following types: int8, int32, float16, float32.
  206. * @param srcRank An integer identifying the source rank.
  207. * @param srTag An integer identifying the send/recv message tag.
  208. * The message will be send by the send operator with the same "sr_tag".
  209. * @param group A string identifying the group name of ranks participating in the operator.
  210. * @param stream A pointer identifying the stream information.
  211. * @return hcclResult_t
  212. */
  213. hcclResult_t hcom_receive(const char *tag, void *outputPtr, u64 count, hcclDataType_t dataType,
  214. u32 srcRank, u32 srTag, const char *group, rtStream_t stream);
  215. /**
  216. * @brief Get the gradient split strategy with in the group.
  217. *
  218. * @param group A string identifying the group name.
  219. * @param feature A pointer identifying the feature of the model.
  220. * @param maxSegmentNum An integer(u32) identifying the max segments of gradients.
  221. * @param segmentNum A pointer identifying the segments number of gradients.
  222. * @param segmentIdx A list identifying the index of end gradient in each segment.
  223. * @return hcclResult_t
  224. */
  225. hcclResult_t hcom_get_split_strategy(const char *group, const struct model_feature *feature, u32 maxSegmentNum,
  226. u32 *segmentNum, u32 *segmentIdx, GradSplitForceMode force = FORCE_NONE,
  227. OriginalGraphShapeType shapeType = KNOWN_SHAPE);
  228. /**
  229. * @brief Set the gradient split strategy with in the group, according to gradient index.
  230. *
  231. * @param group A string identifying the group name.
  232. * @param segmentNum An integer(u32) identifying the segments number of gradients.
  233. * @param IdxList A list identifying the index of end gradient in each segment.
  234. * @return hcclResult_t
  235. */
  236. extern hcclResult_t hcom_set_split_strategy_by_index(const char *group, u32 segmentNum, const u32 *IdxList);
  237. /**
  238. * @brief Set the gradient split strategy with in the group, according to gradient data size.
  239. *
  240. * @param group A string identifying the group name.
  241. * @param segmentNum An integer(u32) identifying the segments number of gradients.
  242. * @param sizeList A list identifying the percent of each segment.
  243. * @return hcclResult_t
  244. */
  245. extern hcclResult_t hcom_set_split_strategy_by_size(const char *group, u32 segmentNum, const float *sizeList);
  246. #ifdef __cplusplus
  247. }
  248. #endif // __cplusplus
  249. #endif // HCOM_H_

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