集体通信函数
以下 MCCL API 提供了一些常用的集体操作。
mcclAllReduce
mcclResult_t mcclAllReduce(const void* sendbuff, void* recvbuff, size_t count, mcclDataType_t datatype, mcclRedOp_t op, mcclComm_t comm, musaStream_t stream)
使用 op 操作将 sendbuff 中长度为 count 的数据数组进行归约,并将结果的相同副本保存在 每个 recvbuff 中。
如果 sendbuff == recvbuff,则会发生就地(in-place)操作。
相关链接:AllReduce。
mcclBroadcast
mcclResult_t mcclBroadcast(const void* sendbuff, void* recvbuff, size_t count, mcclDataType_t datatype, int root, mcclComm_t comm, musaStream_t stream)
从 root rank 的 sendbuff 复制 count 个元素到所有 rank 的 recvbuff。sendbuff 仅在 root rank 上使用,其他 rank 上被忽略。
如果 sendbuff == recvbuff,则会发生就地(in-place)操作。
mcclResult_t mcclBcast(void* buff, size_t count, mcclDataType_t datatype, int root, mcclComm_t comm, musaStream_t stream)
mcclBroadcast 的旧版就地版本,类似于 MPI_Bcast,弃用。调用
mcclBcast(buff, count, datatype, root, comm, stream)
等同于
mcclBroadcast(buff, buff, count, datatype, root, comm, stream)
相关链接:Broadcast。
mcclReduce
mcclResult_t mcclReduce(const void* sendbuff, void* recvbuff, size_t count, mcclDataType_t datatype, mcclRedOp_t op, int root, mcclComm_t comm, musaStream_t stream)
将 sendbuff 中长度为 count 的数据数组归约到 root rank 的 recvbuff 上,使用 op 操作。recvbuff 仅在 root rank 上使用,其他 rank 上被忽略。
如果 sendbuff == recvbuff,则会发生就地(in-place)操作。
相关链接:Reduce。
mcclAllGather
mcclResult_t mcclAllGather(const void* sendbuff, void* recvbuff, size_t sendcount, mcclDataType_t datatype, mcclComm_t comm, musaStream_t stream)
从所有 GPU 收集 sendcount 个值,并将结果的相同副本保存在每个 recvbuff 中,来自 rank i 的数据位于偏移 i*sendcount 处。
注意:这假设接收计数等于 nranks*sendcount,这意味着 recvbuff 的大小至少应为 nranks*sendcount 个元素。
如果 sendbuff == recvbuff + rank * sendcount,则会发生就地(in-place)操作。
相关链接:AllGather。
mcclReduceScatter
mcclResult_t mcclReduceScatter(const void* sendbuff, void* recvbuff, size_t recvcount, mcclDataType_t datatype, mcclRedOp_t op, mcclComm_t comm, musaStream_t stream)
使用 op 操作将所有 GPU 上的 sendbuff 数据进行归约,并将归约结果分散到设备上,使得 rank i 的 recvbuff 包含结果的第 i 个区块。
注意:这假设发送计数等于 nranks*recvcount,这意味着 sendbuff 应该至少有 nranks*recvcount 个元素的大小。
如果 recvbuff == sendbuff + rank * recvcount,则会发生就地(in-place)操作。
相关链接:ReduceScatter。
mcclAlltoAll
mcclResult_t mcclAlltoAll(const void* sendbuff, void* recvbuff, size_t count, mcclDataType_t datatype, mcclComm_t comm, musaStream_t stream)
每个设备向所有其他设备发送 count 个值,并从所有其他设备接收 count 个值。发送到目标 rank j 的数据取自 sendbuff+j*count,从源 rank i 接收的数据放置在 recvbuff+i*count。
此操作要求发送缓冲区和接收缓冲区都有足够的空间容纳来自所有 rank 的数据。
相关链接:AlltoAll。
mcclGather
mcclResult_t mcclGather(const void* sendbuff, void* recvbuff, size_t count, mcclDataType_t datatype, int root, mcclComm_t comm, musaStream_t stream)
每个 rank 从 sendbuff 发送 count 个元素到 root rank。在 root rank 上,来自 rank i 的数据放置在 recvbuff + i*count 处。在非 root rank 上,recvbuff 不被使用。
root 是数据将被收集到的 rank。
如果 sendbuff == recvbuff + root * count,则会发生就地(in-place)操作。
相关链接:Gather。
mcclScatter
mcclResult_t mcclScatter(const void* sendbuff, void* recvbuff, size_t count, mcclDataType_t datatype, int root, mcclComm_t comm, musaStream_t stream)
在 root rank 上,从 sendbuff+i*count 发送 count 个元素到 rank i。在非 root rank 上,sendbuff 不被使用。每个 rank 接收 count 个元素到 recvbuff。
root 是分发数据的 rank。
如果 recvbuff == sendbuff + root * count,则会发生就地(in-place)操作。
相关链接:Scatter。

