集体通信函数¶
以下 NCCL API 提供了一些常用的集体操作。
ncclAllReduce¶
-
ncclResult_t
ncclAllReduce(const void* sendbuff, void* recvbuff, size_t count, ncclDataType_t datatype, ncclRedOp_t op, ncclComm_t comm, cudaStream_t stream)¶ 使用
op操作归约sendbuff中长度为count的数据数组,并在每个recvbuff中留下结果的相同副本。如果
sendbuff == recvbuff,将发生就地操作。
相关链接: AllReduce。
ncclBroadcast¶
-
ncclResult_t
ncclBroadcast(const void* sendbuff, void* recvbuff, size_t count, ncclDataType_t datatype, int root, ncclComm_t comm, cudaStream_t stream)¶ 将
root秩上sendbuff中的count个元素复制到所有秩的recvbuff。sendbuff仅在秩root上使用,对于其他秩则忽略。如果
sendbuff == recvbuff,将发生就地操作。
-
ncclResult_t
ncclBcast(void* buff, size_t count, ncclDataType_t datatype, int root, ncclComm_t comm, cudaStream_t stream)¶ ncclBroadcast的旧版就地版本,类似于 MPI_Bcast。 调用ncclBcast(buff, count, datatype, root, comm, stream)
等效于
ncclBroadcast(buff, buff, count, datatype, root, comm, stream)
相关链接: Broadcast
ncclReduce¶
-
ncclResult_t
ncclReduce(const void* sendbuff, void* recvbuff, size_t count, ncclDataType_t datatype, ncclRedOp_t op, int root, ncclComm_t comm, cudaStream_t stream)¶ 使用
op操作将sendbuff中长度为count的数据数组归约到root秩上的recvbuff中。recvbuff仅在秩root上使用,对于其他秩则忽略。如果
sendbuff == recvbuff,将发生就地操作。
相关链接: Reduce。
ncclAllGather¶
-
ncclResult_t
ncclAllGather(const void* sendbuff, void* recvbuff, size_t sendcount, ncclDataType_t datatype, ncclComm_t comm, cudaStream_t stream)¶ 从所有 GPU 收集
sendcount个值,并在每个recvbuff中留下结果的相同副本,从秩i接收数据,偏移量为i*sendcount。注意: 这假设接收计数等于
nranks*sendcount,这意味着recvbuff的大小应至少为nranks*sendcount个元素。如果
sendbuff == recvbuff + rank * sendcount,将发生就地操作。
ncclReduceScatter¶
-
ncclResult_t
ncclReduceScatter(const void* sendbuff, void* recvbuff, size_t recvcount, ncclDataType_t datatype, ncclRedOp_t op, ncclComm_t comm, cudaStream_t stream)¶ 使用
op操作归约来自所有 GPU 的sendbuff中的数据,并将归约结果分散在设备上,以便秩i上的recvbuff将包含结果的第 i 个块。注意: 这假设发送计数等于
nranks*recvcount,这意味着sendbuff的大小应至少为nranks*recvcount个元素。如果
recvbuff == sendbuff + rank * recvcount,将发生就地操作。
相关链接: ReduceScatter, 就地操作。