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

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