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.

hccl.h 10 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /**
  2. * Copyright 2019-2022 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 HCCL_H_
  17. #define HCCL_H_
  18. #include <hccl/hccl_types.h>
  19. #include <acl/acl.h>
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif // __cplusplus
  23. /**
  24. * @brief Initialize HCCL.
  25. *
  26. * @param clusterInfo A string identifying the cluster info file path, include file name.
  27. * @param rank A integer identifying the identify for the rank.
  28. * @param comm A pointer identifying the initialized communication resource.
  29. * @return HcclResult
  30. * @see HcclCommDestroy()
  31. */
  32. extern HcclResult HcclCommInitClusterInfo(const char *clusterInfo, uint32_t rank, HcclComm *comm);
  33. /**
  34. * @brief Get hccl root info.
  35. *
  36. * @param rootInfo A pointer identifying the hccl root info.
  37. * @return HcclResult
  38. */
  39. extern HcclResult HcclGetRootInfo(HcclRootInfo *rootInfo);
  40. /**
  41. * @brief Initialize HCCL with root info.
  42. *
  43. * @param nRanks A integer identifying the rank size of the cluster.
  44. * @param rootInfo A struct identifying the hccl root info.
  45. * @param rank A integer identifying the identify for the rank.
  46. * @param comm A pointer identifying the initialized communication resource.
  47. * @return HcclResult
  48. * @see HcclCommDestroy()
  49. */
  50. extern HcclResult HcclCommInitRootInfo(uint32_t nRanks, const HcclRootInfo *rootInfo, uint32_t rank, HcclComm *comm);
  51. /**
  52. * @brief AllReduce operator.
  53. *
  54. * @param sendBuf A pointer identifying the input data address of the operator.
  55. * @param recvBuf A pointer identifying the output data address of the operator.
  56. * @param count An integer(u64) identifying the number of the output data.
  57. * @param dataType The data type of the operator, must be one of the following types: int8, int16, int32,
  58. float16, float32, bfloat16.
  59. * @param op The reduction type of the operator, must be one of the following types: sum, min, max, prod.
  60. * @param comm A pointer identifying the communication resource based on.
  61. * @param stream A pointer identifying the stream information.
  62. * @return HcclResult
  63. */
  64. extern HcclResult HcclAllReduce(void *sendBuf, void *recvBuf, uint64_t count, HcclDataType dataType, HcclReduceOp op,
  65. HcclComm comm, aclrtStream stream);
  66. /**
  67. * @brief Broadcast operator.
  68. *
  69. * @param buf A pointer identifying the data address of the operator.
  70. * @param count An integer(u64) identifying the number of the data.
  71. * @param dataType The data type of the operator, must be one of the following types: int8, int16, int32, int64,
  72. uint8, uint16, uint32, uint64, float16, float32, float64, bfloat16.
  73. * @param root An integer(u32) identifying the the root rank in the operator.
  74. * @param comm A pointer identifying the communication resource based on
  75. * @param stream A pointer identifying the stream information.
  76. * @return HcclResult
  77. */
  78. extern HcclResult HcclBroadcast(void *buf, uint64_t count, HcclDataType dataType, uint32_t root, HcclComm comm,
  79. aclrtStream stream);
  80. /**
  81. * @brief ReduceScatter operator.
  82. *
  83. * @param sendBuf A pointer identifying the input data address of the operator.
  84. * @param recvBuf A pointer identifying the output data address of the operator.
  85. * @param recvCount An integer(u64) identifying the number of the output data.
  86. * @param dataType The data type of the operator, must be one of the following types: int8, int32,
  87. float16, float32, bfloat16.
  88. * @param op The reduction type of the operator, must be one of the following types: sum, min, max, prod.
  89. * @param comm A pointer identifying the communication resource based on.
  90. * @param stream A pointer identifying the stream information.
  91. * @return HcclResult
  92. */
  93. extern HcclResult HcclReduceScatter(void *sendBuf, void *recvBuf, uint64_t recvCount, HcclDataType dataType,
  94. HcclReduceOp op, HcclComm comm, aclrtStream stream);
  95. /**
  96. * @brief AllGather operator.
  97. *
  98. * @param sendBuf A pointer identifying the input data address of the operator.
  99. * @param recvBuf A pointer identifying the output data address of the operator.
  100. * @param sendCount An integer(u64) identifying the number of the input data.
  101. * @param dataType The data type of the operator, must be one of the following types: int8, int16, int32, int64,
  102. uint8, uint16, uint32, uint64, float16, float32, float64, bfloat16.
  103. * @param comm A pointer identifying the communication resource based on.
  104. * @param stream A pointer identifying the stream information.
  105. * @return HcclResult
  106. */
  107. extern HcclResult HcclAllGather(void *sendBuf, void *recvBuf, uint64_t sendCount, HcclDataType dataType, HcclComm comm,
  108. aclrtStream stream);
  109. /**
  110. * @brief Get the rank size of this comm.
  111. *
  112. * @param comm A pointer identifying the communication resource based on.
  113. * @param rankSize A pointer identifying the rank size.
  114. * @return HcclResult
  115. */
  116. extern HcclResult HcclGetRankSize(HcclComm comm, uint32_t *rankSize);
  117. /**
  118. * @brief Get the rank id of this comm.
  119. *
  120. * @param comm A pointer identifying the communication resource based on.
  121. * @param rankSize A pointer identifying the rank id.
  122. * @return HcclResult
  123. */
  124. extern HcclResult HcclGetRankId(HcclComm comm, uint32_t *rank);
  125. /**
  126. * @brief Barrier operator.
  127. *
  128. * @param comm A pointer identifying the communication resource based on.
  129. * @param stream A pointer identifying the stream information.
  130. * @return HcclResult
  131. */
  132. extern HcclResult HcclBarrier(HcclComm comm, aclrtStream stream);
  133. /**
  134. * @brief Send operator.
  135. *
  136. * @param sendBuff A pointer identifying the input data address of the operator.
  137. * @param count An integer(u64) identifying the number of the send data.
  138. * @param dataType The data type of the operator, must be one of the following types: int8, int16, int32, int64,
  139. uint8, uint16, uint32, uint64, float16, float32, float64, bfloat16.
  140. * @param destRank An integer identifying the destination rank.
  141. * @param comm A pointer identifying the communication resource based on.
  142. * @param stream A pointer identifying the stream information.
  143. * @return HcclResult
  144. */
  145. extern HcclResult HcclSend(void *sendBuf, uint64_t count, HcclDataType dataType, uint32_t destRank, HcclComm comm,
  146. aclrtStream stream);
  147. /**
  148. * @brief Recv operator.
  149. *
  150. * @param recvBuff A pointer identifying the output data address of the operator.
  151. * @param count An integer(u64) identifying the number of the receive data.
  152. * @param dataType The data type of the operator, must be one of the following types: int8, int16, int32, int64,
  153. uint8, uint16, uint32, uint64, float16, float32, float64, bfloat16.
  154. * @param srcRank An integer identifying the source rank.
  155. * @param comm A pointer identifying the communication resource based on.
  156. * @param stream A pointer identifying the stream information.
  157. * @return HcclResult
  158. */
  159. extern HcclResult HcclRecv(void *recvBuf, uint64_t count, HcclDataType dataType, uint32_t srcRank, HcclComm comm,
  160. aclrtStream stream);
  161. /**
  162. * @brief AlltoAllV operator.
  163. *
  164. * @param sendBuff A pointer identifying the input data address of the operator.
  165. * @param sendCounts Integer array, where entry i specifies the number of elements to send to rank i.
  166. * @param sdispls Integer array, where entry i specifies the displacement (offset from sendbuf, in units of sendtype)
  167. from which to send data to rank i.
  168. * @param sendType Datatype of send buffer elements, must be one of the following types: int8, int16, int32, int64,
  169. uint8, uint16, uint32, uint64, float16, float32, float64, bfloat16.
  170. * @param recvBuf A pointer identifying the output data address of the operator.
  171. * @param recvCounts Integer array, where entry j specifies the number of elements to receive from rank j.
  172. * @param rdispls Integer array, where entry j specifies the displacement (offset from recvbuf, in units of recvtype) to
  173. which data from rank j should be written.
  174. * @param recvType Datatype of receive buffer elements, must be one of the following types: int8, int16, int32, int64,
  175. uint8, uint16, uint32, uint64, float16, float32, float64.
  176. * @param comm A pointer identifying the communication resource based on.
  177. * @param stream A pointer identifying the stream information.
  178. * @return HcclResult
  179. */
  180. extern HcclResult HcclAlltoAllV(const void *sendBuf, const void *sendCounts, const void *sdispls, HcclDataType sendType,
  181. const void *recvBuf, const void *recvCounts, const void *rdispls, HcclDataType recvType,
  182. HcclComm comm, aclrtStream stream);
  183. /**
  184. * @brief Reduce operator.
  185. *
  186. * @param sendBuf A pointer identifying the input data address of the operator.
  187. * @param recvBuf A pointer identifying the output data address of the operator.
  188. * @param count An integer(u64) identifying the number of the output data.
  189. * @param dataType The data type of the operator, must be one of the following types: int8, int16, int32, float16,
  190. * float32, bfloat16.
  191. * @param op The reduction type of the operator, must be one of the following types: sum, min, max, prod.
  192. * @param root An integer(u32) identifying the the root rank in the operator.
  193. * @param comm A pointer identifying the communication resource based on.
  194. * @param stream A pointer identifying the stream information.
  195. * @return HcclResult
  196. */
  197. extern HcclResult HcclReduce(void *sendBuf, void *recvBuf, uint64_t count, HcclDataType dataType, HcclReduceOp op,
  198. uint32_t root, HcclComm comm, aclrtStream stream);
  199. /**
  200. * @brief Destroy HCCL comm
  201. *
  202. * @param comm A pointer identifying the communication resource targetting
  203. * @return HcclResult
  204. * @see HcclCommInitClusterInfo()
  205. */
  206. extern HcclResult HcclCommDestroy(HcclComm comm);
  207. #ifdef __cplusplus
  208. }
  209. #endif // __cplusplus
  210. #endif // HCCL_H_

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